diff --git a/nfs3/lib/nfs3/__init__.py b/nfs3/lib/nfs3/__init__.py new file mode 100644 index 0000000..656b953 --- /dev/null +++ b/nfs3/lib/nfs3/__init__.py @@ -0,0 +1,4 @@ +import os as _os, sys as _sys +# Python 3: make the package directory importable so the historic bare +# (implicit-relative) imports such as ``import nfs3_const`` keep working. +_sys.path.insert(1, _os.path.dirname(_os.path.abspath(__file__))) diff --git a/nfs3/lib/nfs3/acl.x b/nfs3/lib/nfs3/acl.x new file mode 100644 index 0000000..ddc1927 --- /dev/null +++ b/nfs3/lib/nfs3/acl.x @@ -0,0 +1,514 @@ +/* +aclDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1994,2001-2003 Sun Microsystems, Inc. + * All rights reserved. + * Use is subject to license terms. + */ + +/* + * ident "%Z%%M% %I% %E% SMI" + */ + +const NFS_ACL_MAX_ENTRIES = 1024; +const NFS3_FHSIZE = 64; +const NFS_FHSIZE = 32; +const ACL3_OK = 0; +const TRUE = 1; +const FALSE = 0; + +enum ftype3 { + NF3REG = 1, + NF3DIR = 2, + NF3BLK = 3, + NF3CHR = 4, + NF3LNK = 5, + NF3SOCK = 6, + NF3FIFO = 7 +}; + +enum nfsftype { + NFNON = 0, + NFREG = 1, /* regular file */ + NFDIR = 2, /* directory */ + NFBLK = 3, /* block special */ + NFCHR = 4, /* character special */ + NFLNK = 5 /* symbolic link */ +}; + +enum nfsstat3 { + NFS3_OK = 0, + NFS3ERR_PERM = 1, + NFS3ERR_NOENT = 2, + NFS3ERR_IO = 5, + NFS3ERR_NXIO = 6, + NFS3ERR_ACCES = 13, + NFS3ERR_EXIST = 17, + NFS3ERR_XDEV = 18, + NFS3ERR_NODEV = 19, + NFS3ERR_NOTDIR = 20, + NFS3ERR_ISDIR = 21, + NFS3ERR_INVAL = 22, + NFS3ERR_FBIG = 27, + NFS3ERR_NOSPC = 28, + NFS3ERR_ROFS = 30, + NFS3ERR_MLINK = 31, + NFS3ERR_NAMETOOLONG = 63, + NFS3ERR_NOTEMPTY = 66, + NFS3ERR_DQUOT = 69, + NFS3ERR_STALE = 70, + NFS3ERR_REMOTE = 71, + NFS3ERR_BADHANDLE = 10001, + NFS3ERR_NOT_SYNC = 10002, + NFS3ERR_BAD_COOKIE = 10003, + NFS3ERR_NOTSUPP = 10004, + NFS3ERR_TOOSMALL = 10005, + NFS3ERR_SERVERFAULT = 10006, + NFS3ERR_BADTYPE = 10007, + NFS3ERR_JUKEBOX = 10008, + NFS3ERR_FPRINTNOTFOUND = 10009, + NFS3ERR_ABORTED = 10010 +}; + +typedef unsigned hyper uint64; +typedef hyper int64; +typedef unsigned int uint32; +typedef int int32; +typedef int uid; +typedef uint32 o_mode; +typedef unsigned int u_int; + + +/* + * File access handle + */ +struct nfs_fh { + opaque data[NFS_FHSIZE]; +}; + +struct nfs_fh3 { + opaque data; +}; + +struct nfs_fh4 { + opaque data[NFS_FHSIZE]; +}; + +union post_op_attr switch (bool present) { +case TRUE: + fattr3 attributes; +case FALSE: + void; +}; + + +struct specdata3 { + uint32 major; + uint32 minor; +}; + +struct fattr3 { + ftype3 type; + uint32 mode; + uint32 nlink; + uint32 uid; + uint32 gid; + uint64 size; + uint64 used; + specdata3 rdev; + uint64 fsid; + uint64 fileid; + nfstime3 atime; + nfstime3 mtime; + nfstime3 ctime; +}; + +struct nfstime3 { + uint32 seconds; + uint32 nseconds; +}; + +struct nfsfattr { + nfsftype na_type; /* file type */ + uint64 na_mode; /* protection mode bits */ + uint64 na_nlink; /* # hard links */ + uint64 na_uid; /* owner user id */ + uint64 na_gid; /* owner group id */ + uint64 na_size; /* file size in bytes */ + uint64 na_blocksize; /* prefered block size */ + uint64 na_rdev; /* special device # */ + uint64 na_blocks; /* Kb of disk used by file */ + uint64 na_fsid; /* device # */ + uint64 na_nodeid; /* inode # */ + nfstime3 na_atime; /* time of last access */ + nfstime3 na_mtime; /* time of last modification */ + nfstime3 na_ctime; /* time of last change */ +}; + + +/* + * The values for the type element of the aclent structure. + */ +const NA_USER_OBJ = 0x1; /* object owner */ +const NA_USER = 0x2; /* additional users */ +const NA_GROUP_OBJ = 0x4; /* owning group of the object */ +const NA_GROUP = 0x8; /* additional groups */ +const NA_CLASS_OBJ = 0x10; /* file group class and mask entry */ +const NA_OTHER_OBJ = 0x20; /* other entry for the object */ +const NA_ACL_DEFAULT = 0x1000; /* default flag */ + +/* + * The bit field values for the perm element of the aclent + * structure. The three values can be combined to form any + * of the 8 combinations. + */ +const NA_READ = 0x4; /* read permission */ +const NA_WRITE = 0x2; /* write permission */ +const NA_EXEC = 0x1; /* exec permission */ + +/* + * This is the format of an ACL which is passed over the network. + */ +struct aclent { + int type; + uid id; + o_mode perm; +}; + +/* + * This is the structure which contains the ACL entries for a + * particular entity. It contains the ACL entries which apply + * to this object plus any default ACL entries which are + * inherited by its children. + * + * The values for the mask field are defined below. + */ +struct secattr { + u_int mask; + int aclcnt; + aclent aclent; + int dfaclcnt; + aclent dfaclent; +}; + +/* + * The values for the mask element of the secattr struct as well + * as for the mask element in the arguments in the GETACL2 and + * GETACL3 procedures. + */ +const NA_ACL = 0x1; /* aclent contains a valid list */ +const NA_ACLCNT = 0x2; /* the number of entries in the aclent list */ +const NA_DFACL = 0x4; /* dfaclent contains a valid list */ +const NA_DFACLCNT = 0x8; /* the number of entries in the dfaclent list */ + +/* + * This the definition for the GETACL procedure which applies to + * NFS Version 2. + */ +struct GETACL2args { + nfs_fh fh; + u_int mask; +}; + +struct GETACL2resok { + nfsfattr attr; + secattr acl; +}; + +union GETACL2res switch (nfsstat status) { +case ACL2_OK: + GETACL2resok resok; +default: + void; +}; + +/* + * This is the definition for the SETACL procedure which applies + * NFS Version 2. + */ +struct SETACL2args { + nfs_fh fh; + secattr acl; +}; + +struct SETACL2resok { + nfsfattr attr; +}; + +union SETACL2res switch (nfsstat status) { +case ACL2_OK: + SETACL2resok resok; +default: + void; +}; + +/* + * This is the definition for the GETATTR procedure which can be + * used as an alternative to the GETATTR in NFS Version 2. The + * main difference between this GETATTR and the NFS GETATTR is + * that this GETATTR returns the mode of the file without it being + * changed to match the min/max permissions mapping that the NFS + * Version 2 server does. + */ +struct GETATTR2args { + nfs_fh fh; +}; + +struct GETATTR2resok { + nfs_fh attr; +}; + +union GETATTR2res switch (nfsstat status) { +case ACL2_OK: + GETATTR2resok resok; +default: + void; +}; + +/* + * This is the definition for the ACCESS procedure which applies + * to NFS Version 2. + */ +struct ACCESS2args { + nfs_fh fh; + uint32 access; +}; + +/* + * The following access permissions may be requested: + */ +const ACCESS2_READ = 0x1; /* read data or readdir a directory */ +const ACCESS2_LOOKUP = 0x2; /* lookup a name in a directory */ +const ACCESS2_MODIFY = 0x4; /* rewrite existing file data or */ + /* modify existing directory entries */ +const ACCESS2_EXTEND = 0x8; /* write new data or add directory entries */ +const ACCESS2_DELETE = 0x10; /* delete existing directory entry */ +const ACCESS2_EXECUTE = 0x20; /* execute file (no meaning for a directory) */ + +struct ACCESS2resok { + nfsfattr attr; + uint32 access; +}; + +union ACCESS2res switch (nfsstat status) { +case ACL2_OK: + ACCESS2resok resok; +default: + void; +}; + +/* + * This is the definition for the GETXATTRDIR procedure which applies + * to NFS Version 2 files. + */ +struct GETXATTRDIR2args { + nfs_fh fh; + bool create; +}; + +struct GETXATTRDIR2resok { + nfs_fh fh; + nfsfattr attr; +}; + +union GETXATTRDIR2res switch (nfsstat status) { +case ACL2_OK: + GETXATTRDIR2resok resok; +default: + void; +}; + +/* + * This is the definition for the GETACL procedure which applies + * to NFS Version 3 files. + */ +struct GETACL3args { + nfs_fh3 fh; + u_int mask; +}; + +struct GETACL3resok { + post_op_attr attr; + secattr acl; +}; + +struct GETACL3resfail { + post_op_attr attr; +}; + +union GETACL3res switch (nfsstat3 status) { +case ACL3_OK: + GETACL3resok resok; +default: + GETACL3resfail resfail; +}; + +/* + * This is the definition for the SETACL procedure which applies + * to NFS Version 3 files. + */ +struct SETACL3args { + nfs_fh3 fh; + secattr acl; +}; + +struct SETACL3resok { + post_op_attr attr; +}; + +struct SETACL3resfail { + post_op_attr attr; +}; + +union SETACL3res switch (nfsstat3 status) { +case ACL3_OK: + SETACL3resok resok; +default: + SETACL3resfail resfail; +}; + +/* + * This is the definition for the GETXATTRDIR procedure which applies + * to NFS Version 3 files. + */ +struct GETXATTRDIR3args { + nfs_fh3 fh; + bool create; +}; + +struct GETXATTRDIR3resok { + nfs_fh3 fh; + post_op_attr attr; +}; + +union GETXATTRDIR3res switch (nfsstat3 status) { +case ACL3_OK: + GETXATTRDIR3resok resok; +default: + void; +}; + +/* + * XXX { + * This is a transitional interface to enable Solaris NFSv4 + * clients to manipulate ACLs on Solaris servers until the + * spec is complete enough to implement this inside the + * NFSv4 protocol itself. NFSv4 does handle extended + * attributes in-band. + */ + +/* + * This is the definition for the GETACL procedure which applies + * to NFS Version 4 files. + */ +struct GETACL4args { + nfs_fh4 fh; + u_int mask; +}; + +struct GETACL4resok { + post_op_attr attr; + secattr acl; +}; + +struct GETACL4resfail { + post_op_attr attr; +}; + +union GETACL4res switch (nfsstat3 status) { +case ACL4_OK: + GETACL4resok resok; +default: + GETACL4resfail resfail; +}; + +/* + * This is the definition for the SETACL procedure which applies + * to NFS Version 4 files. + */ +struct SETACL4args { + nfs_fh4 fh; + secattr acl; +}; + +struct SETACL4resok { + post_op_attr attr; +}; + +struct SETACL4resfail { + post_op_attr attr; +}; + +union SETACL4res switch (nfsstat3 status) { +case ACL4_OK: + SETACL4resok resok; +default: + SETACL4resfail resfail; +}; + +/* XXX } */ + +/* + * Share the port with the NFS service. NFS has to be running + * in order for this service to be useful anyway. + */ +const NFS_ACL_PORT = 2049; + +/* + * This is the definition for the ACL network protocol which is used + * to provide support for Solaris ACLs for files which are accessed + * via NFS Version 2 and NFS Version 3. + */ +program NFS_ACL_PROGRAM { + version NFS_ACL_V2 { + void + ACLPROC2_NULL(void) = 0; + GETACL2res + ACLPROC2_GETACL(GETACL2args) = 1; + SETACL2res + ACLPROC2_SETACL(SETACL2args) = 2; + GETATTR2res + ACLPROC2_GETATTR(GETATTR2args) = 3; + ACCESS2res + ACLPROC2_ACCESS(ACCESS2args) = 4; + GETXATTRDIR2res + ACLPROC2_GETXATTRDIR(GETXATTRDIR2args) = 5; + } = 2; + version NFS_ACL_V3 { + void + ACLPROC3_NULL(void) = 0; + GETACL3res + ACLPROC3_GETACL(GETACL3args) = 1; + SETACL3res + ACLPROC3_SETACL(SETACL3args) = 2; + GETXATTRDIR3res + ACLPROC3_GETXATTRDIR(GETXATTRDIR3args) = 3; + } = 3; + version NFS_ACL_V4 { + void + ACLPROC4_NULL(void) = 0; + GETACL4res + ACLPROC4_GETACL(GETACL4args) = 1; + SETACL4res + ACLPROC4_SETACL(SETACL4args) = 2; + } = 4; +} = 100227; diff --git a/nfs3/lib/nfs3/acl_const.py b/nfs3/lib/nfs3/acl_const.py new file mode 100644 index 0000000..92e3f04 --- /dev/null +++ b/nfs3/lib/nfs3/acl_const.py @@ -0,0 +1,139 @@ +# Generated by rpcgen.py from acl.x on Wed Jun 24 11:38:48 2026 +ACLPROC2_NULL = 0 +ACLPROC2_GETACL = 1 +ACLPROC2_SETACL = 2 +ACLPROC2_GETATTR = 3 +ACLPROC2_ACCESS = 4 +ACLPROC2_GETXATTRDIR = 5 +ACLPROC3_NULL = 0 +ACLPROC3_GETACL = 1 +ACLPROC3_SETACL = 2 +ACLPROC3_GETXATTRDIR = 3 +ACLPROC4_NULL = 0 +ACLPROC4_GETACL = 1 +ACLPROC4_SETACL = 2 +NFS_ACL_MAX_ENTRIES = 1024 +NFS3_FHSIZE = 64 +NFS_FHSIZE = 32 +ACL3_OK = 0 +TRUE = 1 +FALSE = 0 +NF3REG = 1 +NF3DIR = 2 +NF3BLK = 3 +NF3CHR = 4 +NF3LNK = 5 +NF3SOCK = 6 +NF3FIFO = 7 +ftype3 = { + 1 : 'NF3REG', + 2 : 'NF3DIR', + 3 : 'NF3BLK', + 4 : 'NF3CHR', + 5 : 'NF3LNK', + 6 : 'NF3SOCK', + 7 : 'NF3FIFO', +} +NFNON = 0 +NFREG = 1 +NFDIR = 2 +NFBLK = 3 +NFCHR = 4 +NFLNK = 5 +nfsftype = { + 0 : 'NFNON', + 1 : 'NFREG', + 2 : 'NFDIR', + 3 : 'NFBLK', + 4 : 'NFCHR', + 5 : 'NFLNK', +} +NFS3_OK = 0 +NFS3ERR_PERM = 1 +NFS3ERR_NOENT = 2 +NFS3ERR_IO = 5 +NFS3ERR_NXIO = 6 +NFS3ERR_ACCES = 13 +NFS3ERR_EXIST = 17 +NFS3ERR_XDEV = 18 +NFS3ERR_NODEV = 19 +NFS3ERR_NOTDIR = 20 +NFS3ERR_ISDIR = 21 +NFS3ERR_INVAL = 22 +NFS3ERR_FBIG = 27 +NFS3ERR_NOSPC = 28 +NFS3ERR_ROFS = 30 +NFS3ERR_MLINK = 31 +NFS3ERR_NAMETOOLONG = 63 +NFS3ERR_NOTEMPTY = 66 +NFS3ERR_DQUOT = 69 +NFS3ERR_STALE = 70 +NFS3ERR_REMOTE = 71 +NFS3ERR_BADHANDLE = 10001 +NFS3ERR_NOT_SYNC = 10002 +NFS3ERR_BAD_COOKIE = 10003 +NFS3ERR_NOTSUPP = 10004 +NFS3ERR_TOOSMALL = 10005 +NFS3ERR_SERVERFAULT = 10006 +NFS3ERR_BADTYPE = 10007 +NFS3ERR_JUKEBOX = 10008 +NFS3ERR_FPRINTNOTFOUND = 10009 +NFS3ERR_ABORTED = 10010 +nfsstat3 = { + 0 : 'NFS3_OK', + 1 : 'NFS3ERR_PERM', + 2 : 'NFS3ERR_NOENT', + 5 : 'NFS3ERR_IO', + 6 : 'NFS3ERR_NXIO', + 13 : 'NFS3ERR_ACCES', + 17 : 'NFS3ERR_EXIST', + 18 : 'NFS3ERR_XDEV', + 19 : 'NFS3ERR_NODEV', + 20 : 'NFS3ERR_NOTDIR', + 21 : 'NFS3ERR_ISDIR', + 22 : 'NFS3ERR_INVAL', + 27 : 'NFS3ERR_FBIG', + 28 : 'NFS3ERR_NOSPC', + 30 : 'NFS3ERR_ROFS', + 31 : 'NFS3ERR_MLINK', + 63 : 'NFS3ERR_NAMETOOLONG', + 66 : 'NFS3ERR_NOTEMPTY', + 69 : 'NFS3ERR_DQUOT', + 70 : 'NFS3ERR_STALE', + 71 : 'NFS3ERR_REMOTE', + 10001 : 'NFS3ERR_BADHANDLE', + 10002 : 'NFS3ERR_NOT_SYNC', + 10003 : 'NFS3ERR_BAD_COOKIE', + 10004 : 'NFS3ERR_NOTSUPP', + 10005 : 'NFS3ERR_TOOSMALL', + 10006 : 'NFS3ERR_SERVERFAULT', + 10007 : 'NFS3ERR_BADTYPE', + 10008 : 'NFS3ERR_JUKEBOX', + 10009 : 'NFS3ERR_FPRINTNOTFOUND', + 10010 : 'NFS3ERR_ABORTED', +} +NA_USER_OBJ = 0x1 +NA_USER = 0x2 +NA_GROUP_OBJ = 0x4 +NA_GROUP = 0x8 +NA_CLASS_OBJ = 0x10 +NA_OTHER_OBJ = 0x20 +NA_ACL_DEFAULT = 0x1000 +NA_READ = 0x4 +NA_WRITE = 0x2 +NA_EXEC = 0x1 +NA_ACL = 0x1 +NA_ACLCNT = 0x2 +NA_DFACL = 0x4 +NA_DFACLCNT = 0x8 +ACCESS2_READ = 0x1 +ACCESS2_LOOKUP = 0x2 +ACCESS2_MODIFY = 0x4 +ACCESS2_EXTEND = 0x8 +ACCESS2_DELETE = 0x10 +ACCESS2_EXECUTE = 0x20 +NFS_ACL_PORT = 2049 +NFS_ACL_PROGRAM = 100227 +NFS_ACL_V2 = 2 +NFS_ACL_V3 = 3 +NFS_ACL_V4 = 4 diff --git a/nfs3/lib/nfs3/acl_pack.py b/nfs3/lib/nfs3/acl_pack.py new file mode 100644 index 0000000..d42c45f --- /dev/null +++ b/nfs3/lib/nfs3/acl_pack.py @@ -0,0 +1,1074 @@ +# Generated by rpcgen.py from acl.x on Wed Jun 24 11:38:48 2026 +import acl_const as const +import acl_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class ACLPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + def pack_ftype3(self, data): + if hasattr(self, 'filter_ftype3'): + data = getattr(self, 'filter_ftype3')(data) + if self.check_enum and data not in [const.NF3REG, const.NF3DIR, const.NF3BLK, const.NF3CHR, const.NF3LNK, const.NF3SOCK, const.NF3FIFO]: + raise XDRError('value=%s not in enum ftype3' % data) + self.pack_int(data) + + def pack_nfsftype(self, data): + if hasattr(self, 'filter_nfsftype'): + data = getattr(self, 'filter_nfsftype')(data) + if self.check_enum and data not in [const.NFNON, const.NFREG, const.NFDIR, const.NFBLK, const.NFCHR, const.NFLNK]: + raise XDRError('value=%s not in enum nfsftype' % data) + self.pack_int(data) + + def pack_nfsstat3(self, data): + if hasattr(self, 'filter_nfsstat3'): + data = getattr(self, 'filter_nfsstat3')(data) + if self.check_enum and data not in [const.NFS3_OK, const.NFS3ERR_PERM, const.NFS3ERR_NOENT, const.NFS3ERR_IO, const.NFS3ERR_NXIO, const.NFS3ERR_ACCES, const.NFS3ERR_EXIST, const.NFS3ERR_XDEV, const.NFS3ERR_NODEV, const.NFS3ERR_NOTDIR, const.NFS3ERR_ISDIR, const.NFS3ERR_INVAL, const.NFS3ERR_FBIG, const.NFS3ERR_NOSPC, const.NFS3ERR_ROFS, const.NFS3ERR_MLINK, const.NFS3ERR_NAMETOOLONG, const.NFS3ERR_NOTEMPTY, const.NFS3ERR_DQUOT, const.NFS3ERR_STALE, const.NFS3ERR_REMOTE, const.NFS3ERR_BADHANDLE, const.NFS3ERR_NOT_SYNC, const.NFS3ERR_BAD_COOKIE, const.NFS3ERR_NOTSUPP, const.NFS3ERR_TOOSMALL, const.NFS3ERR_SERVERFAULT, const.NFS3ERR_BADTYPE, const.NFS3ERR_JUKEBOX, const.NFS3ERR_FPRINTNOTFOUND, const.NFS3ERR_ABORTED]: + raise XDRError('value=%s not in enum nfsstat3' % data) + self.pack_int(data) + + pack_uint64 = pack_uhyper + + pack_int64 = pack_hyper + + pack_uint32 = pack_uint + + pack_int32 = pack_int + + pack_uid = pack_int + + pack_o_mode = pack_uint32 + + pack_u_int = pack_uint + + def pack_nfs_fh(self, data): + if hasattr(self, 'filter_nfs_fh'): + data = getattr(self, 'filter_nfs_fh')(data) + if data.data is None: + raise TypeError('data.data == None') + self.pack_fopaque(const.NFS_FHSIZE, data.data) + + def pack_nfs_fh3(self, data): + if hasattr(self, 'filter_nfs_fh3'): + data = getattr(self, 'filter_nfs_fh3')(data) + if data.data is None: + raise TypeError('data.data == None') + if len(data.data) > const.NFS3_FHSIZE and self.check_array: + raise XDRError('array length too long for data.data') + self.pack_opaque(data.data) + + def pack_nfs_fh4(self, data): + if hasattr(self, 'filter_nfs_fh4'): + data = getattr(self, 'filter_nfs_fh4')(data) + if data.data is None: + raise TypeError('data.data == None') + self.pack_fopaque(const.NFS_FHSIZE, data.data) + + def pack_post_op_attr(self, data): + if hasattr(self, 'filter_post_op_attr'): + data = getattr(self, 'filter_post_op_attr')(data) + if data.present is None: + raise TypeError('data.present == None') + self.pack_bool(data.present) + if data.present == const.TRUE: + if data.attributes is None: + raise TypeError('data.attributes == None') + self.pack_fattr3(data.attributes) + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + + def pack_specdata3(self, data): + if hasattr(self, 'filter_specdata3'): + data = getattr(self, 'filter_specdata3')(data) + if data.major is None: + raise TypeError('data.major == None') + self.pack_uint32(data.major) + if data.minor is None: + raise TypeError('data.minor == None') + self.pack_uint32(data.minor) + + def pack_fattr3(self, data): + if hasattr(self, 'filter_fattr3'): + data = getattr(self, 'filter_fattr3')(data) + if data.type is None: + raise TypeError('data.type == None') + self.pack_ftype3(data.type) + if data.mode is None: + raise TypeError('data.mode == None') + self.pack_uint32(data.mode) + if data.nlink is None: + raise TypeError('data.nlink == None') + self.pack_uint32(data.nlink) + if data.uid is None: + raise TypeError('data.uid == None') + self.pack_uint32(data.uid) + if data.gid is None: + raise TypeError('data.gid == None') + self.pack_uint32(data.gid) + if data.size is None: + raise TypeError('data.size == None') + self.pack_uint64(data.size) + if data.used is None: + raise TypeError('data.used == None') + self.pack_uint64(data.used) + if data.rdev is None: + raise TypeError('data.rdev == None') + self.pack_specdata3(data.rdev) + if data.fsid is None: + raise TypeError('data.fsid == None') + self.pack_uint64(data.fsid) + if data.fileid is None: + raise TypeError('data.fileid == None') + self.pack_uint64(data.fileid) + if data.atime is None: + raise TypeError('data.atime == None') + self.pack_nfstime3(data.atime) + if data.mtime is None: + raise TypeError('data.mtime == None') + self.pack_nfstime3(data.mtime) + if data.ctime is None: + raise TypeError('data.ctime == None') + self.pack_nfstime3(data.ctime) + + def pack_nfstime3(self, data): + if hasattr(self, 'filter_nfstime3'): + data = getattr(self, 'filter_nfstime3')(data) + if data.seconds is None: + raise TypeError('data.seconds == None') + self.pack_uint32(data.seconds) + if data.nseconds is None: + raise TypeError('data.nseconds == None') + self.pack_uint32(data.nseconds) + + def pack_nfsfattr(self, data): + if hasattr(self, 'filter_nfsfattr'): + data = getattr(self, 'filter_nfsfattr')(data) + if data.na_type is None: + raise TypeError('data.na_type == None') + self.pack_nfsftype(data.na_type) + if data.na_mode is None: + raise TypeError('data.na_mode == None') + self.pack_uint64(data.na_mode) + if data.na_nlink is None: + raise TypeError('data.na_nlink == None') + self.pack_uint64(data.na_nlink) + if data.na_uid is None: + raise TypeError('data.na_uid == None') + self.pack_uint64(data.na_uid) + if data.na_gid is None: + raise TypeError('data.na_gid == None') + self.pack_uint64(data.na_gid) + if data.na_size is None: + raise TypeError('data.na_size == None') + self.pack_uint64(data.na_size) + if data.na_blocksize is None: + raise TypeError('data.na_blocksize == None') + self.pack_uint64(data.na_blocksize) + if data.na_rdev is None: + raise TypeError('data.na_rdev == None') + self.pack_uint64(data.na_rdev) + if data.na_blocks is None: + raise TypeError('data.na_blocks == None') + self.pack_uint64(data.na_blocks) + if data.na_fsid is None: + raise TypeError('data.na_fsid == None') + self.pack_uint64(data.na_fsid) + if data.na_nodeid is None: + raise TypeError('data.na_nodeid == None') + self.pack_uint64(data.na_nodeid) + if data.na_atime is None: + raise TypeError('data.na_atime == None') + self.pack_nfstime3(data.na_atime) + if data.na_mtime is None: + raise TypeError('data.na_mtime == None') + self.pack_nfstime3(data.na_mtime) + if data.na_ctime is None: + raise TypeError('data.na_ctime == None') + self.pack_nfstime3(data.na_ctime) + + def pack_aclent(self, data): + if hasattr(self, 'filter_aclent'): + data = getattr(self, 'filter_aclent')(data) + if data.type is None: + raise TypeError('data.type == None') + self.pack_int(data.type) + if data.id is None: + raise TypeError('data.id == None') + self.pack_uid(data.id) + if data.perm is None: + raise TypeError('data.perm == None') + self.pack_o_mode(data.perm) + + def pack_secattr(self, data): + if hasattr(self, 'filter_secattr'): + data = getattr(self, 'filter_secattr')(data) + if data.mask is None: + raise TypeError('data.mask == None') + self.pack_u_int(data.mask) + if data.aclcnt is None: + raise TypeError('data.aclcnt == None') + self.pack_int(data.aclcnt) + if data.aclent is None: + raise TypeError('data.aclent == None') + if len(data.aclent) > const.NFS_ACL_MAX_ENTRIES and self.check_array: + raise XDRError('array length too long for data.aclent') + self.pack_array(data.aclent, self.pack_aclent) + if data.dfaclcnt is None: + raise TypeError('data.dfaclcnt == None') + self.pack_int(data.dfaclcnt) + if data.dfaclent is None: + raise TypeError('data.dfaclent == None') + if len(data.dfaclent) > const.NFS_ACL_MAX_ENTRIES and self.check_array: + raise XDRError('array length too long for data.dfaclent') + self.pack_array(data.dfaclent, self.pack_aclent) + + def pack_GETACL2args(self, data): + if hasattr(self, 'filter_GETACL2args'): + data = getattr(self, 'filter_GETACL2args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh(data.fh) + if data.mask is None: + raise TypeError('data.mask == None') + self.pack_u_int(data.mask) + + def pack_GETACL2resok(self, data): + if hasattr(self, 'filter_GETACL2resok'): + data = getattr(self, 'filter_GETACL2resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_nfsfattr(data.attr) + if data.acl is None: + raise TypeError('data.acl == None') + self.pack_secattr(data.acl) + + def pack_GETACL2res(self, data): + if hasattr(self, 'filter_GETACL2res'): + data = getattr(self, 'filter_GETACL2res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat(data.status) + if data.status == const.ACL2_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_GETACL2resok(data.resok) + else: + pass + + def pack_SETACL2args(self, data): + if hasattr(self, 'filter_SETACL2args'): + data = getattr(self, 'filter_SETACL2args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh(data.fh) + if data.acl is None: + raise TypeError('data.acl == None') + self.pack_secattr(data.acl) + + def pack_SETACL2resok(self, data): + if hasattr(self, 'filter_SETACL2resok'): + data = getattr(self, 'filter_SETACL2resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_nfsfattr(data.attr) + + def pack_SETACL2res(self, data): + if hasattr(self, 'filter_SETACL2res'): + data = getattr(self, 'filter_SETACL2res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat(data.status) + if data.status == const.ACL2_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_SETACL2resok(data.resok) + else: + pass + + def pack_GETATTR2args(self, data): + if hasattr(self, 'filter_GETATTR2args'): + data = getattr(self, 'filter_GETATTR2args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh(data.fh) + + def pack_GETATTR2resok(self, data): + if hasattr(self, 'filter_GETATTR2resok'): + data = getattr(self, 'filter_GETATTR2resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_nfs_fh(data.attr) + + def pack_GETATTR2res(self, data): + if hasattr(self, 'filter_GETATTR2res'): + data = getattr(self, 'filter_GETATTR2res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat(data.status) + if data.status == const.ACL2_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_GETATTR2resok(data.resok) + else: + pass + + def pack_ACCESS2args(self, data): + if hasattr(self, 'filter_ACCESS2args'): + data = getattr(self, 'filter_ACCESS2args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh(data.fh) + if data.access is None: + raise TypeError('data.access == None') + self.pack_uint32(data.access) + + def pack_ACCESS2resok(self, data): + if hasattr(self, 'filter_ACCESS2resok'): + data = getattr(self, 'filter_ACCESS2resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_nfsfattr(data.attr) + if data.access is None: + raise TypeError('data.access == None') + self.pack_uint32(data.access) + + def pack_ACCESS2res(self, data): + if hasattr(self, 'filter_ACCESS2res'): + data = getattr(self, 'filter_ACCESS2res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat(data.status) + if data.status == const.ACL2_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_ACCESS2resok(data.resok) + else: + pass + + def pack_GETXATTRDIR2args(self, data): + if hasattr(self, 'filter_GETXATTRDIR2args'): + data = getattr(self, 'filter_GETXATTRDIR2args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh(data.fh) + if data.create is None: + raise TypeError('data.create == None') + self.pack_bool(data.create) + + def pack_GETXATTRDIR2resok(self, data): + if hasattr(self, 'filter_GETXATTRDIR2resok'): + data = getattr(self, 'filter_GETXATTRDIR2resok')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh(data.fh) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_nfsfattr(data.attr) + + def pack_GETXATTRDIR2res(self, data): + if hasattr(self, 'filter_GETXATTRDIR2res'): + data = getattr(self, 'filter_GETXATTRDIR2res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat(data.status) + if data.status == const.ACL2_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_GETXATTRDIR2resok(data.resok) + else: + pass + + def pack_GETACL3args(self, data): + if hasattr(self, 'filter_GETACL3args'): + data = getattr(self, 'filter_GETACL3args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh3(data.fh) + if data.mask is None: + raise TypeError('data.mask == None') + self.pack_u_int(data.mask) + + def pack_GETACL3resok(self, data): + if hasattr(self, 'filter_GETACL3resok'): + data = getattr(self, 'filter_GETACL3resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + if data.acl is None: + raise TypeError('data.acl == None') + self.pack_secattr(data.acl) + + def pack_GETACL3resfail(self, data): + if hasattr(self, 'filter_GETACL3resfail'): + data = getattr(self, 'filter_GETACL3resfail')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_GETACL3res(self, data): + if hasattr(self, 'filter_GETACL3res'): + data = getattr(self, 'filter_GETACL3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.ACL3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_GETACL3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_GETACL3resfail(data.resfail) + + def pack_SETACL3args(self, data): + if hasattr(self, 'filter_SETACL3args'): + data = getattr(self, 'filter_SETACL3args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh3(data.fh) + if data.acl is None: + raise TypeError('data.acl == None') + self.pack_secattr(data.acl) + + def pack_SETACL3resok(self, data): + if hasattr(self, 'filter_SETACL3resok'): + data = getattr(self, 'filter_SETACL3resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_SETACL3resfail(self, data): + if hasattr(self, 'filter_SETACL3resfail'): + data = getattr(self, 'filter_SETACL3resfail')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_SETACL3res(self, data): + if hasattr(self, 'filter_SETACL3res'): + data = getattr(self, 'filter_SETACL3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.ACL3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_SETACL3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_SETACL3resfail(data.resfail) + + def pack_GETXATTRDIR3args(self, data): + if hasattr(self, 'filter_GETXATTRDIR3args'): + data = getattr(self, 'filter_GETXATTRDIR3args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh3(data.fh) + if data.create is None: + raise TypeError('data.create == None') + self.pack_bool(data.create) + + def pack_GETXATTRDIR3resok(self, data): + if hasattr(self, 'filter_GETXATTRDIR3resok'): + data = getattr(self, 'filter_GETXATTRDIR3resok')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh3(data.fh) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_GETXATTRDIR3res(self, data): + if hasattr(self, 'filter_GETXATTRDIR3res'): + data = getattr(self, 'filter_GETXATTRDIR3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.ACL3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_GETXATTRDIR3resok(data.resok) + else: + pass + + def pack_GETACL4args(self, data): + if hasattr(self, 'filter_GETACL4args'): + data = getattr(self, 'filter_GETACL4args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh4(data.fh) + if data.mask is None: + raise TypeError('data.mask == None') + self.pack_u_int(data.mask) + + def pack_GETACL4resok(self, data): + if hasattr(self, 'filter_GETACL4resok'): + data = getattr(self, 'filter_GETACL4resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + if data.acl is None: + raise TypeError('data.acl == None') + self.pack_secattr(data.acl) + + def pack_GETACL4resfail(self, data): + if hasattr(self, 'filter_GETACL4resfail'): + data = getattr(self, 'filter_GETACL4resfail')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_GETACL4res(self, data): + if hasattr(self, 'filter_GETACL4res'): + data = getattr(self, 'filter_GETACL4res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.ACL4_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_GETACL4resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_GETACL4resfail(data.resfail) + + def pack_SETACL4args(self, data): + if hasattr(self, 'filter_SETACL4args'): + data = getattr(self, 'filter_SETACL4args')(data) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_nfs_fh4(data.fh) + if data.acl is None: + raise TypeError('data.acl == None') + self.pack_secattr(data.acl) + + def pack_SETACL4resok(self, data): + if hasattr(self, 'filter_SETACL4resok'): + data = getattr(self, 'filter_SETACL4resok')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_SETACL4resfail(self, data): + if hasattr(self, 'filter_SETACL4resfail'): + data = getattr(self, 'filter_SETACL4resfail')(data) + if data.attr is None: + raise TypeError('data.attr == None') + self.pack_post_op_attr(data.attr) + + def pack_SETACL4res(self, data): + if hasattr(self, 'filter_SETACL4res'): + data = getattr(self, 'filter_SETACL4res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.ACL4_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_SETACL4resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_SETACL4resfail(data.resfail) + +class ACLUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + def unpack_ftype3(self): + data = self.unpack_int() + if self.check_enum and data not in [const.NF3REG, const.NF3DIR, const.NF3BLK, const.NF3CHR, const.NF3LNK, const.NF3SOCK, const.NF3FIFO]: + raise XDRError('value=%s not in enum ftype3' % data) + if hasattr(self, 'filter_ftype3'): + data = getattr(self, 'filter_ftype3')(data) + return data + + def unpack_nfsftype(self): + data = self.unpack_int() + if self.check_enum and data not in [const.NFNON, const.NFREG, const.NFDIR, const.NFBLK, const.NFCHR, const.NFLNK]: + raise XDRError('value=%s not in enum nfsftype' % data) + if hasattr(self, 'filter_nfsftype'): + data = getattr(self, 'filter_nfsftype')(data) + return data + + def unpack_nfsstat3(self): + data = self.unpack_int() + if self.check_enum and data not in [const.NFS3_OK, const.NFS3ERR_PERM, const.NFS3ERR_NOENT, const.NFS3ERR_IO, const.NFS3ERR_NXIO, const.NFS3ERR_ACCES, const.NFS3ERR_EXIST, const.NFS3ERR_XDEV, const.NFS3ERR_NODEV, const.NFS3ERR_NOTDIR, const.NFS3ERR_ISDIR, const.NFS3ERR_INVAL, const.NFS3ERR_FBIG, const.NFS3ERR_NOSPC, const.NFS3ERR_ROFS, const.NFS3ERR_MLINK, const.NFS3ERR_NAMETOOLONG, const.NFS3ERR_NOTEMPTY, const.NFS3ERR_DQUOT, const.NFS3ERR_STALE, const.NFS3ERR_REMOTE, const.NFS3ERR_BADHANDLE, const.NFS3ERR_NOT_SYNC, const.NFS3ERR_BAD_COOKIE, const.NFS3ERR_NOTSUPP, const.NFS3ERR_TOOSMALL, const.NFS3ERR_SERVERFAULT, const.NFS3ERR_BADTYPE, const.NFS3ERR_JUKEBOX, const.NFS3ERR_FPRINTNOTFOUND, const.NFS3ERR_ABORTED]: + raise XDRError('value=%s not in enum nfsstat3' % data) + if hasattr(self, 'filter_nfsstat3'): + data = getattr(self, 'filter_nfsstat3')(data) + return data + + unpack_uint64 = unpack_uhyper + + unpack_int64 = unpack_hyper + + unpack_uint32 = unpack_uint + + unpack_int32 = unpack_int + + unpack_uid = unpack_int + + unpack_o_mode = unpack_uint32 + + unpack_u_int = unpack_uint + + def unpack_nfs_fh(self): + data = types.nfs_fh() + data.data = self.unpack_fopaque(const.NFS_FHSIZE) + if hasattr(self, 'filter_nfs_fh'): + data = getattr(self, 'filter_nfs_fh')(data) + return data + + def unpack_nfs_fh3(self): + data = types.nfs_fh3() + data.data = self.unpack_opaque() + if len(data.data) > const.NFS3_FHSIZE and self.check_array: + raise XDRError('array length too long for data.data') + if hasattr(self, 'filter_nfs_fh3'): + data = getattr(self, 'filter_nfs_fh3')(data) + return data + + def unpack_nfs_fh4(self): + data = types.nfs_fh4() + data.data = self.unpack_fopaque(const.NFS_FHSIZE) + if hasattr(self, 'filter_nfs_fh4'): + data = getattr(self, 'filter_nfs_fh4')(data) + return data + + def unpack_post_op_attr(self): + data = types.post_op_attr() + data.present = self.unpack_bool() + if data.present == const.TRUE: + data.attributes = self.unpack_fattr3() + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + if hasattr(self, 'filter_post_op_attr'): + data = getattr(self, 'filter_post_op_attr')(data) + return data + + def unpack_specdata3(self): + data = types.specdata3() + data.major = self.unpack_uint32() + data.minor = self.unpack_uint32() + if hasattr(self, 'filter_specdata3'): + data = getattr(self, 'filter_specdata3')(data) + return data + + def unpack_fattr3(self): + data = types.fattr3() + data.type = self.unpack_ftype3() + data.mode = self.unpack_uint32() + data.nlink = self.unpack_uint32() + data.uid = self.unpack_uint32() + data.gid = self.unpack_uint32() + data.size = self.unpack_uint64() + data.used = self.unpack_uint64() + data.rdev = self.unpack_specdata3() + data.fsid = self.unpack_uint64() + data.fileid = self.unpack_uint64() + data.atime = self.unpack_nfstime3() + data.mtime = self.unpack_nfstime3() + data.ctime = self.unpack_nfstime3() + if hasattr(self, 'filter_fattr3'): + data = getattr(self, 'filter_fattr3')(data) + return data + + def unpack_nfstime3(self): + data = types.nfstime3() + data.seconds = self.unpack_uint32() + data.nseconds = self.unpack_uint32() + if hasattr(self, 'filter_nfstime3'): + data = getattr(self, 'filter_nfstime3')(data) + return data + + def unpack_nfsfattr(self): + data = types.nfsfattr() + data.na_type = self.unpack_nfsftype() + data.na_mode = self.unpack_uint64() + data.na_nlink = self.unpack_uint64() + data.na_uid = self.unpack_uint64() + data.na_gid = self.unpack_uint64() + data.na_size = self.unpack_uint64() + data.na_blocksize = self.unpack_uint64() + data.na_rdev = self.unpack_uint64() + data.na_blocks = self.unpack_uint64() + data.na_fsid = self.unpack_uint64() + data.na_nodeid = self.unpack_uint64() + data.na_atime = self.unpack_nfstime3() + data.na_mtime = self.unpack_nfstime3() + data.na_ctime = self.unpack_nfstime3() + if hasattr(self, 'filter_nfsfattr'): + data = getattr(self, 'filter_nfsfattr')(data) + return data + + def unpack_aclent(self): + data = types.aclent() + data.type = self.unpack_int() + data.id = self.unpack_uid() + data.perm = self.unpack_o_mode() + if hasattr(self, 'filter_aclent'): + data = getattr(self, 'filter_aclent')(data) + return data + + def unpack_secattr(self): + data = types.secattr() + data.mask = self.unpack_u_int() + data.aclcnt = self.unpack_int() + data.aclent = self.unpack_array(self.unpack_aclent) + if len(data.aclent) > const.NFS_ACL_MAX_ENTRIES and self.check_array: + raise XDRError('array length too long for data.aclent') + data.dfaclcnt = self.unpack_int() + data.dfaclent = self.unpack_array(self.unpack_aclent) + if len(data.dfaclent) > const.NFS_ACL_MAX_ENTRIES and self.check_array: + raise XDRError('array length too long for data.dfaclent') + if hasattr(self, 'filter_secattr'): + data = getattr(self, 'filter_secattr')(data) + return data + + def unpack_GETACL2args(self): + data = types.GETACL2args() + data.fh = self.unpack_nfs_fh() + data.mask = self.unpack_u_int() + if hasattr(self, 'filter_GETACL2args'): + data = getattr(self, 'filter_GETACL2args')(data) + return data + + def unpack_GETACL2resok(self): + data = types.GETACL2resok() + data.attr = self.unpack_nfsfattr() + data.acl = self.unpack_secattr() + if hasattr(self, 'filter_GETACL2resok'): + data = getattr(self, 'filter_GETACL2resok')(data) + return data + + def unpack_GETACL2res(self): + data = types.GETACL2res() + data.status = self.unpack_nfsstat() + if data.status == const.ACL2_OK: + data.resok = self.unpack_GETACL2resok() + else: + pass + if hasattr(self, 'filter_GETACL2res'): + data = getattr(self, 'filter_GETACL2res')(data) + return data + + def unpack_SETACL2args(self): + data = types.SETACL2args() + data.fh = self.unpack_nfs_fh() + data.acl = self.unpack_secattr() + if hasattr(self, 'filter_SETACL2args'): + data = getattr(self, 'filter_SETACL2args')(data) + return data + + def unpack_SETACL2resok(self): + data = types.SETACL2resok() + data.attr = self.unpack_nfsfattr() + if hasattr(self, 'filter_SETACL2resok'): + data = getattr(self, 'filter_SETACL2resok')(data) + return data + + def unpack_SETACL2res(self): + data = types.SETACL2res() + data.status = self.unpack_nfsstat() + if data.status == const.ACL2_OK: + data.resok = self.unpack_SETACL2resok() + else: + pass + if hasattr(self, 'filter_SETACL2res'): + data = getattr(self, 'filter_SETACL2res')(data) + return data + + def unpack_GETATTR2args(self): + data = types.GETATTR2args() + data.fh = self.unpack_nfs_fh() + if hasattr(self, 'filter_GETATTR2args'): + data = getattr(self, 'filter_GETATTR2args')(data) + return data + + def unpack_GETATTR2resok(self): + data = types.GETATTR2resok() + data.attr = self.unpack_nfs_fh() + if hasattr(self, 'filter_GETATTR2resok'): + data = getattr(self, 'filter_GETATTR2resok')(data) + return data + + def unpack_GETATTR2res(self): + data = types.GETATTR2res() + data.status = self.unpack_nfsstat() + if data.status == const.ACL2_OK: + data.resok = self.unpack_GETATTR2resok() + else: + pass + if hasattr(self, 'filter_GETATTR2res'): + data = getattr(self, 'filter_GETATTR2res')(data) + return data + + def unpack_ACCESS2args(self): + data = types.ACCESS2args() + data.fh = self.unpack_nfs_fh() + data.access = self.unpack_uint32() + if hasattr(self, 'filter_ACCESS2args'): + data = getattr(self, 'filter_ACCESS2args')(data) + return data + + def unpack_ACCESS2resok(self): + data = types.ACCESS2resok() + data.attr = self.unpack_nfsfattr() + data.access = self.unpack_uint32() + if hasattr(self, 'filter_ACCESS2resok'): + data = getattr(self, 'filter_ACCESS2resok')(data) + return data + + def unpack_ACCESS2res(self): + data = types.ACCESS2res() + data.status = self.unpack_nfsstat() + if data.status == const.ACL2_OK: + data.resok = self.unpack_ACCESS2resok() + else: + pass + if hasattr(self, 'filter_ACCESS2res'): + data = getattr(self, 'filter_ACCESS2res')(data) + return data + + def unpack_GETXATTRDIR2args(self): + data = types.GETXATTRDIR2args() + data.fh = self.unpack_nfs_fh() + data.create = self.unpack_bool() + if hasattr(self, 'filter_GETXATTRDIR2args'): + data = getattr(self, 'filter_GETXATTRDIR2args')(data) + return data + + def unpack_GETXATTRDIR2resok(self): + data = types.GETXATTRDIR2resok() + data.fh = self.unpack_nfs_fh() + data.attr = self.unpack_nfsfattr() + if hasattr(self, 'filter_GETXATTRDIR2resok'): + data = getattr(self, 'filter_GETXATTRDIR2resok')(data) + return data + + def unpack_GETXATTRDIR2res(self): + data = types.GETXATTRDIR2res() + data.status = self.unpack_nfsstat() + if data.status == const.ACL2_OK: + data.resok = self.unpack_GETXATTRDIR2resok() + else: + pass + if hasattr(self, 'filter_GETXATTRDIR2res'): + data = getattr(self, 'filter_GETXATTRDIR2res')(data) + return data + + def unpack_GETACL3args(self): + data = types.GETACL3args() + data.fh = self.unpack_nfs_fh3() + data.mask = self.unpack_u_int() + if hasattr(self, 'filter_GETACL3args'): + data = getattr(self, 'filter_GETACL3args')(data) + return data + + def unpack_GETACL3resok(self): + data = types.GETACL3resok() + data.attr = self.unpack_post_op_attr() + data.acl = self.unpack_secattr() + if hasattr(self, 'filter_GETACL3resok'): + data = getattr(self, 'filter_GETACL3resok')(data) + return data + + def unpack_GETACL3resfail(self): + data = types.GETACL3resfail() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_GETACL3resfail'): + data = getattr(self, 'filter_GETACL3resfail')(data) + return data + + def unpack_GETACL3res(self): + data = types.GETACL3res() + data.status = self.unpack_nfsstat3() + if data.status == const.ACL3_OK: + data.resok = self.unpack_GETACL3resok() + else: + data.resfail = self.unpack_GETACL3resfail() + if hasattr(self, 'filter_GETACL3res'): + data = getattr(self, 'filter_GETACL3res')(data) + return data + + def unpack_SETACL3args(self): + data = types.SETACL3args() + data.fh = self.unpack_nfs_fh3() + data.acl = self.unpack_secattr() + if hasattr(self, 'filter_SETACL3args'): + data = getattr(self, 'filter_SETACL3args')(data) + return data + + def unpack_SETACL3resok(self): + data = types.SETACL3resok() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_SETACL3resok'): + data = getattr(self, 'filter_SETACL3resok')(data) + return data + + def unpack_SETACL3resfail(self): + data = types.SETACL3resfail() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_SETACL3resfail'): + data = getattr(self, 'filter_SETACL3resfail')(data) + return data + + def unpack_SETACL3res(self): + data = types.SETACL3res() + data.status = self.unpack_nfsstat3() + if data.status == const.ACL3_OK: + data.resok = self.unpack_SETACL3resok() + else: + data.resfail = self.unpack_SETACL3resfail() + if hasattr(self, 'filter_SETACL3res'): + data = getattr(self, 'filter_SETACL3res')(data) + return data + + def unpack_GETXATTRDIR3args(self): + data = types.GETXATTRDIR3args() + data.fh = self.unpack_nfs_fh3() + data.create = self.unpack_bool() + if hasattr(self, 'filter_GETXATTRDIR3args'): + data = getattr(self, 'filter_GETXATTRDIR3args')(data) + return data + + def unpack_GETXATTRDIR3resok(self): + data = types.GETXATTRDIR3resok() + data.fh = self.unpack_nfs_fh3() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_GETXATTRDIR3resok'): + data = getattr(self, 'filter_GETXATTRDIR3resok')(data) + return data + + def unpack_GETXATTRDIR3res(self): + data = types.GETXATTRDIR3res() + data.status = self.unpack_nfsstat3() + if data.status == const.ACL3_OK: + data.resok = self.unpack_GETXATTRDIR3resok() + else: + pass + if hasattr(self, 'filter_GETXATTRDIR3res'): + data = getattr(self, 'filter_GETXATTRDIR3res')(data) + return data + + def unpack_GETACL4args(self): + data = types.GETACL4args() + data.fh = self.unpack_nfs_fh4() + data.mask = self.unpack_u_int() + if hasattr(self, 'filter_GETACL4args'): + data = getattr(self, 'filter_GETACL4args')(data) + return data + + def unpack_GETACL4resok(self): + data = types.GETACL4resok() + data.attr = self.unpack_post_op_attr() + data.acl = self.unpack_secattr() + if hasattr(self, 'filter_GETACL4resok'): + data = getattr(self, 'filter_GETACL4resok')(data) + return data + + def unpack_GETACL4resfail(self): + data = types.GETACL4resfail() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_GETACL4resfail'): + data = getattr(self, 'filter_GETACL4resfail')(data) + return data + + def unpack_GETACL4res(self): + data = types.GETACL4res() + data.status = self.unpack_nfsstat3() + if data.status == const.ACL4_OK: + data.resok = self.unpack_GETACL4resok() + else: + data.resfail = self.unpack_GETACL4resfail() + if hasattr(self, 'filter_GETACL4res'): + data = getattr(self, 'filter_GETACL4res')(data) + return data + + def unpack_SETACL4args(self): + data = types.SETACL4args() + data.fh = self.unpack_nfs_fh4() + data.acl = self.unpack_secattr() + if hasattr(self, 'filter_SETACL4args'): + data = getattr(self, 'filter_SETACL4args')(data) + return data + + def unpack_SETACL4resok(self): + data = types.SETACL4resok() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_SETACL4resok'): + data = getattr(self, 'filter_SETACL4resok')(data) + return data + + def unpack_SETACL4resfail(self): + data = types.SETACL4resfail() + data.attr = self.unpack_post_op_attr() + if hasattr(self, 'filter_SETACL4resfail'): + data = getattr(self, 'filter_SETACL4resfail')(data) + return data + + def unpack_SETACL4res(self): + data = types.SETACL4res() + data.status = self.unpack_nfsstat3() + if data.status == const.ACL4_OK: + data.resok = self.unpack_SETACL4resok() + else: + data.resfail = self.unpack_SETACL4resfail() + if hasattr(self, 'filter_SETACL4res'): + data = getattr(self, 'filter_SETACL4res')(data) + return data + diff --git a/nfs3/lib/nfs3/acl_type.py b/nfs3/lib/nfs3/acl_type.py new file mode 100644 index 0000000..5a9886b --- /dev/null +++ b/nfs3/lib/nfs3/acl_type.py @@ -0,0 +1,1035 @@ +# Generated by rpcgen.py from acl.x on Wed Jun 24 11:38:48 2026 +import acl_const as const +class nfs_fh: + # XDR definition: + # struct nfs_fh { + # opaque data[NFS_FHSIZE]; + # }; + def __init__(self, data=None): + self.data = data + + def __repr__(self): + out = [] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'nfs_fh(%s)' % ', '.join(out) + __str__ = __repr__ + +class nfs_fh3: + # XDR definition: + # struct nfs_fh3 { + # opaque data; + # }; + def __init__(self, data=None): + self.data = data + + def __repr__(self): + out = [] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'nfs_fh3(%s)' % ', '.join(out) + __str__ = __repr__ + +class nfs_fh4: + # XDR definition: + # struct nfs_fh4 { + # opaque data[NFS_FHSIZE]; + # }; + def __init__(self, data=None): + self.data = data + + def __repr__(self): + out = [] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'nfs_fh4(%s)' % ', '.join(out) + __str__ = __repr__ + +class post_op_attr: + # XDR definition: + # union post_op_attr switch(bool present) { + # case TRUE: + # fattr3 attributes; + # case FALSE: + # void; + # }; + def __init__(self, present=None, attributes=None): + self.present = present + self.attributes = attributes + + switch = property(lambda s: {const.TRUE:s.attributes,const.FALSE:None,}[s.present]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.present is not None: + out += ['present=%s' % repr(self.present)] + if self.attributes is not None: + out += ['attributes=%s' % repr(self.attributes)] + return 'post_op_attr(%s)' % ', '.join(out) + __str__ = __repr__ + +class specdata3: + # XDR definition: + # struct specdata3 { + # uint32 major; + # uint32 minor; + # }; + def __init__(self, major=None, minor=None): + self.major = major + self.minor = minor + + def __repr__(self): + out = [] + if self.major is not None: + out += ['major=%s' % repr(self.major)] + if self.minor is not None: + out += ['minor=%s' % repr(self.minor)] + return 'specdata3(%s)' % ', '.join(out) + __str__ = __repr__ + +class fattr3: + # XDR definition: + # struct fattr3 { + # ftype3 type; + # uint32 mode; + # uint32 nlink; + # uint32 uid; + # uint32 gid; + # uint64 size; + # uint64 used; + # specdata3 rdev; + # uint64 fsid; + # uint64 fileid; + # nfstime3 atime; + # nfstime3 mtime; + # nfstime3 ctime; + # }; + def __init__(self, type=None, mode=None, nlink=None, uid=None, gid=None, size=None, used=None, rdev=None, fsid=None, fileid=None, atime=None, mtime=None, ctime=None): + self.type = type + self.mode = mode + self.nlink = nlink + self.uid = uid + self.gid = gid + self.size = size + self.used = used + self.rdev = rdev + self.fsid = fsid + self.fileid = fileid + self.atime = atime + self.mtime = mtime + self.ctime = ctime + + def __repr__(self): + out = [] + if self.type is not None: + out += ['type=%s' % const.ftype3.get(self.type, self.type)] + if self.mode is not None: + out += ['mode=%s' % repr(self.mode)] + if self.nlink is not None: + out += ['nlink=%s' % repr(self.nlink)] + if self.uid is not None: + out += ['uid=%s' % repr(self.uid)] + if self.gid is not None: + out += ['gid=%s' % repr(self.gid)] + if self.size is not None: + out += ['size=%s' % repr(self.size)] + if self.used is not None: + out += ['used=%s' % repr(self.used)] + if self.rdev is not None: + out += ['rdev=%s' % repr(self.rdev)] + if self.fsid is not None: + out += ['fsid=%s' % repr(self.fsid)] + if self.fileid is not None: + out += ['fileid=%s' % repr(self.fileid)] + if self.atime is not None: + out += ['atime=%s' % repr(self.atime)] + if self.mtime is not None: + out += ['mtime=%s' % repr(self.mtime)] + if self.ctime is not None: + out += ['ctime=%s' % repr(self.ctime)] + return 'fattr3(%s)' % ', '.join(out) + __str__ = __repr__ + +class nfstime3: + # XDR definition: + # struct nfstime3 { + # uint32 seconds; + # uint32 nseconds; + # }; + def __init__(self, seconds=None, nseconds=None): + self.seconds = seconds + self.nseconds = nseconds + + def __repr__(self): + out = [] + if self.seconds is not None: + out += ['seconds=%s' % repr(self.seconds)] + if self.nseconds is not None: + out += ['nseconds=%s' % repr(self.nseconds)] + return 'nfstime3(%s)' % ', '.join(out) + __str__ = __repr__ + +class nfsfattr: + # XDR definition: + # struct nfsfattr { + # nfsftype na_type; + # uint64 na_mode; + # uint64 na_nlink; + # uint64 na_uid; + # uint64 na_gid; + # uint64 na_size; + # uint64 na_blocksize; + # uint64 na_rdev; + # uint64 na_blocks; + # uint64 na_fsid; + # uint64 na_nodeid; + # nfstime3 na_atime; + # nfstime3 na_mtime; + # nfstime3 na_ctime; + # }; + def __init__(self, na_type=None, na_mode=None, na_nlink=None, na_uid=None, na_gid=None, na_size=None, na_blocksize=None, na_rdev=None, na_blocks=None, na_fsid=None, na_nodeid=None, na_atime=None, na_mtime=None, na_ctime=None): + self.na_type = na_type + self.na_mode = na_mode + self.na_nlink = na_nlink + self.na_uid = na_uid + self.na_gid = na_gid + self.na_size = na_size + self.na_blocksize = na_blocksize + self.na_rdev = na_rdev + self.na_blocks = na_blocks + self.na_fsid = na_fsid + self.na_nodeid = na_nodeid + self.na_atime = na_atime + self.na_mtime = na_mtime + self.na_ctime = na_ctime + + def __repr__(self): + out = [] + if self.na_type is not None: + out += ['na_type=%s' % const.nfsftype.get(self.na_type, self.na_type)] + if self.na_mode is not None: + out += ['na_mode=%s' % repr(self.na_mode)] + if self.na_nlink is not None: + out += ['na_nlink=%s' % repr(self.na_nlink)] + if self.na_uid is not None: + out += ['na_uid=%s' % repr(self.na_uid)] + if self.na_gid is not None: + out += ['na_gid=%s' % repr(self.na_gid)] + if self.na_size is not None: + out += ['na_size=%s' % repr(self.na_size)] + if self.na_blocksize is not None: + out += ['na_blocksize=%s' % repr(self.na_blocksize)] + if self.na_rdev is not None: + out += ['na_rdev=%s' % repr(self.na_rdev)] + if self.na_blocks is not None: + out += ['na_blocks=%s' % repr(self.na_blocks)] + if self.na_fsid is not None: + out += ['na_fsid=%s' % repr(self.na_fsid)] + if self.na_nodeid is not None: + out += ['na_nodeid=%s' % repr(self.na_nodeid)] + if self.na_atime is not None: + out += ['na_atime=%s' % repr(self.na_atime)] + if self.na_mtime is not None: + out += ['na_mtime=%s' % repr(self.na_mtime)] + if self.na_ctime is not None: + out += ['na_ctime=%s' % repr(self.na_ctime)] + return 'nfsfattr(%s)' % ', '.join(out) + __str__ = __repr__ + +class aclent: + # XDR definition: + # struct aclent { + # int type; + # uid id; + # o_mode perm; + # }; + def __init__(self, type=None, id=None, perm=None): + self.type = type + self.id = id + self.perm = perm + + def __repr__(self): + out = [] + if self.type is not None: + out += ['type=%s' % repr(self.type)] + if self.id is not None: + out += ['id=%s' % repr(self.id)] + if self.perm is not None: + out += ['perm=%s' % repr(self.perm)] + return 'aclent(%s)' % ', '.join(out) + __str__ = __repr__ + +class secattr: + # XDR definition: + # struct secattr { + # u_int mask; + # int aclcnt; + # aclent aclent; + # int dfaclcnt; + # aclent dfaclent; + # }; + def __init__(self, mask=None, aclcnt=None, aclent=None, dfaclcnt=None, dfaclent=None): + self.mask = mask + self.aclcnt = aclcnt + self.aclent = aclent + self.dfaclcnt = dfaclcnt + self.dfaclent = dfaclent + + def __repr__(self): + out = [] + if self.mask is not None: + out += ['mask=%s' % repr(self.mask)] + if self.aclcnt is not None: + out += ['aclcnt=%s' % repr(self.aclcnt)] + if self.aclent is not None: + out += ['aclent=%s' % repr(self.aclent)] + if self.dfaclcnt is not None: + out += ['dfaclcnt=%s' % repr(self.dfaclcnt)] + if self.dfaclent is not None: + out += ['dfaclent=%s' % repr(self.dfaclent)] + return 'secattr(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL2args: + # XDR definition: + # struct GETACL2args { + # nfs_fh fh; + # u_int mask; + # }; + def __init__(self, fh=None, mask=None): + self.fh = fh + self.mask = mask + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.mask is not None: + out += ['mask=%s' % repr(self.mask)] + return 'GETACL2args(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL2resok: + # XDR definition: + # struct GETACL2resok { + # nfsfattr attr; + # secattr acl; + # }; + def __init__(self, attr=None, acl=None): + self.attr = attr + self.acl = acl + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + if self.acl is not None: + out += ['acl=%s' % repr(self.acl)] + return 'GETACL2resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL2res: + # XDR definition: + # union GETACL2res switch(nfsstat status) { + # case ACL2_OK: + # GETACL2resok resok; + # default: + # void; + # }; + def __init__(self, status=None, resok=None): + self.status = status + self.resok = resok + + switch = property(lambda s: {const.ACL2_OK:s.resok,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % repr(self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + return 'GETACL2res(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL2args: + # XDR definition: + # struct SETACL2args { + # nfs_fh fh; + # secattr acl; + # }; + def __init__(self, fh=None, acl=None): + self.fh = fh + self.acl = acl + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.acl is not None: + out += ['acl=%s' % repr(self.acl)] + return 'SETACL2args(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL2resok: + # XDR definition: + # struct SETACL2resok { + # nfsfattr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'SETACL2resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL2res: + # XDR definition: + # union SETACL2res switch(nfsstat status) { + # case ACL2_OK: + # SETACL2resok resok; + # default: + # void; + # }; + def __init__(self, status=None, resok=None): + self.status = status + self.resok = resok + + switch = property(lambda s: {const.ACL2_OK:s.resok,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % repr(self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + return 'SETACL2res(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETATTR2args: + # XDR definition: + # struct GETATTR2args { + # nfs_fh fh; + # }; + def __init__(self, fh=None): + self.fh = fh + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + return 'GETATTR2args(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETATTR2resok: + # XDR definition: + # struct GETATTR2resok { + # nfs_fh attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'GETATTR2resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETATTR2res: + # XDR definition: + # union GETATTR2res switch(nfsstat status) { + # case ACL2_OK: + # GETATTR2resok resok; + # default: + # void; + # }; + def __init__(self, status=None, resok=None): + self.status = status + self.resok = resok + + switch = property(lambda s: {const.ACL2_OK:s.resok,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % repr(self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + return 'GETATTR2res(%s)' % ', '.join(out) + __str__ = __repr__ + +class ACCESS2args: + # XDR definition: + # struct ACCESS2args { + # nfs_fh fh; + # uint32 access; + # }; + def __init__(self, fh=None, access=None): + self.fh = fh + self.access = access + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.access is not None: + out += ['access=%s' % repr(self.access)] + return 'ACCESS2args(%s)' % ', '.join(out) + __str__ = __repr__ + +class ACCESS2resok: + # XDR definition: + # struct ACCESS2resok { + # nfsfattr attr; + # uint32 access; + # }; + def __init__(self, attr=None, access=None): + self.attr = attr + self.access = access + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + if self.access is not None: + out += ['access=%s' % repr(self.access)] + return 'ACCESS2resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class ACCESS2res: + # XDR definition: + # union ACCESS2res switch(nfsstat status) { + # case ACL2_OK: + # ACCESS2resok resok; + # default: + # void; + # }; + def __init__(self, status=None, resok=None): + self.status = status + self.resok = resok + + switch = property(lambda s: {const.ACL2_OK:s.resok,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % repr(self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + return 'ACCESS2res(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETXATTRDIR2args: + # XDR definition: + # struct GETXATTRDIR2args { + # nfs_fh fh; + # bool create; + # }; + def __init__(self, fh=None, create=None): + self.fh = fh + self.create = create + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.create is not None: + out += ['create=%s' % repr(self.create)] + return 'GETXATTRDIR2args(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETXATTRDIR2resok: + # XDR definition: + # struct GETXATTRDIR2resok { + # nfs_fh fh; + # nfsfattr attr; + # }; + def __init__(self, fh=None, attr=None): + self.fh = fh + self.attr = attr + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'GETXATTRDIR2resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETXATTRDIR2res: + # XDR definition: + # union GETXATTRDIR2res switch(nfsstat status) { + # case ACL2_OK: + # GETXATTRDIR2resok resok; + # default: + # void; + # }; + def __init__(self, status=None, resok=None): + self.status = status + self.resok = resok + + switch = property(lambda s: {const.ACL2_OK:s.resok,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % repr(self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + return 'GETXATTRDIR2res(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL3args: + # XDR definition: + # struct GETACL3args { + # nfs_fh3 fh; + # u_int mask; + # }; + def __init__(self, fh=None, mask=None): + self.fh = fh + self.mask = mask + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.mask is not None: + out += ['mask=%s' % repr(self.mask)] + return 'GETACL3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL3resok: + # XDR definition: + # struct GETACL3resok { + # post_op_attr attr; + # secattr acl; + # }; + def __init__(self, attr=None, acl=None): + self.attr = attr + self.acl = acl + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + if self.acl is not None: + out += ['acl=%s' % repr(self.acl)] + return 'GETACL3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL3resfail: + # XDR definition: + # struct GETACL3resfail { + # post_op_attr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'GETACL3resfail(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL3res: + # XDR definition: + # union GETACL3res switch(nfsstat3 status) { + # case ACL3_OK: + # GETACL3resok resok; + # default: + # GETACL3resfail resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.ACL3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'GETACL3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL3args: + # XDR definition: + # struct SETACL3args { + # nfs_fh3 fh; + # secattr acl; + # }; + def __init__(self, fh=None, acl=None): + self.fh = fh + self.acl = acl + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.acl is not None: + out += ['acl=%s' % repr(self.acl)] + return 'SETACL3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL3resok: + # XDR definition: + # struct SETACL3resok { + # post_op_attr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'SETACL3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL3resfail: + # XDR definition: + # struct SETACL3resfail { + # post_op_attr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'SETACL3resfail(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL3res: + # XDR definition: + # union SETACL3res switch(nfsstat3 status) { + # case ACL3_OK: + # SETACL3resok resok; + # default: + # SETACL3resfail resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.ACL3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'SETACL3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETXATTRDIR3args: + # XDR definition: + # struct GETXATTRDIR3args { + # nfs_fh3 fh; + # bool create; + # }; + def __init__(self, fh=None, create=None): + self.fh = fh + self.create = create + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.create is not None: + out += ['create=%s' % repr(self.create)] + return 'GETXATTRDIR3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETXATTRDIR3resok: + # XDR definition: + # struct GETXATTRDIR3resok { + # nfs_fh3 fh; + # post_op_attr attr; + # }; + def __init__(self, fh=None, attr=None): + self.fh = fh + self.attr = attr + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'GETXATTRDIR3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETXATTRDIR3res: + # XDR definition: + # union GETXATTRDIR3res switch(nfsstat3 status) { + # case ACL3_OK: + # GETXATTRDIR3resok resok; + # default: + # void; + # }; + def __init__(self, status=None, resok=None): + self.status = status + self.resok = resok + + switch = property(lambda s: {const.ACL3_OK:s.resok,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + return 'GETXATTRDIR3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL4args: + # XDR definition: + # struct GETACL4args { + # nfs_fh4 fh; + # u_int mask; + # }; + def __init__(self, fh=None, mask=None): + self.fh = fh + self.mask = mask + + def __getattr__(self, attr): + return getattr(self.fh, attr) + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.mask is not None: + out += ['mask=%s' % repr(self.mask)] + return 'GETACL4args(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL4resok: + # XDR definition: + # struct GETACL4resok { + # post_op_attr attr; + # secattr acl; + # }; + def __init__(self, attr=None, acl=None): + self.attr = attr + self.acl = acl + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + if self.acl is not None: + out += ['acl=%s' % repr(self.acl)] + return 'GETACL4resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL4resfail: + # XDR definition: + # struct GETACL4resfail { + # post_op_attr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'GETACL4resfail(%s)' % ', '.join(out) + __str__ = __repr__ + +class GETACL4res: + # XDR definition: + # union GETACL4res switch(nfsstat3 status) { + # case ACL4_OK: + # GETACL4resok resok; + # default: + # GETACL4resfail resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.ACL4_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'GETACL4res(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL4args: + # XDR definition: + # struct SETACL4args { + # nfs_fh4 fh; + # secattr acl; + # }; + def __init__(self, fh=None, acl=None): + self.fh = fh + self.acl = acl + + def __repr__(self): + out = [] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.acl is not None: + out += ['acl=%s' % repr(self.acl)] + return 'SETACL4args(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL4resok: + # XDR definition: + # struct SETACL4resok { + # post_op_attr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'SETACL4resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL4resfail: + # XDR definition: + # struct SETACL4resfail { + # post_op_attr attr; + # }; + def __init__(self, attr=None): + self.attr = attr + + def __getattr__(self, attr): + return getattr(self.attr, attr) + + def __repr__(self): + out = [] + if self.attr is not None: + out += ['attr=%s' % repr(self.attr)] + return 'SETACL4resfail(%s)' % ', '.join(out) + __str__ = __repr__ + +class SETACL4res: + # XDR definition: + # union SETACL4res switch(nfsstat3 status) { + # case ACL4_OK: + # SETACL4resok resok; + # default: + # SETACL4resfail resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.ACL4_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'SETACL4res(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/nfs3/acllib.py b/nfs3/lib/nfs3/acllib.py new file mode 100644 index 0000000..a96e3b5 --- /dev/null +++ b/nfs3/lib/nfs3/acllib.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python +# acllib.py - POSIX ACL library for python + +import rpc +from xdrlib import Error as XDRError +from acl_const import * +from acl_type import * +from acl_pack import * +from nfs3_const import * +from nfs3_type import * +from nfs3_pack import * + +AuthSys = rpc.SecAuthSys(0, 'jupiter', 103558, 100, []) + + +class ACLException(rpc.RPCError): + pass + + +# An ACL procedure returned an error +class BadACLRes(ACLException): + def __init__(self, errcode, msg=None): + self.errcode = errcode + if msg: + self.msg = msg + ': ' + else: + self.msg = '' + + def __str__(self): + return self.msg + "should return ACL3_OK, instead got %s" % \ + (nfsstat3[self.errcode]) + + +class ACLClient(rpc.RPCClient): + def __init__(self, id, host='localhost', port=300, homedir=['pynfs'], + sec_list=[AuthSys], opts=None, acl_version=NFS_ACL_V3): + self.ipv6 = getattr(opts, 'ipv6', False) + self.packer = ACLPacker() + self.unpacker = ACLUnpacker('') + self.homedir = homedir + self.id = id + self.opts = opts + uselowport = getattr(opts, "secure", False) + rpc.RPCClient.__init__(self, host, port, program=NFS_ACL_PROGRAM, + version=acl_version, sec_list=sec_list, + uselowport=uselowport, ipv6=self.ipv6) + self.server_address = (host, port) + print("seclist = ", sec_list) + + def acl_pack_v3(self, procedure, data): + p = self.packer + + if procedure == ACLPROC3_NULL: + pass + elif procedure == ACLPROC3_GETACL: + p.pack_GETACL3args(data) + elif procedure == ACLPROC3_SETACL: + p.pack_SETACL3args(data) + elif procedure == ACLPROC3_GETXATTRDIR: + p.pack_GETXATTRDIR3args(data) + else: + # raise XDRError, 'bad switch=%s' % procedure + print(("XDRError: bad switch=%s" % procedure)) + + # XXX Fancy unpacking, into status, data, etc + def acl_unpack_v3(self, procedure): + un_p = self.unpacker + if procedure == ACLPROC3_NULL: + pass + elif procedure == ACLPROC3_GETACL: + return un_p.unpack_GETACL3res() + elif procedure == ACLPROC3_SETACL: + return un_p.unpack_SETACL3res() + elif procedure == ACLPROC3_GETXATTRDIR: + return un_p.unpack_GETXATTRDIR3res() + else: + # raise XDRError, 'bad switch=%s' % procedure + print(("XDRError: bad switch=%s" % procedure)) + + def acl_pack_v2(self, procedure, data): + p = self.packer + + if procedure == ACLPROC2_NULL: + pass + elif procedure == ACLPROC2_GETACL: + p.pack_GETACL2args(data) + elif procedure == ACLPROC2_SETACL: + p.pack_SETACL2args(data) + elif procedure == ACLPROC2_GETATTR: + p.pack_GETATTR2args(data) + elif procedure == ACLPROC2_ACCESS: + p.pack_ACCESS2args(data) + elif procedure == ACLPROC2_GETXATTRDIR: + p.pack_GETXATTRDIR2args(data) + else: + raise XDRError('bad switch=%s' % procedure) + + # XXX Fancy unpacking, into status, data, etc + def acl_unpack_v2(self, procedure): + un_p = self.unpacker + if procedure == ACLPROC2_NULL: + pass + elif procedure == ACLPROC2_GETACL: + return un_p.unpack_GETACL2res() + elif procedure == ACLPROC2_SETACL: + return un_p.unpack_SETACL2res() + elif procedure == ACLPROC2_GETATTR: + return un_p.unpack_SETACL2res() + elif procedure == ACLPROC2_ACCESS: + return un_p.unpack_SETACL2res() + elif procedure == ACLPROC2_GETXATTRDIR: + return un_p.unpack_GETXATTRDIR2res() + else: + raise XDRError('bad switch=%s' % procedure) + + def acl_pack_v4(self, procedure, data): + p = self.packer + + if procedure == ACLPROC2_NULL: + pass + elif procedure == ACLPROC2_GETACL: + p.pack_GETACL2args(data) + elif procedure == ACLPROC2_SETACL: + p.pack_SETACL2args(data) + else: + raise XDRError('bad switch=%s' % procedure) + + # XXX Fancy unpacking, into status, data, etc + def acl_unpack_v4(self, procedure): + un_p = self.unpacker + if procedure == ACLPROC2_NULL: + pass + elif procedure == ACLPROC2_GETACL: + return un_p.unpack_GETACL2res() + elif procedure == ACLPROC2_SETACL: + return un_p.unpack_SETACL2res() + else: + raise XDRError('bad switch=%s' % procedure) + + pack_to_version = { + NFS_ACL_V2: acl_pack_v2, + NFS_ACL_V3: acl_pack_v3, + NFS_ACL_V4: acl_pack_v4 + } + unpack_to_version = { + NFS_ACL_V2: acl_unpack_v2, + NFS_ACL_V3: acl_unpack_v3, + NFS_ACL_V4: acl_unpack_v4 + } + + def acl_call(self, procedure, data='', acl_version=NFS_ACL_V3): + # Pack Request + p = self.packer + un_p = self.unpacker + p.reset() + + print(("### DEBUG: acl_version={}".format(acl_version))) + self.pack_to_version[acl_version](self, procedure, data) + + # Make Call + res = self.call(procedure, p.get_buffer()) + + # Unpack Reply + un_p.reset(res) + res = self.unpack_to_version[acl_version](self, procedure) + un_p.done() + + # XXX Error checking? + return res + + """ + ACLV3 OPERATIONS (NFS3) + """ + + def acl_null(self): + return self.acl_call(ACLPROC3_NULL) + + def acl_getacl(self, file_handle, mask=None): + arg_list = GETACL3args(nfs_fh3(file_handle), mask) + return self.acl_call(ACLPROC3_GETACL, arg_list) + + def acl_setacl(self, file_handle, acls, mask=0x0): + """ + * This is the format of an ACL which is passed over the network. + struct aclent { + int type; + uid id; + o_mode perm; + }; + """ + args_list = SETACL3args(nfs_fh3(file_handle), secattr(mask, len(acls), [aclent(*acl) for acl in acls], 0, [])) + return self.acl_call(ACLPROC3_SETACL, args_list) + + def acl_getxattrdir(self, file_handle, create=False): + arg_list = GETXATTRDIR3args(nfs_fh3(file_handle), create) + return self.acl_call(ACLPROC3_GETXATTRDIR, arg_list) + + def acl_all_programms(self, file_handle, proc): + arg_list = GETXATTRDIR3args(nfs_fh3(file_handle), False) + return self.acl_call(proc, arg_list) + + """ + ACLV2 OPERATIONS (NFS2) + """ + + def acl2_null(self): + return self.acl_call(ACLPROC2_NULL, acl_version=NFS_ACL_V2) + + def acl2_getattr(self, file_handle): + arg_list = GETATTR2args(nfs_fh(file_handle)) + return self.acl_call(ACLPROC2_GETATTR, arg_list, acl_version=NFS_ACL_V2) + + def acl2_access(self, file_handle, access): + arg_list = ACCESS2args(nfs_fh(file_handle), access) + return self.acl_call(ACLPROC2_ACCESS, arg_list, acl_version=NFS_ACL_V2) + + def acl2_getacl(self, file_handle, mask=None): + arg_list = GETACL2args(nfs_fh(file_handle), mask) + return self.acl_call(ACLPROC2_GETACL, arg_list, acl_version=NFS_ACL_V2) + + def acl2_setacl(self, file_handle, acls, mask=0x0): + """ + * This is the format of an ACL which is passed over the network. + struct aclent { + int type; + uid id; + o_mode perm; + }; + """ + args_list = SETACL2args(nfs_fh(file_handle), secattr(mask, len(acls), [aclent(*acl) for acl in acls], 0, [])) + return self.acl_call(ACLPROC2_SETACL, args_list, acl_version=NFS_ACL_V2) + + def acl2_getxattrdir(self, file_handle, create=False): + arg_list = GETXATTRDIR2args(nfs_fh(file_handle), create) + return self.acl_call(ACLPROC2_GETXATTRDIR, arg_list, acl_version=NFS_ACL_V2) + + """ + ACLV4 OPERATIONS (NFS4) + """ + + def acl4_null(self): + return self.acl_call(ACLPROC4_NULL, acl_version=NFS_ACL_V4) + + def acl4_getacl(self, file_handle, mask=None): + arg_list = GETACL4args(nfs_fh4(file_handle), mask) + return self.acl_call(ACLPROC4_GETACL, arg_list, acl_version=NFS_ACL_V4) + + def acl4_setacl(self, file_handle, acls, mask=0x0): + """ + * This is the format of an ACL which is passed over the network. + struct aclent { + int type; + uid id; + o_mode perm; + }; + """ + args_list = SETACL4args(nfs_fh4(file_handle), secattr(mask, len(acls), [aclent(*acl) for acl in acls], 0, [])) + return self.acl_call(ACLPROC4_SETACL, args_list, acl_version=NFS_ACL_V4) + + """ + UTILITY FUNCTIONS + """ + + # Verify if ACL call was successful, + # raise BadACLRes otherwise + def acl_check_result(self, res, msg=None): + if not res.status: + return + raise BadACLRes(res.status, msg) diff --git a/nfs3/lib/nfs3/mount.x b/nfs3/lib/nfs3/mount.x new file mode 100644 index 0000000..c628927 --- /dev/null +++ b/nfs3/lib/nfs3/mount.x @@ -0,0 +1,114 @@ +/* $Id: mount_prot.x,v 1.1 2006/05/19 20:59:18 max Exp $ */ + +const MNTPATHLEN = 1024; /* Maximum bytes in a path name */ +const MNTNAMLEN = 255; /* Maximum bytes in a name */ +const FHSIZE2 = 32; /* Maximum bytes in a V2 file handle */ +const FHSIZE3 = 64; /* Maximum bytes in a V3 file handle */ + +typedef opaque fhandle2[FHSIZE2]; +typedef opaque fhandle3; +typedef string dirpath; +typedef string name; + +union fhstatus switch (unsigned fhs_status) { +case 0: + fhandle2 fhs_fhandle; +default: + void; +}; + +enum mountstat3 { + MNT3_OK = 0, /* no error */ + MNT3ERR_PERM = 1, /* Not owner */ + MNT3ERR_NOENT = 2, /* No such file or directory */ + MNT3ERR_IO = 5, /* I/O error */ + MNT3ERR_ACCES = 13, /* Permission denied */ + MNT3ERR_NOTDIR = 20, /* Not a directory */ + MNT3ERR_INVAL = 22, /* Invalid argument */ + MNT3ERR_NAMETOOLONG = 63, /* Filename too long */ + MNT3ERR_NOTSUPP = 10004, /* Operation not supported */ + MNT3ERR_SERVERFAULT = 10006 /* A failure on the server */ +}; + +struct mountres3_ok { + fhandle3 fhandle; + int auth_flavors<>; +}; + +union mountres3 switch (mountstat3 fhs_status) { +case MNT3_OK: + mountres3_ok mountinfo; +default: + void; +}; + +/* XXX ZACK - THIS IS ACTUALLY ILLEGAL XDR +typedef struct mountbody *mountlist; + +struct mountbody { + name ml_hostname; + dirpath ml_directory; + mountlist ml_next; +}; +*/ + +typedef struct { + name ml_hostname; + dirpath ml_directory; + mountlist ml_next; +} *mountlist; + + +/* XXX ZACK - Illegal XDR +typedef struct groupnode *groups; + +struct groupnode { + name gr_name; + groups gr_next; +}; +*/ + +typedef struct { + name gr_name; + groups *gr_next; +} groupnode; + +typedef groupnode *groups; + +/* XXX ZACK - Illegal XDR +typedef struct exportnode *exports; + +struct exportnode { + dirpath ex_dir; + groups ex_groups; + exports ex_next; +}; +*/ + +typedef struct { + dirpath ex_dir; + groups ex_groups; + exportnode *ex_next; +} exportnode; + +typedef exportnode *exports; + +program MOUNT_PROGRAM { + version MOUNT_V1 { + void MOUNTPROC_NULL (void) = 0; + fhstatus MOUNTPROC_MNT (dirpath) = 1; + mountlist MOUNTPROC_DUMP (void) = 2; + void MOUNTPROC_UMNT (dirpath) = 3; + void MOUNTPROC_UMNTALL (void) = 4; + exports MOUNTPROC_EXPORT (void) = 5; + exports MOUNTPROC_EXPORTALL (void) = 6; + } = 1; + version MOUNT_V3 { + void MOUNTPROC3_NULL (void) = 0; + mountres3 MOUNTPROC3_MNT (dirpath) = 1; + mountlist MOUNTPROC3_DUMP (void) = 2; + void MOUNTPROC3_UMNT (dirpath) = 3; + void MOUNTPROC3_UMNTALL (void) = 4; + exports MOUNTPROC3_EXPORT (void) = 5; + } = 3; +} = 100005; diff --git a/nfs3/lib/nfs3/mount_const.py b/nfs3/lib/nfs3/mount_const.py new file mode 100644 index 0000000..6cca4a7 --- /dev/null +++ b/nfs3/lib/nfs3/mount_const.py @@ -0,0 +1,43 @@ +# Generated by rpcgen.py from mount.x on Wed Jun 24 11:38:48 2026 +MOUNTPROC_NULL = 0 +MOUNTPROC_MNT = 1 +MOUNTPROC_DUMP = 2 +MOUNTPROC_UMNT = 3 +MOUNTPROC_UMNTALL = 4 +MOUNTPROC_EXPORT = 5 +MOUNTPROC_EXPORTALL = 6 +MOUNTPROC3_NULL = 0 +MOUNTPROC3_MNT = 1 +MOUNTPROC3_DUMP = 2 +MOUNTPROC3_UMNT = 3 +MOUNTPROC3_UMNTALL = 4 +MOUNTPROC3_EXPORT = 5 +MNTPATHLEN = 1024 +MNTNAMLEN = 255 +FHSIZE2 = 32 +FHSIZE3 = 64 +MNT3_OK = 0 +MNT3ERR_PERM = 1 +MNT3ERR_NOENT = 2 +MNT3ERR_IO = 5 +MNT3ERR_ACCES = 13 +MNT3ERR_NOTDIR = 20 +MNT3ERR_INVAL = 22 +MNT3ERR_NAMETOOLONG = 63 +MNT3ERR_NOTSUPP = 10004 +MNT3ERR_SERVERFAULT = 10006 +mountstat3 = { + 0 : 'MNT3_OK', + 1 : 'MNT3ERR_PERM', + 2 : 'MNT3ERR_NOENT', + 5 : 'MNT3ERR_IO', + 13 : 'MNT3ERR_ACCES', + 20 : 'MNT3ERR_NOTDIR', + 22 : 'MNT3ERR_INVAL', + 63 : 'MNT3ERR_NAMETOOLONG', + 10004 : 'MNT3ERR_NOTSUPP', + 10006 : 'MNT3ERR_SERVERFAULT', +} +MOUNT_PROGRAM = 100005 +MOUNT_V1 = 1 +MOUNT_V3 = 3 diff --git a/nfs3/lib/nfs3/mount_pack.py b/nfs3/lib/nfs3/mount_pack.py new file mode 100644 index 0000000..375bf58 --- /dev/null +++ b/nfs3/lib/nfs3/mount_pack.py @@ -0,0 +1,305 @@ +# Generated by rpcgen.py from mount.x on Wed Jun 24 11:38:48 2026 +import mount_const as const +import mount_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class MOUNTPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + def pack_fhandle2(self, data): + if hasattr(self, 'filter_fhandle2'): + data = getattr(self, 'filter_fhandle2')(data) + self.pack_fopaque(const.FHSIZE2, data) + + def pack_fhandle3(self, data): + if hasattr(self, 'filter_fhandle3'): + data = getattr(self, 'filter_fhandle3')(data) + if len(data) > const.FHSIZE3 and self.check_array: + raise XDRError('array length too long for data') + self.pack_opaque(data) + + def pack_dirpath(self, data): + if hasattr(self, 'filter_dirpath'): + data = getattr(self, 'filter_dirpath')(data) + if len(data) > const.MNTPATHLEN and self.check_array: + raise XDRError('array length too long for data') + self.pack_string(data) + + def pack_name(self, data): + if hasattr(self, 'filter_name'): + data = getattr(self, 'filter_name')(data) + if len(data) > const.MNTNAMLEN and self.check_array: + raise XDRError('array length too long for data') + self.pack_string(data) + + def pack_fhstatus(self, data): + if hasattr(self, 'filter_fhstatus'): + data = getattr(self, 'filter_fhstatus')(data) + if data.fhs_status is None: + raise TypeError('data.fhs_status == None') + self.pack_unsigned(data.fhs_status) + if data.fhs_status == 0: + if data.fhs_fhandle is None: + raise TypeError('data.fhs_fhandle == None') + self.pack_fhandle2(data.fhs_fhandle) + else: + pass + + def pack_mountstat3(self, data): + if hasattr(self, 'filter_mountstat3'): + data = getattr(self, 'filter_mountstat3')(data) + if self.check_enum and data not in [const.MNT3_OK, const.MNT3ERR_PERM, const.MNT3ERR_NOENT, const.MNT3ERR_IO, const.MNT3ERR_ACCES, const.MNT3ERR_NOTDIR, const.MNT3ERR_INVAL, const.MNT3ERR_NAMETOOLONG, const.MNT3ERR_NOTSUPP, const.MNT3ERR_SERVERFAULT]: + raise XDRError('value=%s not in enum mountstat3' % data) + self.pack_int(data) + + def pack_mountres3_ok(self, data): + if hasattr(self, 'filter_mountres3_ok'): + data = getattr(self, 'filter_mountres3_ok')(data) + if data.fhandle is None: + raise TypeError('data.fhandle == None') + self.pack_fhandle3(data.fhandle) + if data.auth_flavors is None: + raise TypeError('data.auth_flavors == None') + self.pack_array(data.auth_flavors, self.pack_int) + + def pack_mountres3(self, data): + if hasattr(self, 'filter_mountres3'): + data = getattr(self, 'filter_mountres3')(data) + if data.fhs_status is None: + raise TypeError('data.fhs_status == None') + self.pack_mountstat3(data.fhs_status) + if data.fhs_status == const.MNT3_OK: + if data.mountinfo is None: + raise TypeError('data.mountinfo == None') + self.pack_mountres3_ok(data.mountinfo) + else: + pass + + def pack_mountlist(self, data): + if hasattr(self, 'filter_mountlist'): + data = getattr(self, 'filter_mountlist')(data) + def pack_one_mountlist(self, data): + if data.ml_hostname is None: + raise TypeError('data.ml_hostname == None') + self.pack_name(data.ml_hostname) + if data.ml_directory is None: + raise TypeError('data.ml_directory == None') + self.pack_dirpath(data.ml_directory) + if data.ml_next is None: + raise TypeError('data.ml_next == None') + self.pack_mountlist(data.ml_next) + if len(data) > 1: + raise XDRError('array length too long') + self.pack_array(data, pack_one_mountlist) + + def pack_groupnode(self, data): + if hasattr(self, 'filter_groupnode'): + data = getattr(self, 'filter_groupnode')(data) + if data.gr_name is None: + raise TypeError('data.gr_name == None') + self.pack_name(data.gr_name) + if data.gr_next is None: + raise TypeError('data.gr_next == None') + if len(data.gr_next) > 1 and self.check_array: + raise XDRError('array length too long for data.gr_next') + self.pack_array(data.gr_next, self.pack_groups) + + def pack_groups(self, data): + if hasattr(self, 'filter_groups'): + data = getattr(self, 'filter_groups')(data) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + self.pack_array(data, self.pack_groupnode) + + def pack_exportnode(self, data): + if hasattr(self, 'filter_exportnode'): + data = getattr(self, 'filter_exportnode')(data) + if data.ex_dir is None: + raise TypeError('data.ex_dir == None') + self.pack_dirpath(data.ex_dir) + if data.ex_groups is None: + raise TypeError('data.ex_groups == None') + self.pack_groups(data.ex_groups) + if data.ex_next is None: + raise TypeError('data.ex_next == None') + if len(data.ex_next) > 1 and self.check_array: + raise XDRError('array length too long for data.ex_next') + self.pack_array(data.ex_next, self.pack_exportnode) + + def pack_exports(self, data): + if hasattr(self, 'filter_exports'): + data = getattr(self, 'filter_exports')(data) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + self.pack_array(data, self.pack_exportnode) + +class MOUNTUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + def unpack_fhandle2(self): + data = self.unpack_fopaque(const.FHSIZE2) + if hasattr(self, 'filter_fhandle2'): + data = getattr(self, 'filter_fhandle2')(data) + return data + + def unpack_fhandle3(self): + data = self.unpack_opaque() + if len(data) > const.FHSIZE3 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_fhandle3'): + data = getattr(self, 'filter_fhandle3')(data) + return data + + def unpack_dirpath(self): + data = self.unpack_string() + if len(data) > const.MNTPATHLEN and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_dirpath'): + data = getattr(self, 'filter_dirpath')(data) + return data + + def unpack_name(self): + data = self.unpack_string() + if len(data) > const.MNTNAMLEN and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_name'): + data = getattr(self, 'filter_name')(data) + return data + + def unpack_fhstatus(self): + data = types.fhstatus() + data.fhs_status = self.unpack_unsigned() + if data.fhs_status == 0: + data.fhs_fhandle = self.unpack_fhandle2() + else: + pass + if hasattr(self, 'filter_fhstatus'): + data = getattr(self, 'filter_fhstatus')(data) + return data + + def unpack_mountstat3(self): + data = self.unpack_int() + if self.check_enum and data not in [const.MNT3_OK, const.MNT3ERR_PERM, const.MNT3ERR_NOENT, const.MNT3ERR_IO, const.MNT3ERR_ACCES, const.MNT3ERR_NOTDIR, const.MNT3ERR_INVAL, const.MNT3ERR_NAMETOOLONG, const.MNT3ERR_NOTSUPP, const.MNT3ERR_SERVERFAULT]: + raise XDRError('value=%s not in enum mountstat3' % data) + if hasattr(self, 'filter_mountstat3'): + data = getattr(self, 'filter_mountstat3')(data) + return data + + def unpack_mountres3_ok(self): + data = types.mountres3_ok() + data.fhandle = self.unpack_fhandle3() + data.auth_flavors = self.unpack_array(self.unpack_int) + if hasattr(self, 'filter_mountres3_ok'): + data = getattr(self, 'filter_mountres3_ok')(data) + return data + + def unpack_mountres3(self): + data = types.mountres3() + data.fhs_status = self.unpack_mountstat3() + if data.fhs_status == const.MNT3_OK: + data.mountinfo = self.unpack_mountres3_ok() + else: + pass + if hasattr(self, 'filter_mountres3'): + data = getattr(self, 'filter_mountres3')(data) + return data + + def unpack_mountlist(self): + def unpack_one_mountlist(self, data): + data = types.mountlist() + data.ml_hostname = self.unpack_name() + data.ml_directory = self.unpack_dirpath() + data.ml_next = self.unpack_mountlist() + return data + data = self.unpack_array(unpack_one_mountlist) + if len(data) > 1: + raise XDRError('array length too long') + if hasattr(self, 'filter_mountlist'): + data = getattr(self, 'filter_mountlist')(data) + return data + + def unpack_groupnode(self): + data = types.groupnode() + data.gr_name = self.unpack_name() + data.gr_next = self.unpack_array(self.unpack_groups) + if len(data.gr_next) > 1 and self.check_array: + raise XDRError('array length too long for data.gr_next') + if hasattr(self, 'filter_groupnode'): + data = getattr(self, 'filter_groupnode')(data) + return data + + def unpack_groups(self): + data = self.unpack_array(self.unpack_groupnode) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_groups'): + data = getattr(self, 'filter_groups')(data) + return data + + def unpack_exportnode(self): + data = types.exportnode() + data.ex_dir = self.unpack_dirpath() + data.ex_groups = self.unpack_groups() + data.ex_next = self.unpack_array(self.unpack_exportnode) + if len(data.ex_next) > 1 and self.check_array: + raise XDRError('array length too long for data.ex_next') + if hasattr(self, 'filter_exportnode'): + data = getattr(self, 'filter_exportnode')(data) + return data + + def unpack_exports(self): + data = self.unpack_array(self.unpack_exportnode) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_exports'): + data = getattr(self, 'filter_exports')(data) + return data + diff --git a/nfs3/lib/nfs3/mount_type.py b/nfs3/lib/nfs3/mount_type.py new file mode 100644 index 0000000..8e1e5b5 --- /dev/null +++ b/nfs3/lib/nfs3/mount_type.py @@ -0,0 +1,138 @@ +# Generated by rpcgen.py from mount.x on Wed Jun 24 11:38:48 2026 +import mount_const as const +class fhstatus: + # XDR definition: + # union fhstatus switch(unsigned fhs_status) { + # case 0: + # fhandle2 fhs_fhandle; + # default: + # void; + # }; + def __init__(self, fhs_status=None, fhs_fhandle=None): + self.fhs_status = fhs_status + self.fhs_fhandle = fhs_fhandle + + switch = property(lambda s: {0:s.fhs_fhandle,}.get(s.fhs_status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.fhs_status is not None: + out += ['fhs_status=%s' % repr(self.fhs_status)] + if self.fhs_fhandle is not None: + out += ['fhs_fhandle=%s' % repr(self.fhs_fhandle)] + return 'fhstatus(%s)' % ', '.join(out) + __str__ = __repr__ + +class mountres3_ok: + # XDR definition: + # struct mountres3_ok { + # fhandle3 fhandle; + # int auth_flavors<>; + # }; + def __init__(self, fhandle=None, auth_flavors=None): + self.fhandle = fhandle + self.auth_flavors = auth_flavors + + def __repr__(self): + out = [] + if self.fhandle is not None: + out += ['fhandle=%s' % repr(self.fhandle)] + if self.auth_flavors is not None: + out += ['auth_flavors=%s' % repr(self.auth_flavors)] + return 'mountres3_ok(%s)' % ', '.join(out) + __str__ = __repr__ + +class mountres3: + # XDR definition: + # union mountres3 switch(mountstat3 fhs_status) { + # case MNT3_OK: + # mountres3_ok mountinfo; + # default: + # void; + # }; + def __init__(self, fhs_status=None, mountinfo=None): + self.fhs_status = fhs_status + self.mountinfo = mountinfo + + switch = property(lambda s: {const.MNT3_OK:s.mountinfo,}.get(s.fhs_status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.fhs_status is not None: + out += ['fhs_status=%s' % const.mountstat3.get(self.fhs_status, self.fhs_status)] + if self.mountinfo is not None: + out += ['mountinfo=%s' % repr(self.mountinfo)] + return 'mountres3(%s)' % ', '.join(out) + __str__ = __repr__ + +class mountlist: + # XDR definition: + # struct mountlist { + # name ml_hostname; + # dirpath ml_directory; + # mountlist ml_next; + # }; + def __init__(self, ml_hostname=None, ml_directory=None, ml_next=None): + self.ml_hostname = ml_hostname + self.ml_directory = ml_directory + self.ml_next = ml_next + + def __repr__(self): + out = [] + if self.ml_hostname is not None: + out += ['ml_hostname=%s' % repr(self.ml_hostname)] + if self.ml_directory is not None: + out += ['ml_directory=%s' % repr(self.ml_directory)] + if self.ml_next is not None: + out += ['ml_next=%s' % repr(self.ml_next)] + return 'mountlist(%s)' % ', '.join(out) + __str__ = __repr__ + +class groupnode: + # XDR definition: + # struct groupnode { + # name gr_name; + # groups gr_next<1>; + # }; + def __init__(self, gr_name=None, gr_next=None): + self.gr_name = gr_name + self.gr_next = gr_next + + def __repr__(self): + out = [] + if self.gr_name is not None: + out += ['gr_name=%s' % repr(self.gr_name)] + if self.gr_next is not None: + out += ['gr_next=%s' % repr(self.gr_next)] + return 'groupnode(%s)' % ', '.join(out) + __str__ = __repr__ + +class exportnode: + # XDR definition: + # struct exportnode { + # dirpath ex_dir; + # groups ex_groups; + # exportnode ex_next<1>; + # }; + def __init__(self, ex_dir=None, ex_groups=None, ex_next=None): + self.ex_dir = ex_dir + self.ex_groups = ex_groups + self.ex_next = ex_next + + def __repr__(self): + out = [] + if self.ex_dir is not None: + out += ['ex_dir=%s' % repr(self.ex_dir)] + if self.ex_groups is not None: + out += ['ex_groups=%s' % repr(self.ex_groups)] + if self.ex_next is not None: + out += ['ex_next=%s' % repr(self.ex_next)] + return 'exportnode(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/nfs3/mountlib.py b/nfs3/lib/nfs3/mountlib.py new file mode 100644 index 0000000..5d3ed60 --- /dev/null +++ b/nfs3/lib/nfs3/mountlib.py @@ -0,0 +1,156 @@ +#!/usr/bin/env python +# mountlib.py - MOUNT library for python + +import rpc +from xdrlib import Error as XDRError +import mount_const +from mount_const import * +import mount_type +from mount_type import * +from mount_pack import * +import time +import struct +import socket +import sys + +AuthSys = rpc.SecAuthSys(0, 'jupiter', 103558, 100, []) + + +class MountException(rpc.RPCError): + pass + + +# A MOUNT procedure returned an error +class BadMountRes(MountException): + def __init__(self, errcode, msg=None): + self.errcode = errcode + if msg: + self.msg = msg + ': ' + else: + self.msg = '' + + def __str__(self): + return self.msg + "should return MNT3_OK, instead got %s" % \ + (mountstat3[self.errcode]) + + +class MountClient(rpc.RPCClient): + def __init__(self, id, host='localhost', port=300, homedir=['pynfs'], + sec_list=[AuthSys], opts=None, mount_version=MOUNT_V3): + self.ipv6 = getattr(opts, 'ipv6', False) + self.packer = MOUNTPacker() + self.unpacker = MOUNTUnpacker('') + self.homedir = homedir + self.id = id + self.opts = opts + # Mounting generally requires a low port + # uselowport = getattr(opts, "secure", False) + uselowport = True + rpc.RPCClient.__init__(self, host, port, program=MOUNT_PROGRAM, + version=mount_version, sec_list=sec_list, + uselowport=uselowport, ipv6=self.ipv6) + self.server_address = (host, port) + print("seclist = ", sec_list) + + # XXX Mount version - assuming MOUNT V3 + def mount_pack(self, procedure, data): + p = self.packer + + if procedure == MOUNTPROC3_NULL: + pass + elif procedure == MOUNTPROC3_MNT: + p.pack_dirpath(data) + elif procedure == MOUNTPROC3_DUMP: + pass + elif procedure == MOUNTPROC3_UMNT: + p.pack_dirpath(data) + elif procedure == MOUNTPROC3_UMNTALL: + pass + elif procedure == MOUNTPROC3_EXPORT: + pass + else: + raise XDRError('bad switch=%s' % procedure) + + # XXX Fancy unpacking, into status, data, etc + def mount_unpack(self, procedure): + un_p = self.unpacker + + if procedure == MOUNTPROC3_NULL: + return + elif procedure == MOUNTPROC3_MNT: + return un_p.unpack_mountres3() + elif procedure == MOUNTPROC3_DUMP: + return un_p.unpack_mountlist() + elif procedure == MOUNTPROC3_UMNT: + return + elif procedure == MOUNTPROC3_UMNTALL: + return + elif procedure == MOUNTPROC3_EXPORT: + return un_p.unpack_exports() + else: + raise XDRError('bad switch=%s' % procedure) + + def mount_call(self, procedure, data=''): + # Pack Request + p = self.packer + un_p = self.unpacker + p.reset() + + self.mount_pack(procedure, data) + + # Make Call + res = self.call(procedure, p.get_buffer()) + + # Unpack Reply + un_p.reset(res) + res = self.mount_unpack(procedure) + un_p.done() + + # XXX Error checking? + return res + + """ + BASIC MOUNT OPERATIONS + """ + + def mount_null(self): + return self.mount_call(mount_const.MOUNTPROC3_NULL) + + def mount_mnt(self, path): + return self.mount_call(mount_const.MOUNTPROC3_MNT, path) + + def mount_dump(self): + return self.mount_call(mount_const.MOUNTPROC3_DUMP) + + # XXX Ops 3 and 4 + def mount_export(self): + return self.mount_call(mount_const.MOUNTPROC_EXPORT) + + def mount_null_v1(self): + return self.mount_call(mount_const.MOUNTPROC_NULL) + + def mount_mnt_v1(self, path): + return self.mount_call(mount_const.MOUNTPROC_MNT, path) + + def mount_dump_v1(self): + return self.mount_call(mount_const.MOUNTPROC_DUMP) + + # XXX Ops 3 and 4 + def mount_export_v1(self): + return self.mount_call(mount_const.MOUNTPROC_EXPORT) + """ + UTILITY FUNCTIONS + """ + + # Verify a MOUNT call was successful, + # raise BadMountRes otherwise + def mount_check_result(self, res, msg=None): + if not res.fhs_status: + return + raise BadMountRes(res.fhs_status, msg) + + def mount_getfh(self, path): + res = self.mount_mnt(path) + + self.mount_check_result(res, "MNT") + return res.mountinfo.fhandle diff --git a/nfs3/lib/nfs3/nfs3.x b/nfs3/lib/nfs3/nfs3.x new file mode 100755 index 0000000..0db938d --- /dev/null +++ b/nfs3/lib/nfs3/nfs3.x @@ -0,0 +1,618 @@ +/* $Id: nfs3_prot.x,v 1.1 2006/05/19 20:59:18 max Exp $ */ + +typedef unsigned hyper uint64; +typedef hyper int64; +typedef unsigned int uint32; +typedef int int32; + +const RPCSEC_GSS = 6; +const FALSE = 0; +const TRUE = 1; +const NFS3_FHSIZE = 64; +const NFS3_COOKIEVERFSIZE = 8; +const NFS3_CREATEVERFSIZE = 8; +const NFS3_WRITEVERFSIZE = 8; + +typedef string filename3<>; +typedef string nfspath3<>; +typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE]; +typedef opaque createverf3[NFS3_CREATEVERFSIZE]; +typedef opaque writeverf3[NFS3_WRITEVERFSIZE]; + +enum nfsstat3 { + NFS3_OK = 0, + NFS3ERR_PERM = 1, + NFS3ERR_NOENT = 2, + NFS3ERR_IO = 5, + NFS3ERR_NXIO = 6, + NFS3ERR_ACCES = 13, + NFS3ERR_EXIST = 17, + NFS3ERR_XDEV = 18, + NFS3ERR_NODEV = 19, + NFS3ERR_NOTDIR = 20, + NFS3ERR_ISDIR = 21, + NFS3ERR_INVAL = 22, + NFS3ERR_FBIG = 27, + NFS3ERR_NOSPC = 28, + NFS3ERR_ROFS = 30, + NFS3ERR_MLINK = 31, + NFS3ERR_NAMETOOLONG = 63, + NFS3ERR_NOTEMPTY = 66, + NFS3ERR_DQUOT = 69, + NFS3ERR_STALE = 70, + NFS3ERR_REMOTE = 71, + NFS3ERR_BADHANDLE = 10001, + NFS3ERR_NOT_SYNC = 10002, + NFS3ERR_BAD_COOKIE = 10003, + NFS3ERR_NOTSUPP = 10004, + NFS3ERR_TOOSMALL = 10005, + NFS3ERR_SERVERFAULT = 10006, + NFS3ERR_BADTYPE = 10007, + NFS3ERR_JUKEBOX = 10008, + NFS3ERR_FPRINTNOTFOUND = 10009, + NFS3ERR_ABORTED = 10010 +}; + +enum ftype3 { + NF3REG = 1, + NF3DIR = 2, + NF3BLK = 3, + NF3CHR = 4, + NF3LNK = 5, + NF3SOCK = 6, + NF3FIFO = 7 +}; + +struct specdata3 { + uint32 major; + uint32 minor; +}; + +struct nfs_fh3 { + opaque data; +}; + +struct nfstime3 { + uint32 seconds; + uint32 nseconds; +}; + +struct fattr3 { + ftype3 type; + uint32 mode; + uint32 nlink; + uint32 uid; + uint32 gid; + uint64 size; + uint64 used; + specdata3 rdev; + uint64 fsid; + uint64 fileid; + nfstime3 atime; + nfstime3 mtime; + nfstime3 ctime; +}; + +/*#ifdef SFSSVC +# include "nfs3_ext.x" +#endif *//* SFSSVC */ + +union post_op_attr switch (bool present) { +case TRUE: + fattr3 attributes; +case FALSE: + void; +}; + +struct wcc_attr { + uint64 size; + nfstime3 mtime; + nfstime3 ctime; +}; + +union pre_op_attr switch (bool present) { +case TRUE: + wcc_attr attributes; +case FALSE: + void; +}; + +struct wcc_data { + pre_op_attr before; + post_op_attr after; +}; + +union post_op_fh3 switch (bool present) { +case TRUE: + nfs_fh3 handle; +case FALSE: + void; +}; + +union set_uint32 switch (bool set) { +case TRUE: + uint32 val; +default: + void; +}; + +union set_uint64 switch (bool set) { +case TRUE: + uint64 val; +default: + void; +}; + +enum time_how { + DONT_CHANGE = 0, + SET_TO_SERVER_TIME = 1, + SET_TO_CLIENT_TIME = 2 +}; + +union set_time switch (time_how set) { +case SET_TO_CLIENT_TIME: + nfstime3 time; +default: + void; +}; + +struct sattr3 { + set_uint32 mode; + set_uint32 uid; + set_uint32 gid; + set_uint64 size; + set_time atime; + set_time mtime; +}; + +struct diropargs3 { + nfs_fh3 dir; + filename3 name; +}; + +struct diropres3ok { + post_op_fh3 obj; + post_op_attr obj_attributes; + wcc_data dir_wcc; +}; + +union diropres3 switch (nfsstat3 status) { +case NFS3_OK: + diropres3ok resok; +default: + wcc_data resfail; /* Directory attributes */ +}; + +union wccstat3 switch (nfsstat3 status) { +case -1: + void; +default: + wcc_data wcc; +}; + +union getattr3res switch (nfsstat3 status) { +case NFS3_OK: + fattr3 attributes; +default: + void; +}; + +union sattrguard3 switch (bool check) { +case TRUE: + nfstime3 ctime; +case FALSE: + void; +}; + +struct setattr3args { + nfs_fh3 object; + sattr3 new_attributes; + sattrguard3 guard; +}; + +struct lookup3resok { + nfs_fh3 object; + post_op_attr obj_attributes; + post_op_attr dir_attributes; +}; + +union lookup3res switch (nfsstat3 status) { +case NFS3_OK: + lookup3resok resok; +default: + post_op_attr resfail; /* Directory attributes */ +}; + +const ACCESS3_READ = 0x0001; +const ACCESS3_LOOKUP = 0x0002; +const ACCESS3_MODIFY = 0x0004; +const ACCESS3_EXTEND = 0x0008; +const ACCESS3_DELETE = 0x0010; +const ACCESS3_EXECUTE = 0x0020; + +struct access3args { + nfs_fh3 object; + uint32 access; +}; + +struct access3resok { + post_op_attr obj_attributes; + uint32 access; +}; + +union access3res switch (nfsstat3 status) { +case NFS3_OK: + access3resok resok; +default: + post_op_attr resfail; +}; + +struct readlink3resok { + post_op_attr symlink_attributes; + nfspath3 data; +}; + +union readlink3res switch (nfsstat3 status) { +case NFS3_OK: + readlink3resok resok; +default: + post_op_attr resfail; +}; + +struct read3args { + nfs_fh3 file; + uint64 offset; + uint32 count; +}; + +struct read3resok { + post_op_attr file_attributes; + uint32 count; + bool eof; + opaque data<>; +}; + +union read3res switch (nfsstat3 status) { +case NFS3_OK: + read3resok resok; +default: + post_op_attr resfail; +}; + +enum stable_how { + UNSTABLE = 0, + DATA_SYNC = 1, + FILE_SYNC = 2 +}; + +struct write3args { + nfs_fh3 file; + uint64 offset; + uint32 count; + stable_how stable; + opaque data<>; +}; + +struct write3resok { + wcc_data file_wcc; + uint32 count; + stable_how committed; + writeverf3 verf; +}; + +union write3res switch (nfsstat3 status) { +case NFS3_OK: + write3resok resok; +default: + wcc_data resfail; +}; + +enum createmode3 { + UNCHECKED = 0, + GUARDED = 1, + EXCLUSIVE = 2 +}; + +union createhow3 switch (createmode3 mode) { +case UNCHECKED: +case GUARDED: + sattr3 obj_attributes; +case EXCLUSIVE: + createverf3 verf; +}; + +struct create3args { + diropargs3 where; + createhow3 how; +}; + +struct mkdir3args { + diropargs3 where; + sattr3 attributes; +}; + +struct symlinkdata3 { + sattr3 symlink_attributes; + nfspath3 symlink_data; +}; + +struct symlink3args { + diropargs3 where; + symlinkdata3 symlink; +}; + +struct devicedata3 { + sattr3 dev_attributes; + specdata3 spec; +}; + +union mknoddata3 switch (ftype3 type) { +case NF3CHR: +case NF3BLK: + devicedata3 device; +case NF3SOCK: +case NF3FIFO: + sattr3 pipe_attributes; +default: + void; +}; + +struct mknod3args { + diropargs3 where; + mknoddata3 what; +}; + +struct rename3args { + diropargs3 from_dir; + diropargs3 to_dir; +}; + +struct rename3wcc { + wcc_data fromdir_wcc; + wcc_data todir_wcc; +}; + +union rename3res switch (nfsstat3 status) { +case -1: + void; +default: + rename3wcc res; +}; + +struct link3args { + nfs_fh3 file; + diropargs3 link; +}; + +struct link3wcc { + post_op_attr file_attributes; + wcc_data linkdir_wcc; +}; + +union link3res switch (nfsstat3 status) { +case -1: + void; +default: + link3wcc res; +}; + +struct readdir3args { + nfs_fh3 dir; + uint64 cookie; + cookieverf3 cookieverf; + uint32 count; +}; + +struct entry3 { + uint64 fileid; + filename3 name; + uint64 cookie; + entry3 *nextentry; +}; + +struct dirlist3 { + entry3 *entries; + bool eof; +}; + +struct readdir3resok { + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlist3 reply; +}; + +union readdir3res switch (nfsstat3 status) { +case NFS3_OK: + readdir3resok resok; +default: + post_op_attr resfail; +}; + +struct readdirplus3args { + nfs_fh3 dir; + uint64 cookie; + cookieverf3 cookieverf; + uint32 dircount; + uint32 maxcount; +}; + +struct entryplus3 { + uint64 fileid; + filename3 name; + uint64 cookie; + post_op_attr name_attributes; + post_op_fh3 name_handle; + entryplus3 *nextentry; +}; + +struct dirlistplus3 { + entryplus3 *entries; + bool eof; +}; + +struct readdirplus3resok { + post_op_attr dir_attributes; + cookieverf3 cookieverf; + dirlistplus3 reply; +}; + +union readdirplus3res switch (nfsstat3 status) { +case NFS3_OK: + readdirplus3resok resok; +default: + post_op_attr resfail; +}; + +struct fsstat3resok { + post_op_attr obj_attributes; + uint64 tbytes; + uint64 fbytes; + uint64 abytes; + uint64 tfiles; + uint64 ffiles; + uint64 afiles; + uint32 invarsec; +}; + +union fsstat3res switch (nfsstat3 status) { +case NFS3_OK: + fsstat3resok resok; +default: + post_op_attr resfail; +}; + +const FSF3_LINK = 0x0001; +const FSF3_SYMLINK = 0x0002; +const FSF3_HOMOGENEOUS = 0x0008; +const FSF3_CANSETTIME = 0x0010; + +struct fsinfo3resok { + post_op_attr obj_attributes; + uint32 rtmax; + uint32 rtpref; + uint32 rtmult; + uint32 wtmax; + uint32 wtpref; + uint32 wtmult; + uint32 dtpref; + uint64 maxfilesize; + nfstime3 time_delta; + uint32 properties; +}; + +union fsinfo3res switch (nfsstat3 status) { +case NFS3_OK: + fsinfo3resok resok; +default: + post_op_attr resfail; +}; + +struct pathconf3resok { + post_op_attr obj_attributes; + uint32 linkmax; + uint32 name_max; + bool no_trunc; + bool chown_restricted; + bool case_insensitive; + bool case_preserving; +}; + +union pathconf3res switch (nfsstat3 status) { +case NFS3_OK: + pathconf3resok resok; +default: + post_op_attr resfail; +}; + +struct commit3args { + nfs_fh3 file; + uint64 offset; + uint32 count; +}; + +struct commit3resok { + wcc_data file_wcc; + writeverf3 verf; +}; + +union commit3res switch (nfsstat3 status) { +case NFS3_OK: + commit3resok resok; +default: + wcc_data resfail; +}; + +struct setaclargs { + diropargs3 dargs; + write3args wargs; +}; + +program NFS_PROGRAM { + version NFS_V3 { + void + NFSPROC3_NULL (void) = 0; + + getattr3res + NFSPROC3_GETATTR (nfs_fh3) = 1; + + wccstat3 + NFSPROC3_SETATTR (setattr3args) = 2; + + lookup3res + NFSPROC3_LOOKUP (diropargs3) = 3; + + access3res + NFSPROC3_ACCESS (access3args) = 4; + + readlink3res + NFSPROC3_READLINK (nfs_fh3) = 5; + + read3res + NFSPROC3_READ (read3args) = 6; + + write3res + NFSPROC3_WRITE (write3args) = 7; + + diropres3 + NFSPROC3_CREATE (create3args) = 8; + + diropres3 + NFSPROC3_MKDIR (mkdir3args) = 9; + + diropres3 + NFSPROC3_SYMLINK (symlink3args) = 10; + + diropres3 + NFSPROC3_MKNOD (mknod3args) = 11; + + wccstat3 + NFSPROC3_REMOVE (diropargs3) = 12; + + wccstat3 + NFSPROC3_RMDIR (diropargs3) = 13; + + rename3res + NFSPROC3_RENAME (rename3args) = 14; + + link3res + NFSPROC3_LINK (link3args) = 15; + + readdir3res + NFSPROC3_READDIR (readdir3args) = 16; + + readdirplus3res + NFSPROC3_READDIRPLUS (readdirplus3args) = 17; + + fsstat3res + NFSPROC3_FSSTAT (nfs_fh3) = 18; + + fsinfo3res + NFSPROC3_FSINFO (nfs_fh3) = 19; + + pathconf3res + NFSPROC3_PATHCONF (nfs_fh3) = 20; + + commit3res + NFSPROC3_COMMIT (commit3args) = 21; + } = 3; +} = 100003; diff --git a/nfs3/lib/nfs3/nfs3_const.py b/nfs3/lib/nfs3/nfs3_const.py new file mode 100644 index 0000000..069629c --- /dev/null +++ b/nfs3/lib/nfs3/nfs3_const.py @@ -0,0 +1,146 @@ +# Generated by rpcgen.py from nfs3.x on Wed Jun 24 11:38:48 2026 +NFSPROC3_NULL = 0 +NFSPROC3_GETATTR = 1 +NFSPROC3_SETATTR = 2 +NFSPROC3_LOOKUP = 3 +NFSPROC3_ACCESS = 4 +NFSPROC3_READLINK = 5 +NFSPROC3_READ = 6 +NFSPROC3_WRITE = 7 +NFSPROC3_CREATE = 8 +NFSPROC3_MKDIR = 9 +NFSPROC3_SYMLINK = 10 +NFSPROC3_MKNOD = 11 +NFSPROC3_REMOVE = 12 +NFSPROC3_RMDIR = 13 +NFSPROC3_RENAME = 14 +NFSPROC3_LINK = 15 +NFSPROC3_READDIR = 16 +NFSPROC3_READDIRPLUS = 17 +NFSPROC3_FSSTAT = 18 +NFSPROC3_FSINFO = 19 +NFSPROC3_PATHCONF = 20 +NFSPROC3_COMMIT = 21 +RPCSEC_GSS = 6 +FALSE = 0 +TRUE = 1 +NFS3_FHSIZE = 64 +NFS3_COOKIEVERFSIZE = 8 +NFS3_CREATEVERFSIZE = 8 +NFS3_WRITEVERFSIZE = 8 +NFS3_OK = 0 +NFS3ERR_PERM = 1 +NFS3ERR_NOENT = 2 +NFS3ERR_IO = 5 +NFS3ERR_NXIO = 6 +NFS3ERR_ACCES = 13 +NFS3ERR_EXIST = 17 +NFS3ERR_XDEV = 18 +NFS3ERR_NODEV = 19 +NFS3ERR_NOTDIR = 20 +NFS3ERR_ISDIR = 21 +NFS3ERR_INVAL = 22 +NFS3ERR_FBIG = 27 +NFS3ERR_NOSPC = 28 +NFS3ERR_ROFS = 30 +NFS3ERR_MLINK = 31 +NFS3ERR_NAMETOOLONG = 63 +NFS3ERR_NOTEMPTY = 66 +NFS3ERR_DQUOT = 69 +NFS3ERR_STALE = 70 +NFS3ERR_REMOTE = 71 +NFS3ERR_BADHANDLE = 10001 +NFS3ERR_NOT_SYNC = 10002 +NFS3ERR_BAD_COOKIE = 10003 +NFS3ERR_NOTSUPP = 10004 +NFS3ERR_TOOSMALL = 10005 +NFS3ERR_SERVERFAULT = 10006 +NFS3ERR_BADTYPE = 10007 +NFS3ERR_JUKEBOX = 10008 +NFS3ERR_FPRINTNOTFOUND = 10009 +NFS3ERR_ABORTED = 10010 +nfsstat3 = { + 0 : 'NFS3_OK', + 1 : 'NFS3ERR_PERM', + 2 : 'NFS3ERR_NOENT', + 5 : 'NFS3ERR_IO', + 6 : 'NFS3ERR_NXIO', + 13 : 'NFS3ERR_ACCES', + 17 : 'NFS3ERR_EXIST', + 18 : 'NFS3ERR_XDEV', + 19 : 'NFS3ERR_NODEV', + 20 : 'NFS3ERR_NOTDIR', + 21 : 'NFS3ERR_ISDIR', + 22 : 'NFS3ERR_INVAL', + 27 : 'NFS3ERR_FBIG', + 28 : 'NFS3ERR_NOSPC', + 30 : 'NFS3ERR_ROFS', + 31 : 'NFS3ERR_MLINK', + 63 : 'NFS3ERR_NAMETOOLONG', + 66 : 'NFS3ERR_NOTEMPTY', + 69 : 'NFS3ERR_DQUOT', + 70 : 'NFS3ERR_STALE', + 71 : 'NFS3ERR_REMOTE', + 10001 : 'NFS3ERR_BADHANDLE', + 10002 : 'NFS3ERR_NOT_SYNC', + 10003 : 'NFS3ERR_BAD_COOKIE', + 10004 : 'NFS3ERR_NOTSUPP', + 10005 : 'NFS3ERR_TOOSMALL', + 10006 : 'NFS3ERR_SERVERFAULT', + 10007 : 'NFS3ERR_BADTYPE', + 10008 : 'NFS3ERR_JUKEBOX', + 10009 : 'NFS3ERR_FPRINTNOTFOUND', + 10010 : 'NFS3ERR_ABORTED', +} +NF3REG = 1 +NF3DIR = 2 +NF3BLK = 3 +NF3CHR = 4 +NF3LNK = 5 +NF3SOCK = 6 +NF3FIFO = 7 +ftype3 = { + 1 : 'NF3REG', + 2 : 'NF3DIR', + 3 : 'NF3BLK', + 4 : 'NF3CHR', + 5 : 'NF3LNK', + 6 : 'NF3SOCK', + 7 : 'NF3FIFO', +} +DONT_CHANGE = 0 +SET_TO_SERVER_TIME = 1 +SET_TO_CLIENT_TIME = 2 +time_how = { + 0 : 'DONT_CHANGE', + 1 : 'SET_TO_SERVER_TIME', + 2 : 'SET_TO_CLIENT_TIME', +} +ACCESS3_READ = 0x0001 +ACCESS3_LOOKUP = 0x0002 +ACCESS3_MODIFY = 0x0004 +ACCESS3_EXTEND = 0x0008 +ACCESS3_DELETE = 0x0010 +ACCESS3_EXECUTE = 0x0020 +UNSTABLE = 0 +DATA_SYNC = 1 +FILE_SYNC = 2 +stable_how = { + 0 : 'UNSTABLE', + 1 : 'DATA_SYNC', + 2 : 'FILE_SYNC', +} +UNCHECKED = 0 +GUARDED = 1 +EXCLUSIVE = 2 +createmode3 = { + 0 : 'UNCHECKED', + 1 : 'GUARDED', + 2 : 'EXCLUSIVE', +} +FSF3_LINK = 0x0001 +FSF3_SYMLINK = 0x0002 +FSF3_HOMOGENEOUS = 0x0008 +FSF3_CANSETTIME = 0x0010 +NFS_PROGRAM = 100003 +NFS_V3 = 3 diff --git a/nfs3/lib/nfs3/nfs3_pack.py b/nfs3/lib/nfs3/nfs3_pack.py new file mode 100644 index 0000000..c73aede --- /dev/null +++ b/nfs3/lib/nfs3/nfs3_pack.py @@ -0,0 +1,1873 @@ +# Generated by rpcgen.py from nfs3.x on Wed Jun 24 11:38:48 2026 +import nfs3_const as const +import nfs3_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class NFS3Packer(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + pack_uint64 = pack_uhyper + + pack_int64 = pack_hyper + + pack_uint32 = pack_uint + + pack_int32 = pack_int + + def pack_filename3(self, data): + if hasattr(self, 'filter_filename3'): + data = getattr(self, 'filter_filename3')(data) + self.pack_string(data) + + def pack_nfspath3(self, data): + if hasattr(self, 'filter_nfspath3'): + data = getattr(self, 'filter_nfspath3')(data) + self.pack_string(data) + + def pack_cookieverf3(self, data): + if hasattr(self, 'filter_cookieverf3'): + data = getattr(self, 'filter_cookieverf3')(data) + self.pack_fopaque(const.NFS3_COOKIEVERFSIZE, data) + + def pack_createverf3(self, data): + if hasattr(self, 'filter_createverf3'): + data = getattr(self, 'filter_createverf3')(data) + self.pack_fopaque(const.NFS3_CREATEVERFSIZE, data) + + def pack_writeverf3(self, data): + if hasattr(self, 'filter_writeverf3'): + data = getattr(self, 'filter_writeverf3')(data) + self.pack_fopaque(const.NFS3_WRITEVERFSIZE, data) + + def pack_nfsstat3(self, data): + if hasattr(self, 'filter_nfsstat3'): + data = getattr(self, 'filter_nfsstat3')(data) + if self.check_enum and data not in [const.NFS3_OK, const.NFS3ERR_PERM, const.NFS3ERR_NOENT, const.NFS3ERR_IO, const.NFS3ERR_NXIO, const.NFS3ERR_ACCES, const.NFS3ERR_EXIST, const.NFS3ERR_XDEV, const.NFS3ERR_NODEV, const.NFS3ERR_NOTDIR, const.NFS3ERR_ISDIR, const.NFS3ERR_INVAL, const.NFS3ERR_FBIG, const.NFS3ERR_NOSPC, const.NFS3ERR_ROFS, const.NFS3ERR_MLINK, const.NFS3ERR_NAMETOOLONG, const.NFS3ERR_NOTEMPTY, const.NFS3ERR_DQUOT, const.NFS3ERR_STALE, const.NFS3ERR_REMOTE, const.NFS3ERR_BADHANDLE, const.NFS3ERR_NOT_SYNC, const.NFS3ERR_BAD_COOKIE, const.NFS3ERR_NOTSUPP, const.NFS3ERR_TOOSMALL, const.NFS3ERR_SERVERFAULT, const.NFS3ERR_BADTYPE, const.NFS3ERR_JUKEBOX, const.NFS3ERR_FPRINTNOTFOUND, const.NFS3ERR_ABORTED]: + raise XDRError('value=%s not in enum nfsstat3' % data) + self.pack_int(data) + + def pack_ftype3(self, data): + if hasattr(self, 'filter_ftype3'): + data = getattr(self, 'filter_ftype3')(data) + if self.check_enum and data not in [const.NF3REG, const.NF3DIR, const.NF3BLK, const.NF3CHR, const.NF3LNK, const.NF3SOCK, const.NF3FIFO]: + raise XDRError('value=%s not in enum ftype3' % data) + self.pack_int(data) + + def pack_specdata3(self, data): + if hasattr(self, 'filter_specdata3'): + data = getattr(self, 'filter_specdata3')(data) + if data.major is None: + raise TypeError('data.major == None') + self.pack_uint32(data.major) + if data.minor is None: + raise TypeError('data.minor == None') + self.pack_uint32(data.minor) + + def pack_nfs_fh3(self, data): + if hasattr(self, 'filter_nfs_fh3'): + data = getattr(self, 'filter_nfs_fh3')(data) + if data.data is None: + raise TypeError('data.data == None') + if len(data.data) > const.NFS3_FHSIZE and self.check_array: + raise XDRError('array length too long for data.data') + self.pack_opaque(data.data) + + def pack_nfstime3(self, data): + if hasattr(self, 'filter_nfstime3'): + data = getattr(self, 'filter_nfstime3')(data) + if data.seconds is None: + raise TypeError('data.seconds == None') + self.pack_uint32(data.seconds) + if data.nseconds is None: + raise TypeError('data.nseconds == None') + self.pack_uint32(data.nseconds) + + def pack_fattr3(self, data): + if hasattr(self, 'filter_fattr3'): + data = getattr(self, 'filter_fattr3')(data) + if data.type is None: + raise TypeError('data.type == None') + self.pack_ftype3(data.type) + if data.mode is None: + raise TypeError('data.mode == None') + self.pack_uint32(data.mode) + if data.nlink is None: + raise TypeError('data.nlink == None') + self.pack_uint32(data.nlink) + if data.uid is None: + raise TypeError('data.uid == None') + self.pack_uint32(data.uid) + if data.gid is None: + raise TypeError('data.gid == None') + self.pack_uint32(data.gid) + if data.size is None: + raise TypeError('data.size == None') + self.pack_uint64(data.size) + if data.used is None: + raise TypeError('data.used == None') + self.pack_uint64(data.used) + if data.rdev is None: + raise TypeError('data.rdev == None') + self.pack_specdata3(data.rdev) + if data.fsid is None: + raise TypeError('data.fsid == None') + self.pack_uint64(data.fsid) + if data.fileid is None: + raise TypeError('data.fileid == None') + self.pack_uint64(data.fileid) + if data.atime is None: + raise TypeError('data.atime == None') + self.pack_nfstime3(data.atime) + if data.mtime is None: + raise TypeError('data.mtime == None') + self.pack_nfstime3(data.mtime) + if data.ctime is None: + raise TypeError('data.ctime == None') + self.pack_nfstime3(data.ctime) + + def pack_post_op_attr(self, data): + if hasattr(self, 'filter_post_op_attr'): + data = getattr(self, 'filter_post_op_attr')(data) + if data.present is None: + raise TypeError('data.present == None') + self.pack_bool(data.present) + if data.present == const.TRUE: + if data.attributes is None: + raise TypeError('data.attributes == None') + self.pack_fattr3(data.attributes) + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + + def pack_wcc_attr(self, data): + if hasattr(self, 'filter_wcc_attr'): + data = getattr(self, 'filter_wcc_attr')(data) + if data.size is None: + raise TypeError('data.size == None') + self.pack_uint64(data.size) + if data.mtime is None: + raise TypeError('data.mtime == None') + self.pack_nfstime3(data.mtime) + if data.ctime is None: + raise TypeError('data.ctime == None') + self.pack_nfstime3(data.ctime) + + def pack_pre_op_attr(self, data): + if hasattr(self, 'filter_pre_op_attr'): + data = getattr(self, 'filter_pre_op_attr')(data) + if data.present is None: + raise TypeError('data.present == None') + self.pack_bool(data.present) + if data.present == const.TRUE: + if data.attributes is None: + raise TypeError('data.attributes == None') + self.pack_wcc_attr(data.attributes) + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + + def pack_wcc_data(self, data): + if hasattr(self, 'filter_wcc_data'): + data = getattr(self, 'filter_wcc_data')(data) + if data.before is None: + raise TypeError('data.before == None') + self.pack_pre_op_attr(data.before) + if data.after is None: + raise TypeError('data.after == None') + self.pack_post_op_attr(data.after) + + def pack_post_op_fh3(self, data): + if hasattr(self, 'filter_post_op_fh3'): + data = getattr(self, 'filter_post_op_fh3')(data) + if data.present is None: + raise TypeError('data.present == None') + self.pack_bool(data.present) + if data.present == const.TRUE: + if data.handle is None: + raise TypeError('data.handle == None') + self.pack_nfs_fh3(data.handle) + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + + def pack_set_uint32(self, data): + if hasattr(self, 'filter_set_uint32'): + data = getattr(self, 'filter_set_uint32')(data) + if data.set is None: + raise TypeError('data.set == None') + self.pack_bool(data.set) + if data.set == const.TRUE: + if data.val is None: + raise TypeError('data.val == None') + self.pack_uint32(data.val) + else: + pass + + def pack_set_uint64(self, data): + if hasattr(self, 'filter_set_uint64'): + data = getattr(self, 'filter_set_uint64')(data) + if data.set is None: + raise TypeError('data.set == None') + self.pack_bool(data.set) + if data.set == const.TRUE: + if data.val is None: + raise TypeError('data.val == None') + self.pack_uint64(data.val) + else: + pass + + def pack_time_how(self, data): + if hasattr(self, 'filter_time_how'): + data = getattr(self, 'filter_time_how')(data) + if self.check_enum and data not in [const.DONT_CHANGE, const.SET_TO_SERVER_TIME, const.SET_TO_CLIENT_TIME]: + raise XDRError('value=%s not in enum time_how' % data) + self.pack_int(data) + + def pack_set_time(self, data): + if hasattr(self, 'filter_set_time'): + data = getattr(self, 'filter_set_time')(data) + if data.set is None: + raise TypeError('data.set == None') + self.pack_time_how(data.set) + if data.set == const.SET_TO_CLIENT_TIME: + if data.time is None: + raise TypeError('data.time == None') + self.pack_nfstime3(data.time) + else: + pass + + def pack_sattr3(self, data): + if hasattr(self, 'filter_sattr3'): + data = getattr(self, 'filter_sattr3')(data) + if data.mode is None: + raise TypeError('data.mode == None') + self.pack_set_uint32(data.mode) + if data.uid is None: + raise TypeError('data.uid == None') + self.pack_set_uint32(data.uid) + if data.gid is None: + raise TypeError('data.gid == None') + self.pack_set_uint32(data.gid) + if data.size is None: + raise TypeError('data.size == None') + self.pack_set_uint64(data.size) + if data.atime is None: + raise TypeError('data.atime == None') + self.pack_set_time(data.atime) + if data.mtime is None: + raise TypeError('data.mtime == None') + self.pack_set_time(data.mtime) + + def pack_diropargs3(self, data): + if hasattr(self, 'filter_diropargs3'): + data = getattr(self, 'filter_diropargs3')(data) + if data.dir is None: + raise TypeError('data.dir == None') + self.pack_nfs_fh3(data.dir) + if data.name is None: + raise TypeError('data.name == None') + self.pack_filename3(data.name) + + def pack_diropres3ok(self, data): + if hasattr(self, 'filter_diropres3ok'): + data = getattr(self, 'filter_diropres3ok')(data) + if data.obj is None: + raise TypeError('data.obj == None') + self.pack_post_op_fh3(data.obj) + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_post_op_attr(data.obj_attributes) + if data.dir_wcc is None: + raise TypeError('data.dir_wcc == None') + self.pack_wcc_data(data.dir_wcc) + + def pack_diropres3(self, data): + if hasattr(self, 'filter_diropres3'): + data = getattr(self, 'filter_diropres3')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_diropres3ok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_wcc_data(data.resfail) + + def pack_wccstat3(self, data): + if hasattr(self, 'filter_wccstat3'): + data = getattr(self, 'filter_wccstat3')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == -1: + pass + else: + if data.wcc is None: + raise TypeError('data.wcc == None') + self.pack_wcc_data(data.wcc) + + def pack_getattr3res(self, data): + if hasattr(self, 'filter_getattr3res'): + data = getattr(self, 'filter_getattr3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.attributes is None: + raise TypeError('data.attributes == None') + self.pack_fattr3(data.attributes) + else: + pass + + def pack_sattrguard3(self, data): + if hasattr(self, 'filter_sattrguard3'): + data = getattr(self, 'filter_sattrguard3')(data) + if data.check is None: + raise TypeError('data.check == None') + self.pack_bool(data.check) + if data.check == const.TRUE: + if data.ctime is None: + raise TypeError('data.ctime == None') + self.pack_nfstime3(data.ctime) + elif data.check == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.check) + + def pack_setattr3args(self, data): + if hasattr(self, 'filter_setattr3args'): + data = getattr(self, 'filter_setattr3args')(data) + if data.object is None: + raise TypeError('data.object == None') + self.pack_nfs_fh3(data.object) + if data.new_attributes is None: + raise TypeError('data.new_attributes == None') + self.pack_sattr3(data.new_attributes) + if data.guard is None: + raise TypeError('data.guard == None') + self.pack_sattrguard3(data.guard) + + def pack_lookup3resok(self, data): + if hasattr(self, 'filter_lookup3resok'): + data = getattr(self, 'filter_lookup3resok')(data) + if data.object is None: + raise TypeError('data.object == None') + self.pack_nfs_fh3(data.object) + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_post_op_attr(data.obj_attributes) + if data.dir_attributes is None: + raise TypeError('data.dir_attributes == None') + self.pack_post_op_attr(data.dir_attributes) + + def pack_lookup3res(self, data): + if hasattr(self, 'filter_lookup3res'): + data = getattr(self, 'filter_lookup3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_lookup3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_access3args(self, data): + if hasattr(self, 'filter_access3args'): + data = getattr(self, 'filter_access3args')(data) + if data.object is None: + raise TypeError('data.object == None') + self.pack_nfs_fh3(data.object) + if data.access is None: + raise TypeError('data.access == None') + self.pack_uint32(data.access) + + def pack_access3resok(self, data): + if hasattr(self, 'filter_access3resok'): + data = getattr(self, 'filter_access3resok')(data) + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_post_op_attr(data.obj_attributes) + if data.access is None: + raise TypeError('data.access == None') + self.pack_uint32(data.access) + + def pack_access3res(self, data): + if hasattr(self, 'filter_access3res'): + data = getattr(self, 'filter_access3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_access3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_readlink3resok(self, data): + if hasattr(self, 'filter_readlink3resok'): + data = getattr(self, 'filter_readlink3resok')(data) + if data.symlink_attributes is None: + raise TypeError('data.symlink_attributes == None') + self.pack_post_op_attr(data.symlink_attributes) + if data.data is None: + raise TypeError('data.data == None') + self.pack_nfspath3(data.data) + + def pack_readlink3res(self, data): + if hasattr(self, 'filter_readlink3res'): + data = getattr(self, 'filter_readlink3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_readlink3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_read3args(self, data): + if hasattr(self, 'filter_read3args'): + data = getattr(self, 'filter_read3args')(data) + if data.file is None: + raise TypeError('data.file == None') + self.pack_nfs_fh3(data.file) + if data.offset is None: + raise TypeError('data.offset == None') + self.pack_uint64(data.offset) + if data.count is None: + raise TypeError('data.count == None') + self.pack_uint32(data.count) + + def pack_read3resok(self, data): + if hasattr(self, 'filter_read3resok'): + data = getattr(self, 'filter_read3resok')(data) + if data.file_attributes is None: + raise TypeError('data.file_attributes == None') + self.pack_post_op_attr(data.file_attributes) + if data.count is None: + raise TypeError('data.count == None') + self.pack_uint32(data.count) + if data.eof is None: + raise TypeError('data.eof == None') + self.pack_bool(data.eof) + if data.data is None: + raise TypeError('data.data == None') + self.pack_opaque(data.data) + + def pack_read3res(self, data): + if hasattr(self, 'filter_read3res'): + data = getattr(self, 'filter_read3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_read3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_stable_how(self, data): + if hasattr(self, 'filter_stable_how'): + data = getattr(self, 'filter_stable_how')(data) + if self.check_enum and data not in [const.UNSTABLE, const.DATA_SYNC, const.FILE_SYNC]: + raise XDRError('value=%s not in enum stable_how' % data) + self.pack_int(data) + + def pack_write3args(self, data): + if hasattr(self, 'filter_write3args'): + data = getattr(self, 'filter_write3args')(data) + if data.file is None: + raise TypeError('data.file == None') + self.pack_nfs_fh3(data.file) + if data.offset is None: + raise TypeError('data.offset == None') + self.pack_uint64(data.offset) + if data.count is None: + raise TypeError('data.count == None') + self.pack_uint32(data.count) + if data.stable is None: + raise TypeError('data.stable == None') + self.pack_stable_how(data.stable) + if data.data is None: + raise TypeError('data.data == None') + self.pack_opaque(data.data) + + def pack_write3resok(self, data): + if hasattr(self, 'filter_write3resok'): + data = getattr(self, 'filter_write3resok')(data) + if data.file_wcc is None: + raise TypeError('data.file_wcc == None') + self.pack_wcc_data(data.file_wcc) + if data.count is None: + raise TypeError('data.count == None') + self.pack_uint32(data.count) + if data.committed is None: + raise TypeError('data.committed == None') + self.pack_stable_how(data.committed) + if data.verf is None: + raise TypeError('data.verf == None') + self.pack_writeverf3(data.verf) + + def pack_write3res(self, data): + if hasattr(self, 'filter_write3res'): + data = getattr(self, 'filter_write3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_write3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_wcc_data(data.resfail) + + def pack_createmode3(self, data): + if hasattr(self, 'filter_createmode3'): + data = getattr(self, 'filter_createmode3')(data) + if self.check_enum and data not in [const.UNCHECKED, const.GUARDED, const.EXCLUSIVE]: + raise XDRError('value=%s not in enum createmode3' % data) + self.pack_int(data) + + def pack_createhow3(self, data): + if hasattr(self, 'filter_createhow3'): + data = getattr(self, 'filter_createhow3')(data) + if data.mode is None: + raise TypeError('data.mode == None') + self.pack_createmode3(data.mode) + if data.mode == const.UNCHECKED or data.mode == const.GUARDED: + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_sattr3(data.obj_attributes) + elif data.mode == const.EXCLUSIVE: + if data.verf is None: + raise TypeError('data.verf == None') + self.pack_createverf3(data.verf) + else: + raise XDRError('bad switch=%s' % data.mode) + + def pack_create3args(self, data): + if hasattr(self, 'filter_create3args'): + data = getattr(self, 'filter_create3args')(data) + if data.where is None: + raise TypeError('data.where == None') + self.pack_diropargs3(data.where) + if data.how is None: + raise TypeError('data.how == None') + self.pack_createhow3(data.how) + + def pack_mkdir3args(self, data): + if hasattr(self, 'filter_mkdir3args'): + data = getattr(self, 'filter_mkdir3args')(data) + if data.where is None: + raise TypeError('data.where == None') + self.pack_diropargs3(data.where) + if data.attributes is None: + raise TypeError('data.attributes == None') + self.pack_sattr3(data.attributes) + + def pack_symlinkdata3(self, data): + if hasattr(self, 'filter_symlinkdata3'): + data = getattr(self, 'filter_symlinkdata3')(data) + if data.symlink_attributes is None: + raise TypeError('data.symlink_attributes == None') + self.pack_sattr3(data.symlink_attributes) + if data.symlink_data is None: + raise TypeError('data.symlink_data == None') + self.pack_nfspath3(data.symlink_data) + + def pack_symlink3args(self, data): + if hasattr(self, 'filter_symlink3args'): + data = getattr(self, 'filter_symlink3args')(data) + if data.where is None: + raise TypeError('data.where == None') + self.pack_diropargs3(data.where) + if data.symlink is None: + raise TypeError('data.symlink == None') + self.pack_symlinkdata3(data.symlink) + + def pack_devicedata3(self, data): + if hasattr(self, 'filter_devicedata3'): + data = getattr(self, 'filter_devicedata3')(data) + if data.dev_attributes is None: + raise TypeError('data.dev_attributes == None') + self.pack_sattr3(data.dev_attributes) + if data.spec is None: + raise TypeError('data.spec == None') + self.pack_specdata3(data.spec) + + def pack_mknoddata3(self, data): + if hasattr(self, 'filter_mknoddata3'): + data = getattr(self, 'filter_mknoddata3')(data) + if data.type is None: + raise TypeError('data.type == None') + self.pack_ftype3(data.type) + if data.type == const.NF3CHR or data.type == const.NF3BLK: + if data.device is None: + raise TypeError('data.device == None') + self.pack_devicedata3(data.device) + elif data.type == const.NF3SOCK or data.type == const.NF3FIFO: + if data.pipe_attributes is None: + raise TypeError('data.pipe_attributes == None') + self.pack_sattr3(data.pipe_attributes) + else: + pass + + def pack_mknod3args(self, data): + if hasattr(self, 'filter_mknod3args'): + data = getattr(self, 'filter_mknod3args')(data) + if data.where is None: + raise TypeError('data.where == None') + self.pack_diropargs3(data.where) + if data.what is None: + raise TypeError('data.what == None') + self.pack_mknoddata3(data.what) + + def pack_rename3args(self, data): + if hasattr(self, 'filter_rename3args'): + data = getattr(self, 'filter_rename3args')(data) + if data.from_dir is None: + raise TypeError('data.from_dir == None') + self.pack_diropargs3(data.from_dir) + if data.to_dir is None: + raise TypeError('data.to_dir == None') + self.pack_diropargs3(data.to_dir) + + def pack_rename3wcc(self, data): + if hasattr(self, 'filter_rename3wcc'): + data = getattr(self, 'filter_rename3wcc')(data) + if data.fromdir_wcc is None: + raise TypeError('data.fromdir_wcc == None') + self.pack_wcc_data(data.fromdir_wcc) + if data.todir_wcc is None: + raise TypeError('data.todir_wcc == None') + self.pack_wcc_data(data.todir_wcc) + + def pack_rename3res(self, data): + if hasattr(self, 'filter_rename3res'): + data = getattr(self, 'filter_rename3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == -1: + pass + else: + if data.res is None: + raise TypeError('data.res == None') + self.pack_rename3wcc(data.res) + + def pack_link3args(self, data): + if hasattr(self, 'filter_link3args'): + data = getattr(self, 'filter_link3args')(data) + if data.file is None: + raise TypeError('data.file == None') + self.pack_nfs_fh3(data.file) + if data.link is None: + raise TypeError('data.link == None') + self.pack_diropargs3(data.link) + + def pack_link3wcc(self, data): + if hasattr(self, 'filter_link3wcc'): + data = getattr(self, 'filter_link3wcc')(data) + if data.file_attributes is None: + raise TypeError('data.file_attributes == None') + self.pack_post_op_attr(data.file_attributes) + if data.linkdir_wcc is None: + raise TypeError('data.linkdir_wcc == None') + self.pack_wcc_data(data.linkdir_wcc) + + def pack_link3res(self, data): + if hasattr(self, 'filter_link3res'): + data = getattr(self, 'filter_link3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == -1: + pass + else: + if data.res is None: + raise TypeError('data.res == None') + self.pack_link3wcc(data.res) + + def pack_readdir3args(self, data): + if hasattr(self, 'filter_readdir3args'): + data = getattr(self, 'filter_readdir3args')(data) + if data.dir is None: + raise TypeError('data.dir == None') + self.pack_nfs_fh3(data.dir) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_uint64(data.cookie) + if data.cookieverf is None: + raise TypeError('data.cookieverf == None') + self.pack_cookieverf3(data.cookieverf) + if data.count is None: + raise TypeError('data.count == None') + self.pack_uint32(data.count) + + def pack_entry3(self, data): + if hasattr(self, 'filter_entry3'): + data = getattr(self, 'filter_entry3')(data) + if data.fileid is None: + raise TypeError('data.fileid == None') + self.pack_uint64(data.fileid) + if data.name is None: + raise TypeError('data.name == None') + self.pack_filename3(data.name) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_uint64(data.cookie) + if data.nextentry is None: + raise TypeError('data.nextentry == None') + if len(data.nextentry) > 1 and self.check_array: + raise XDRError('array length too long for data.nextentry') + self.pack_array(data.nextentry, self.pack_entry3) + + def pack_dirlist3(self, data): + if hasattr(self, 'filter_dirlist3'): + data = getattr(self, 'filter_dirlist3')(data) + if data.entries is None: + raise TypeError('data.entries == None') + if len(data.entries) > 1 and self.check_array: + raise XDRError('array length too long for data.entries') + self.pack_array(data.entries, self.pack_entry3) + if data.eof is None: + raise TypeError('data.eof == None') + self.pack_bool(data.eof) + + def pack_readdir3resok(self, data): + if hasattr(self, 'filter_readdir3resok'): + data = getattr(self, 'filter_readdir3resok')(data) + if data.dir_attributes is None: + raise TypeError('data.dir_attributes == None') + self.pack_post_op_attr(data.dir_attributes) + if data.cookieverf is None: + raise TypeError('data.cookieverf == None') + self.pack_cookieverf3(data.cookieverf) + if data.reply is None: + raise TypeError('data.reply == None') + self.pack_dirlist3(data.reply) + + def pack_readdir3res(self, data): + if hasattr(self, 'filter_readdir3res'): + data = getattr(self, 'filter_readdir3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_readdir3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_readdirplus3args(self, data): + if hasattr(self, 'filter_readdirplus3args'): + data = getattr(self, 'filter_readdirplus3args')(data) + if data.dir is None: + raise TypeError('data.dir == None') + self.pack_nfs_fh3(data.dir) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_uint64(data.cookie) + if data.cookieverf is None: + raise TypeError('data.cookieverf == None') + self.pack_cookieverf3(data.cookieverf) + if data.dircount is None: + raise TypeError('data.dircount == None') + self.pack_uint32(data.dircount) + if data.maxcount is None: + raise TypeError('data.maxcount == None') + self.pack_uint32(data.maxcount) + + def pack_entryplus3(self, data): + if hasattr(self, 'filter_entryplus3'): + data = getattr(self, 'filter_entryplus3')(data) + if data.fileid is None: + raise TypeError('data.fileid == None') + self.pack_uint64(data.fileid) + if data.name is None: + raise TypeError('data.name == None') + self.pack_filename3(data.name) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_uint64(data.cookie) + if data.name_attributes is None: + raise TypeError('data.name_attributes == None') + self.pack_post_op_attr(data.name_attributes) + if data.name_handle is None: + raise TypeError('data.name_handle == None') + self.pack_post_op_fh3(data.name_handle) + if data.nextentry is None: + raise TypeError('data.nextentry == None') + if len(data.nextentry) > 1 and self.check_array: + raise XDRError('array length too long for data.nextentry') + self.pack_array(data.nextentry, self.pack_entryplus3) + + def pack_dirlistplus3(self, data): + if hasattr(self, 'filter_dirlistplus3'): + data = getattr(self, 'filter_dirlistplus3')(data) + if data.entries is None: + raise TypeError('data.entries == None') + if len(data.entries) > 1 and self.check_array: + raise XDRError('array length too long for data.entries') + self.pack_array(data.entries, self.pack_entryplus3) + if data.eof is None: + raise TypeError('data.eof == None') + self.pack_bool(data.eof) + + def pack_readdirplus3resok(self, data): + if hasattr(self, 'filter_readdirplus3resok'): + data = getattr(self, 'filter_readdirplus3resok')(data) + if data.dir_attributes is None: + raise TypeError('data.dir_attributes == None') + self.pack_post_op_attr(data.dir_attributes) + if data.cookieverf is None: + raise TypeError('data.cookieverf == None') + self.pack_cookieverf3(data.cookieverf) + if data.reply is None: + raise TypeError('data.reply == None') + self.pack_dirlistplus3(data.reply) + + def pack_readdirplus3res(self, data): + if hasattr(self, 'filter_readdirplus3res'): + data = getattr(self, 'filter_readdirplus3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_readdirplus3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_fsstat3resok(self, data): + if hasattr(self, 'filter_fsstat3resok'): + data = getattr(self, 'filter_fsstat3resok')(data) + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_post_op_attr(data.obj_attributes) + if data.tbytes is None: + raise TypeError('data.tbytes == None') + self.pack_uint64(data.tbytes) + if data.fbytes is None: + raise TypeError('data.fbytes == None') + self.pack_uint64(data.fbytes) + if data.abytes is None: + raise TypeError('data.abytes == None') + self.pack_uint64(data.abytes) + if data.tfiles is None: + raise TypeError('data.tfiles == None') + self.pack_uint64(data.tfiles) + if data.ffiles is None: + raise TypeError('data.ffiles == None') + self.pack_uint64(data.ffiles) + if data.afiles is None: + raise TypeError('data.afiles == None') + self.pack_uint64(data.afiles) + if data.invarsec is None: + raise TypeError('data.invarsec == None') + self.pack_uint32(data.invarsec) + + def pack_fsstat3res(self, data): + if hasattr(self, 'filter_fsstat3res'): + data = getattr(self, 'filter_fsstat3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_fsstat3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_fsinfo3resok(self, data): + if hasattr(self, 'filter_fsinfo3resok'): + data = getattr(self, 'filter_fsinfo3resok')(data) + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_post_op_attr(data.obj_attributes) + if data.rtmax is None: + raise TypeError('data.rtmax == None') + self.pack_uint32(data.rtmax) + if data.rtpref is None: + raise TypeError('data.rtpref == None') + self.pack_uint32(data.rtpref) + if data.rtmult is None: + raise TypeError('data.rtmult == None') + self.pack_uint32(data.rtmult) + if data.wtmax is None: + raise TypeError('data.wtmax == None') + self.pack_uint32(data.wtmax) + if data.wtpref is None: + raise TypeError('data.wtpref == None') + self.pack_uint32(data.wtpref) + if data.wtmult is None: + raise TypeError('data.wtmult == None') + self.pack_uint32(data.wtmult) + if data.dtpref is None: + raise TypeError('data.dtpref == None') + self.pack_uint32(data.dtpref) + if data.maxfilesize is None: + raise TypeError('data.maxfilesize == None') + self.pack_uint64(data.maxfilesize) + if data.time_delta is None: + raise TypeError('data.time_delta == None') + self.pack_nfstime3(data.time_delta) + if data.properties is None: + raise TypeError('data.properties == None') + self.pack_uint32(data.properties) + + def pack_fsinfo3res(self, data): + if hasattr(self, 'filter_fsinfo3res'): + data = getattr(self, 'filter_fsinfo3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_fsinfo3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_pathconf3resok(self, data): + if hasattr(self, 'filter_pathconf3resok'): + data = getattr(self, 'filter_pathconf3resok')(data) + if data.obj_attributes is None: + raise TypeError('data.obj_attributes == None') + self.pack_post_op_attr(data.obj_attributes) + if data.linkmax is None: + raise TypeError('data.linkmax == None') + self.pack_uint32(data.linkmax) + if data.name_max is None: + raise TypeError('data.name_max == None') + self.pack_uint32(data.name_max) + if data.no_trunc is None: + raise TypeError('data.no_trunc == None') + self.pack_bool(data.no_trunc) + if data.chown_restricted is None: + raise TypeError('data.chown_restricted == None') + self.pack_bool(data.chown_restricted) + if data.case_insensitive is None: + raise TypeError('data.case_insensitive == None') + self.pack_bool(data.case_insensitive) + if data.case_preserving is None: + raise TypeError('data.case_preserving == None') + self.pack_bool(data.case_preserving) + + def pack_pathconf3res(self, data): + if hasattr(self, 'filter_pathconf3res'): + data = getattr(self, 'filter_pathconf3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_pathconf3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_post_op_attr(data.resfail) + + def pack_commit3args(self, data): + if hasattr(self, 'filter_commit3args'): + data = getattr(self, 'filter_commit3args')(data) + if data.file is None: + raise TypeError('data.file == None') + self.pack_nfs_fh3(data.file) + if data.offset is None: + raise TypeError('data.offset == None') + self.pack_uint64(data.offset) + if data.count is None: + raise TypeError('data.count == None') + self.pack_uint32(data.count) + + def pack_commit3resok(self, data): + if hasattr(self, 'filter_commit3resok'): + data = getattr(self, 'filter_commit3resok')(data) + if data.file_wcc is None: + raise TypeError('data.file_wcc == None') + self.pack_wcc_data(data.file_wcc) + if data.verf is None: + raise TypeError('data.verf == None') + self.pack_writeverf3(data.verf) + + def pack_commit3res(self, data): + if hasattr(self, 'filter_commit3res'): + data = getattr(self, 'filter_commit3res')(data) + if data.status is None: + raise TypeError('data.status == None') + self.pack_nfsstat3(data.status) + if data.status == const.NFS3_OK: + if data.resok is None: + raise TypeError('data.resok == None') + self.pack_commit3resok(data.resok) + else: + if data.resfail is None: + raise TypeError('data.resfail == None') + self.pack_wcc_data(data.resfail) + + def pack_setaclargs(self, data): + if hasattr(self, 'filter_setaclargs'): + data = getattr(self, 'filter_setaclargs')(data) + if data.dargs is None: + raise TypeError('data.dargs == None') + self.pack_diropargs3(data.dargs) + if data.wargs is None: + raise TypeError('data.wargs == None') + self.pack_write3args(data.wargs) + +class NFS3Unpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + unpack_uint64 = unpack_uhyper + + unpack_int64 = unpack_hyper + + unpack_uint32 = unpack_uint + + unpack_int32 = unpack_int + + def unpack_filename3(self): + data = self.unpack_string() + if hasattr(self, 'filter_filename3'): + data = getattr(self, 'filter_filename3')(data) + return data + + def unpack_nfspath3(self): + data = self.unpack_string() + if hasattr(self, 'filter_nfspath3'): + data = getattr(self, 'filter_nfspath3')(data) + return data + + def unpack_cookieverf3(self): + data = self.unpack_fopaque(const.NFS3_COOKIEVERFSIZE) + if hasattr(self, 'filter_cookieverf3'): + data = getattr(self, 'filter_cookieverf3')(data) + return data + + def unpack_createverf3(self): + data = self.unpack_fopaque(const.NFS3_CREATEVERFSIZE) + if hasattr(self, 'filter_createverf3'): + data = getattr(self, 'filter_createverf3')(data) + return data + + def unpack_writeverf3(self): + data = self.unpack_fopaque(const.NFS3_WRITEVERFSIZE) + if hasattr(self, 'filter_writeverf3'): + data = getattr(self, 'filter_writeverf3')(data) + return data + + def unpack_nfsstat3(self): + data = self.unpack_int() + if self.check_enum and data not in [const.NFS3_OK, const.NFS3ERR_PERM, const.NFS3ERR_NOENT, const.NFS3ERR_IO, const.NFS3ERR_NXIO, const.NFS3ERR_ACCES, const.NFS3ERR_EXIST, const.NFS3ERR_XDEV, const.NFS3ERR_NODEV, const.NFS3ERR_NOTDIR, const.NFS3ERR_ISDIR, const.NFS3ERR_INVAL, const.NFS3ERR_FBIG, const.NFS3ERR_NOSPC, const.NFS3ERR_ROFS, const.NFS3ERR_MLINK, const.NFS3ERR_NAMETOOLONG, const.NFS3ERR_NOTEMPTY, const.NFS3ERR_DQUOT, const.NFS3ERR_STALE, const.NFS3ERR_REMOTE, const.NFS3ERR_BADHANDLE, const.NFS3ERR_NOT_SYNC, const.NFS3ERR_BAD_COOKIE, const.NFS3ERR_NOTSUPP, const.NFS3ERR_TOOSMALL, const.NFS3ERR_SERVERFAULT, const.NFS3ERR_BADTYPE, const.NFS3ERR_JUKEBOX, const.NFS3ERR_FPRINTNOTFOUND, const.NFS3ERR_ABORTED]: + raise XDRError('value=%s not in enum nfsstat3' % data) + if hasattr(self, 'filter_nfsstat3'): + data = getattr(self, 'filter_nfsstat3')(data) + return data + + def unpack_ftype3(self): + data = self.unpack_int() + if self.check_enum and data not in [const.NF3REG, const.NF3DIR, const.NF3BLK, const.NF3CHR, const.NF3LNK, const.NF3SOCK, const.NF3FIFO]: + raise XDRError('value=%s not in enum ftype3' % data) + if hasattr(self, 'filter_ftype3'): + data = getattr(self, 'filter_ftype3')(data) + return data + + def unpack_specdata3(self): + data = types.specdata3() + data.major = self.unpack_uint32() + data.minor = self.unpack_uint32() + if hasattr(self, 'filter_specdata3'): + data = getattr(self, 'filter_specdata3')(data) + return data + + def unpack_nfs_fh3(self): + data = types.nfs_fh3() + data.data = self.unpack_opaque() + if len(data.data) > const.NFS3_FHSIZE and self.check_array: + raise XDRError('array length too long for data.data') + if hasattr(self, 'filter_nfs_fh3'): + data = getattr(self, 'filter_nfs_fh3')(data) + return data + + def unpack_nfstime3(self): + data = types.nfstime3() + data.seconds = self.unpack_uint32() + data.nseconds = self.unpack_uint32() + if hasattr(self, 'filter_nfstime3'): + data = getattr(self, 'filter_nfstime3')(data) + return data + + def unpack_fattr3(self): + data = types.fattr3() + data.type = self.unpack_ftype3() + data.mode = self.unpack_uint32() + data.nlink = self.unpack_uint32() + data.uid = self.unpack_uint32() + data.gid = self.unpack_uint32() + data.size = self.unpack_uint64() + data.used = self.unpack_uint64() + data.rdev = self.unpack_specdata3() + data.fsid = self.unpack_uint64() + data.fileid = self.unpack_uint64() + data.atime = self.unpack_nfstime3() + data.mtime = self.unpack_nfstime3() + data.ctime = self.unpack_nfstime3() + if hasattr(self, 'filter_fattr3'): + data = getattr(self, 'filter_fattr3')(data) + return data + + def unpack_post_op_attr(self): + data = types.post_op_attr() + data.present = self.unpack_bool() + if data.present == const.TRUE: + data.attributes = self.unpack_fattr3() + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + if hasattr(self, 'filter_post_op_attr'): + data = getattr(self, 'filter_post_op_attr')(data) + return data + + def unpack_wcc_attr(self): + data = types.wcc_attr() + data.size = self.unpack_uint64() + data.mtime = self.unpack_nfstime3() + data.ctime = self.unpack_nfstime3() + if hasattr(self, 'filter_wcc_attr'): + data = getattr(self, 'filter_wcc_attr')(data) + return data + + def unpack_pre_op_attr(self): + data = types.pre_op_attr() + data.present = self.unpack_bool() + if data.present == const.TRUE: + data.attributes = self.unpack_wcc_attr() + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + if hasattr(self, 'filter_pre_op_attr'): + data = getattr(self, 'filter_pre_op_attr')(data) + return data + + def unpack_wcc_data(self): + data = types.wcc_data() + data.before = self.unpack_pre_op_attr() + data.after = self.unpack_post_op_attr() + if hasattr(self, 'filter_wcc_data'): + data = getattr(self, 'filter_wcc_data')(data) + return data + + def unpack_post_op_fh3(self): + data = types.post_op_fh3() + data.present = self.unpack_bool() + if data.present == const.TRUE: + data.handle = self.unpack_nfs_fh3() + elif data.present == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.present) + if hasattr(self, 'filter_post_op_fh3'): + data = getattr(self, 'filter_post_op_fh3')(data) + return data + + def unpack_set_uint32(self): + data = types.set_uint32() + data.set = self.unpack_bool() + if data.set == const.TRUE: + data.val = self.unpack_uint32() + else: + pass + if hasattr(self, 'filter_set_uint32'): + data = getattr(self, 'filter_set_uint32')(data) + return data + + def unpack_set_uint64(self): + data = types.set_uint64() + data.set = self.unpack_bool() + if data.set == const.TRUE: + data.val = self.unpack_uint64() + else: + pass + if hasattr(self, 'filter_set_uint64'): + data = getattr(self, 'filter_set_uint64')(data) + return data + + def unpack_time_how(self): + data = self.unpack_int() + if self.check_enum and data not in [const.DONT_CHANGE, const.SET_TO_SERVER_TIME, const.SET_TO_CLIENT_TIME]: + raise XDRError('value=%s not in enum time_how' % data) + if hasattr(self, 'filter_time_how'): + data = getattr(self, 'filter_time_how')(data) + return data + + def unpack_set_time(self): + data = types.set_time() + data.set = self.unpack_time_how() + if data.set == const.SET_TO_CLIENT_TIME: + data.time = self.unpack_nfstime3() + else: + pass + if hasattr(self, 'filter_set_time'): + data = getattr(self, 'filter_set_time')(data) + return data + + def unpack_sattr3(self): + data = types.sattr3() + data.mode = self.unpack_set_uint32() + data.uid = self.unpack_set_uint32() + data.gid = self.unpack_set_uint32() + data.size = self.unpack_set_uint64() + data.atime = self.unpack_set_time() + data.mtime = self.unpack_set_time() + if hasattr(self, 'filter_sattr3'): + data = getattr(self, 'filter_sattr3')(data) + return data + + def unpack_diropargs3(self): + data = types.diropargs3() + data.dir = self.unpack_nfs_fh3() + data.name = self.unpack_filename3() + if hasattr(self, 'filter_diropargs3'): + data = getattr(self, 'filter_diropargs3')(data) + return data + + def unpack_diropres3ok(self): + data = types.diropres3ok() + data.obj = self.unpack_post_op_fh3() + data.obj_attributes = self.unpack_post_op_attr() + data.dir_wcc = self.unpack_wcc_data() + if hasattr(self, 'filter_diropres3ok'): + data = getattr(self, 'filter_diropres3ok')(data) + return data + + def unpack_diropres3(self): + data = types.diropres3() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_diropres3ok() + else: + data.resfail = self.unpack_wcc_data() + if hasattr(self, 'filter_diropres3'): + data = getattr(self, 'filter_diropres3')(data) + return data + + def unpack_wccstat3(self): + data = types.wccstat3() + data.status = self.unpack_nfsstat3() + if data.status == -1: + pass + else: + data.wcc = self.unpack_wcc_data() + if hasattr(self, 'filter_wccstat3'): + data = getattr(self, 'filter_wccstat3')(data) + return data + + def unpack_getattr3res(self): + data = types.getattr3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.attributes = self.unpack_fattr3() + else: + pass + if hasattr(self, 'filter_getattr3res'): + data = getattr(self, 'filter_getattr3res')(data) + return data + + def unpack_sattrguard3(self): + data = types.sattrguard3() + data.check = self.unpack_bool() + if data.check == const.TRUE: + data.ctime = self.unpack_nfstime3() + elif data.check == const.FALSE: + pass + else: + raise XDRError('bad switch=%s' % data.check) + if hasattr(self, 'filter_sattrguard3'): + data = getattr(self, 'filter_sattrguard3')(data) + return data + + def unpack_setattr3args(self): + data = types.setattr3args() + data.object = self.unpack_nfs_fh3() + data.new_attributes = self.unpack_sattr3() + data.guard = self.unpack_sattrguard3() + if hasattr(self, 'filter_setattr3args'): + data = getattr(self, 'filter_setattr3args')(data) + return data + + def unpack_lookup3resok(self): + data = types.lookup3resok() + data.object = self.unpack_nfs_fh3() + data.obj_attributes = self.unpack_post_op_attr() + data.dir_attributes = self.unpack_post_op_attr() + if hasattr(self, 'filter_lookup3resok'): + data = getattr(self, 'filter_lookup3resok')(data) + return data + + def unpack_lookup3res(self): + data = types.lookup3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_lookup3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_lookup3res'): + data = getattr(self, 'filter_lookup3res')(data) + return data + + def unpack_access3args(self): + data = types.access3args() + data.object = self.unpack_nfs_fh3() + data.access = self.unpack_uint32() + if hasattr(self, 'filter_access3args'): + data = getattr(self, 'filter_access3args')(data) + return data + + def unpack_access3resok(self): + data = types.access3resok() + data.obj_attributes = self.unpack_post_op_attr() + data.access = self.unpack_uint32() + if hasattr(self, 'filter_access3resok'): + data = getattr(self, 'filter_access3resok')(data) + return data + + def unpack_access3res(self): + data = types.access3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_access3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_access3res'): + data = getattr(self, 'filter_access3res')(data) + return data + + def unpack_readlink3resok(self): + data = types.readlink3resok() + data.symlink_attributes = self.unpack_post_op_attr() + data.data = self.unpack_nfspath3() + if hasattr(self, 'filter_readlink3resok'): + data = getattr(self, 'filter_readlink3resok')(data) + return data + + def unpack_readlink3res(self): + data = types.readlink3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_readlink3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_readlink3res'): + data = getattr(self, 'filter_readlink3res')(data) + return data + + def unpack_read3args(self): + data = types.read3args() + data.file = self.unpack_nfs_fh3() + data.offset = self.unpack_uint64() + data.count = self.unpack_uint32() + if hasattr(self, 'filter_read3args'): + data = getattr(self, 'filter_read3args')(data) + return data + + def unpack_read3resok(self): + data = types.read3resok() + data.file_attributes = self.unpack_post_op_attr() + data.count = self.unpack_uint32() + data.eof = self.unpack_bool() + data.data = self.unpack_opaque() + if hasattr(self, 'filter_read3resok'): + data = getattr(self, 'filter_read3resok')(data) + return data + + def unpack_read3res(self): + data = types.read3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_read3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_read3res'): + data = getattr(self, 'filter_read3res')(data) + return data + + def unpack_stable_how(self): + data = self.unpack_int() + if self.check_enum and data not in [const.UNSTABLE, const.DATA_SYNC, const.FILE_SYNC]: + raise XDRError('value=%s not in enum stable_how' % data) + if hasattr(self, 'filter_stable_how'): + data = getattr(self, 'filter_stable_how')(data) + return data + + def unpack_write3args(self): + data = types.write3args() + data.file = self.unpack_nfs_fh3() + data.offset = self.unpack_uint64() + data.count = self.unpack_uint32() + data.stable = self.unpack_stable_how() + data.data = self.unpack_opaque() + if hasattr(self, 'filter_write3args'): + data = getattr(self, 'filter_write3args')(data) + return data + + def unpack_write3resok(self): + data = types.write3resok() + data.file_wcc = self.unpack_wcc_data() + data.count = self.unpack_uint32() + data.committed = self.unpack_stable_how() + data.verf = self.unpack_writeverf3() + if hasattr(self, 'filter_write3resok'): + data = getattr(self, 'filter_write3resok')(data) + return data + + def unpack_write3res(self): + data = types.write3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_write3resok() + else: + data.resfail = self.unpack_wcc_data() + if hasattr(self, 'filter_write3res'): + data = getattr(self, 'filter_write3res')(data) + return data + + def unpack_createmode3(self): + data = self.unpack_int() + if self.check_enum and data not in [const.UNCHECKED, const.GUARDED, const.EXCLUSIVE]: + raise XDRError('value=%s not in enum createmode3' % data) + if hasattr(self, 'filter_createmode3'): + data = getattr(self, 'filter_createmode3')(data) + return data + + def unpack_createhow3(self): + data = types.createhow3() + data.mode = self.unpack_createmode3() + if data.mode == const.UNCHECKED or data.mode == const.GUARDED: + data.obj_attributes = self.unpack_sattr3() + elif data.mode == const.EXCLUSIVE: + data.verf = self.unpack_createverf3() + else: + raise XDRError('bad switch=%s' % data.mode) + if hasattr(self, 'filter_createhow3'): + data = getattr(self, 'filter_createhow3')(data) + return data + + def unpack_create3args(self): + data = types.create3args() + data.where = self.unpack_diropargs3() + data.how = self.unpack_createhow3() + if hasattr(self, 'filter_create3args'): + data = getattr(self, 'filter_create3args')(data) + return data + + def unpack_mkdir3args(self): + data = types.mkdir3args() + data.where = self.unpack_diropargs3() + data.attributes = self.unpack_sattr3() + if hasattr(self, 'filter_mkdir3args'): + data = getattr(self, 'filter_mkdir3args')(data) + return data + + def unpack_symlinkdata3(self): + data = types.symlinkdata3() + data.symlink_attributes = self.unpack_sattr3() + data.symlink_data = self.unpack_nfspath3() + if hasattr(self, 'filter_symlinkdata3'): + data = getattr(self, 'filter_symlinkdata3')(data) + return data + + def unpack_symlink3args(self): + data = types.symlink3args() + data.where = self.unpack_diropargs3() + data.symlink = self.unpack_symlinkdata3() + if hasattr(self, 'filter_symlink3args'): + data = getattr(self, 'filter_symlink3args')(data) + return data + + def unpack_devicedata3(self): + data = types.devicedata3() + data.dev_attributes = self.unpack_sattr3() + data.spec = self.unpack_specdata3() + if hasattr(self, 'filter_devicedata3'): + data = getattr(self, 'filter_devicedata3')(data) + return data + + def unpack_mknoddata3(self): + data = types.mknoddata3() + data.type = self.unpack_ftype3() + if data.type == const.NF3CHR or data.type == const.NF3BLK: + data.device = self.unpack_devicedata3() + elif data.type == const.NF3SOCK or data.type == const.NF3FIFO: + data.pipe_attributes = self.unpack_sattr3() + else: + pass + if hasattr(self, 'filter_mknoddata3'): + data = getattr(self, 'filter_mknoddata3')(data) + return data + + def unpack_mknod3args(self): + data = types.mknod3args() + data.where = self.unpack_diropargs3() + data.what = self.unpack_mknoddata3() + if hasattr(self, 'filter_mknod3args'): + data = getattr(self, 'filter_mknod3args')(data) + return data + + def unpack_rename3args(self): + data = types.rename3args() + data.from_dir = self.unpack_diropargs3() + data.to_dir = self.unpack_diropargs3() + if hasattr(self, 'filter_rename3args'): + data = getattr(self, 'filter_rename3args')(data) + return data + + def unpack_rename3wcc(self): + data = types.rename3wcc() + data.fromdir_wcc = self.unpack_wcc_data() + data.todir_wcc = self.unpack_wcc_data() + if hasattr(self, 'filter_rename3wcc'): + data = getattr(self, 'filter_rename3wcc')(data) + return data + + def unpack_rename3res(self): + data = types.rename3res() + data.status = self.unpack_nfsstat3() + if data.status == -1: + pass + else: + data.res = self.unpack_rename3wcc() + if hasattr(self, 'filter_rename3res'): + data = getattr(self, 'filter_rename3res')(data) + return data + + def unpack_link3args(self): + data = types.link3args() + data.file = self.unpack_nfs_fh3() + data.link = self.unpack_diropargs3() + if hasattr(self, 'filter_link3args'): + data = getattr(self, 'filter_link3args')(data) + return data + + def unpack_link3wcc(self): + data = types.link3wcc() + data.file_attributes = self.unpack_post_op_attr() + data.linkdir_wcc = self.unpack_wcc_data() + if hasattr(self, 'filter_link3wcc'): + data = getattr(self, 'filter_link3wcc')(data) + return data + + def unpack_link3res(self): + data = types.link3res() + data.status = self.unpack_nfsstat3() + if data.status == -1: + pass + else: + data.res = self.unpack_link3wcc() + if hasattr(self, 'filter_link3res'): + data = getattr(self, 'filter_link3res')(data) + return data + + def unpack_readdir3args(self): + data = types.readdir3args() + data.dir = self.unpack_nfs_fh3() + data.cookie = self.unpack_uint64() + data.cookieverf = self.unpack_cookieverf3() + data.count = self.unpack_uint32() + if hasattr(self, 'filter_readdir3args'): + data = getattr(self, 'filter_readdir3args')(data) + return data + + def unpack_entry3(self): + data = types.entry3() + data.fileid = self.unpack_uint64() + data.name = self.unpack_filename3() + data.cookie = self.unpack_uint64() + data.nextentry = self.unpack_array(self.unpack_entry3) + if len(data.nextentry) > 1 and self.check_array: + raise XDRError('array length too long for data.nextentry') + if hasattr(self, 'filter_entry3'): + data = getattr(self, 'filter_entry3')(data) + return data + + def unpack_dirlist3(self): + data = types.dirlist3() + data.entries = self.unpack_array(self.unpack_entry3) + if len(data.entries) > 1 and self.check_array: + raise XDRError('array length too long for data.entries') + data.eof = self.unpack_bool() + if hasattr(self, 'filter_dirlist3'): + data = getattr(self, 'filter_dirlist3')(data) + return data + + def unpack_readdir3resok(self): + data = types.readdir3resok() + data.dir_attributes = self.unpack_post_op_attr() + data.cookieverf = self.unpack_cookieverf3() + data.reply = self.unpack_dirlist3() + if hasattr(self, 'filter_readdir3resok'): + data = getattr(self, 'filter_readdir3resok')(data) + return data + + def unpack_readdir3res(self): + data = types.readdir3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_readdir3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_readdir3res'): + data = getattr(self, 'filter_readdir3res')(data) + return data + + def unpack_readdirplus3args(self): + data = types.readdirplus3args() + data.dir = self.unpack_nfs_fh3() + data.cookie = self.unpack_uint64() + data.cookieverf = self.unpack_cookieverf3() + data.dircount = self.unpack_uint32() + data.maxcount = self.unpack_uint32() + if hasattr(self, 'filter_readdirplus3args'): + data = getattr(self, 'filter_readdirplus3args')(data) + return data + + def unpack_entryplus3(self): + data = types.entryplus3() + data.fileid = self.unpack_uint64() + data.name = self.unpack_filename3() + data.cookie = self.unpack_uint64() + data.name_attributes = self.unpack_post_op_attr() + data.name_handle = self.unpack_post_op_fh3() + data.nextentry = self.unpack_array(self.unpack_entryplus3) + if len(data.nextentry) > 1 and self.check_array: + raise XDRError('array length too long for data.nextentry') + if hasattr(self, 'filter_entryplus3'): + data = getattr(self, 'filter_entryplus3')(data) + return data + + def unpack_dirlistplus3(self): + data = types.dirlistplus3() + data.entries = self.unpack_array(self.unpack_entryplus3) + if len(data.entries) > 1 and self.check_array: + raise XDRError('array length too long for data.entries') + data.eof = self.unpack_bool() + if hasattr(self, 'filter_dirlistplus3'): + data = getattr(self, 'filter_dirlistplus3')(data) + return data + + def unpack_readdirplus3resok(self): + data = types.readdirplus3resok() + data.dir_attributes = self.unpack_post_op_attr() + data.cookieverf = self.unpack_cookieverf3() + data.reply = self.unpack_dirlistplus3() + if hasattr(self, 'filter_readdirplus3resok'): + data = getattr(self, 'filter_readdirplus3resok')(data) + return data + + def unpack_readdirplus3res(self): + data = types.readdirplus3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_readdirplus3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_readdirplus3res'): + data = getattr(self, 'filter_readdirplus3res')(data) + return data + + def unpack_fsstat3resok(self): + data = types.fsstat3resok() + data.obj_attributes = self.unpack_post_op_attr() + data.tbytes = self.unpack_uint64() + data.fbytes = self.unpack_uint64() + data.abytes = self.unpack_uint64() + data.tfiles = self.unpack_uint64() + data.ffiles = self.unpack_uint64() + data.afiles = self.unpack_uint64() + data.invarsec = self.unpack_uint32() + if hasattr(self, 'filter_fsstat3resok'): + data = getattr(self, 'filter_fsstat3resok')(data) + return data + + def unpack_fsstat3res(self): + data = types.fsstat3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_fsstat3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_fsstat3res'): + data = getattr(self, 'filter_fsstat3res')(data) + return data + + def unpack_fsinfo3resok(self): + data = types.fsinfo3resok() + data.obj_attributes = self.unpack_post_op_attr() + data.rtmax = self.unpack_uint32() + data.rtpref = self.unpack_uint32() + data.rtmult = self.unpack_uint32() + data.wtmax = self.unpack_uint32() + data.wtpref = self.unpack_uint32() + data.wtmult = self.unpack_uint32() + data.dtpref = self.unpack_uint32() + data.maxfilesize = self.unpack_uint64() + data.time_delta = self.unpack_nfstime3() + data.properties = self.unpack_uint32() + if hasattr(self, 'filter_fsinfo3resok'): + data = getattr(self, 'filter_fsinfo3resok')(data) + return data + + def unpack_fsinfo3res(self): + data = types.fsinfo3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_fsinfo3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_fsinfo3res'): + data = getattr(self, 'filter_fsinfo3res')(data) + return data + + def unpack_pathconf3resok(self): + data = types.pathconf3resok() + data.obj_attributes = self.unpack_post_op_attr() + data.linkmax = self.unpack_uint32() + data.name_max = self.unpack_uint32() + data.no_trunc = self.unpack_bool() + data.chown_restricted = self.unpack_bool() + data.case_insensitive = self.unpack_bool() + data.case_preserving = self.unpack_bool() + if hasattr(self, 'filter_pathconf3resok'): + data = getattr(self, 'filter_pathconf3resok')(data) + return data + + def unpack_pathconf3res(self): + data = types.pathconf3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_pathconf3resok() + else: + data.resfail = self.unpack_post_op_attr() + if hasattr(self, 'filter_pathconf3res'): + data = getattr(self, 'filter_pathconf3res')(data) + return data + + def unpack_commit3args(self): + data = types.commit3args() + data.file = self.unpack_nfs_fh3() + data.offset = self.unpack_uint64() + data.count = self.unpack_uint32() + if hasattr(self, 'filter_commit3args'): + data = getattr(self, 'filter_commit3args')(data) + return data + + def unpack_commit3resok(self): + data = types.commit3resok() + data.file_wcc = self.unpack_wcc_data() + data.verf = self.unpack_writeverf3() + if hasattr(self, 'filter_commit3resok'): + data = getattr(self, 'filter_commit3resok')(data) + return data + + def unpack_commit3res(self): + data = types.commit3res() + data.status = self.unpack_nfsstat3() + if data.status == const.NFS3_OK: + data.resok = self.unpack_commit3resok() + else: + data.resfail = self.unpack_wcc_data() + if hasattr(self, 'filter_commit3res'): + data = getattr(self, 'filter_commit3res')(data) + return data + + def unpack_setaclargs(self): + data = types.setaclargs() + data.dargs = self.unpack_diropargs3() + data.wargs = self.unpack_write3args() + if hasattr(self, 'filter_setaclargs'): + data = getattr(self, 'filter_setaclargs')(data) + return data + diff --git a/nfs3/lib/nfs3/nfs3_type.py b/nfs3/lib/nfs3/nfs3_type.py new file mode 100644 index 0000000..54c40a6 --- /dev/null +++ b/nfs3/lib/nfs3/nfs3_type.py @@ -0,0 +1,1782 @@ +# Generated by rpcgen.py from nfs3.x on Wed Jun 24 11:38:48 2026 +import nfs3_const as const +class specdata3: + # XDR definition: + # struct specdata3 { + # uint32 major; + # uint32 minor; + # }; + def __init__(self, major=None, minor=None): + self.major = major + self.minor = minor + + def __repr__(self): + out = [] + if self.major is not None: + out += ['major=%s' % repr(self.major)] + if self.minor is not None: + out += ['minor=%s' % repr(self.minor)] + return 'specdata3(%s)' % ', '.join(out) + __str__ = __repr__ + +class nfs_fh3: + # XDR definition: + # struct nfs_fh3 { + # opaque data; + # }; + def __init__(self, data=None): + self.data = data + + def __repr__(self): + out = [] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'nfs_fh3(%s)' % ', '.join(out) + __str__ = __repr__ + +class nfstime3: + # XDR definition: + # struct nfstime3 { + # uint32 seconds; + # uint32 nseconds; + # }; + def __init__(self, seconds=None, nseconds=None): + self.seconds = seconds + self.nseconds = nseconds + + def __repr__(self): + out = [] + if self.seconds is not None: + out += ['seconds=%s' % repr(self.seconds)] + if self.nseconds is not None: + out += ['nseconds=%s' % repr(self.nseconds)] + return 'nfstime3(%s)' % ', '.join(out) + __str__ = __repr__ + +class fattr3: + # XDR definition: + # struct fattr3 { + # ftype3 type; + # uint32 mode; + # uint32 nlink; + # uint32 uid; + # uint32 gid; + # uint64 size; + # uint64 used; + # specdata3 rdev; + # uint64 fsid; + # uint64 fileid; + # nfstime3 atime; + # nfstime3 mtime; + # nfstime3 ctime; + # }; + def __init__(self, type=None, mode=None, nlink=None, uid=None, gid=None, size=None, used=None, rdev=None, fsid=None, fileid=None, atime=None, mtime=None, ctime=None): + self.type = type + self.mode = mode + self.nlink = nlink + self.uid = uid + self.gid = gid + self.size = size + self.used = used + self.rdev = rdev + self.fsid = fsid + self.fileid = fileid + self.atime = atime + self.mtime = mtime + self.ctime = ctime + + def __repr__(self): + out = [] + if self.type is not None: + out += ['type=%s' % const.ftype3.get(self.type, self.type)] + if self.mode is not None: + out += ['mode=%s' % repr(self.mode)] + if self.nlink is not None: + out += ['nlink=%s' % repr(self.nlink)] + if self.uid is not None: + out += ['uid=%s' % repr(self.uid)] + if self.gid is not None: + out += ['gid=%s' % repr(self.gid)] + if self.size is not None: + out += ['size=%s' % repr(self.size)] + if self.used is not None: + out += ['used=%s' % repr(self.used)] + if self.rdev is not None: + out += ['rdev=%s' % repr(self.rdev)] + if self.fsid is not None: + out += ['fsid=%s' % repr(self.fsid)] + if self.fileid is not None: + out += ['fileid=%s' % repr(self.fileid)] + if self.atime is not None: + out += ['atime=%s' % repr(self.atime)] + if self.mtime is not None: + out += ['mtime=%s' % repr(self.mtime)] + if self.ctime is not None: + out += ['ctime=%s' % repr(self.ctime)] + return 'fattr3(%s)' % ', '.join(out) + __str__ = __repr__ + +class post_op_attr: + # XDR definition: + # union post_op_attr switch(bool present) { + # case TRUE: + # fattr3 attributes; + # case FALSE: + # void; + # }; + def __init__(self, present=None, attributes=None): + self.present = present + self.attributes = attributes + + switch = property(lambda s: {const.TRUE:s.attributes,const.FALSE:None,}[s.present]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.present is not None: + out += ['present=%s' % repr(self.present)] + if self.attributes is not None: + out += ['attributes=%s' % repr(self.attributes)] + return 'post_op_attr(%s)' % ', '.join(out) + __str__ = __repr__ + +class wcc_attr: + # XDR definition: + # struct wcc_attr { + # uint64 size; + # nfstime3 mtime; + # nfstime3 ctime; + # }; + def __init__(self, size=None, mtime=None, ctime=None): + self.size = size + self.mtime = mtime + self.ctime = ctime + + def __repr__(self): + out = [] + if self.size is not None: + out += ['size=%s' % repr(self.size)] + if self.mtime is not None: + out += ['mtime=%s' % repr(self.mtime)] + if self.ctime is not None: + out += ['ctime=%s' % repr(self.ctime)] + return 'wcc_attr(%s)' % ', '.join(out) + __str__ = __repr__ + +class pre_op_attr: + # XDR definition: + # union pre_op_attr switch(bool present) { + # case TRUE: + # wcc_attr attributes; + # case FALSE: + # void; + # }; + def __init__(self, present=None, attributes=None): + self.present = present + self.attributes = attributes + + switch = property(lambda s: {const.TRUE:s.attributes,const.FALSE:None,}[s.present]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.present is not None: + out += ['present=%s' % repr(self.present)] + if self.attributes is not None: + out += ['attributes=%s' % repr(self.attributes)] + return 'pre_op_attr(%s)' % ', '.join(out) + __str__ = __repr__ + +class wcc_data: + # XDR definition: + # struct wcc_data { + # pre_op_attr before; + # post_op_attr after; + # }; + def __init__(self, before=None, after=None): + self.before = before + self.after = after + + def __repr__(self): + out = [] + if self.before is not None: + out += ['before=%s' % repr(self.before)] + if self.after is not None: + out += ['after=%s' % repr(self.after)] + return 'wcc_data(%s)' % ', '.join(out) + __str__ = __repr__ + +class post_op_fh3: + # XDR definition: + # union post_op_fh3 switch(bool present) { + # case TRUE: + # nfs_fh3 handle; + # case FALSE: + # void; + # }; + def __init__(self, present=None, handle=None): + self.present = present + self.handle = handle + + switch = property(lambda s: {const.TRUE:s.handle,const.FALSE:None,}[s.present]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.present is not None: + out += ['present=%s' % repr(self.present)] + if self.handle is not None: + out += ['handle=%s' % repr(self.handle)] + return 'post_op_fh3(%s)' % ', '.join(out) + __str__ = __repr__ + +class set_uint32: + # XDR definition: + # union set_uint32 switch(bool set) { + # case TRUE: + # uint32 val; + # default: + # void; + # }; + def __init__(self, set=None, val=None): + self.set = set + self.val = val + + switch = property(lambda s: {const.TRUE:s.val,}.get(s.set, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.set is not None: + out += ['set=%s' % repr(self.set)] + if self.val is not None: + out += ['val=%s' % repr(self.val)] + return 'set_uint32(%s)' % ', '.join(out) + __str__ = __repr__ + +class set_uint64: + # XDR definition: + # union set_uint64 switch(bool set) { + # case TRUE: + # uint64 val; + # default: + # void; + # }; + def __init__(self, set=None, val=None): + self.set = set + self.val = val + + switch = property(lambda s: {const.TRUE:s.val,}.get(s.set, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.set is not None: + out += ['set=%s' % repr(self.set)] + if self.val is not None: + out += ['val=%s' % repr(self.val)] + return 'set_uint64(%s)' % ', '.join(out) + __str__ = __repr__ + +class set_time: + # XDR definition: + # union set_time switch(time_how set) { + # case SET_TO_CLIENT_TIME: + # nfstime3 time; + # default: + # void; + # }; + def __init__(self, set=None, time=None): + self.set = set + self.time = time + + switch = property(lambda s: {const.SET_TO_CLIENT_TIME:s.time,}.get(s.set, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.set is not None: + out += ['set=%s' % const.time_how.get(self.set, self.set)] + if self.time is not None: + out += ['time=%s' % repr(self.time)] + return 'set_time(%s)' % ', '.join(out) + __str__ = __repr__ + +class sattr3: + # XDR definition: + # struct sattr3 { + # set_uint32 mode; + # set_uint32 uid; + # set_uint32 gid; + # set_uint64 size; + # set_time atime; + # set_time mtime; + # }; + def __init__(self, mode=None, uid=None, gid=None, size=None, atime=None, mtime=None): + self.mode = mode + self.uid = uid + self.gid = gid + self.size = size + self.atime = atime + self.mtime = mtime + + def __repr__(self): + out = [] + if self.mode is not None: + out += ['mode=%s' % repr(self.mode)] + if self.uid is not None: + out += ['uid=%s' % repr(self.uid)] + if self.gid is not None: + out += ['gid=%s' % repr(self.gid)] + if self.size is not None: + out += ['size=%s' % repr(self.size)] + if self.atime is not None: + out += ['atime=%s' % repr(self.atime)] + if self.mtime is not None: + out += ['mtime=%s' % repr(self.mtime)] + return 'sattr3(%s)' % ', '.join(out) + __str__ = __repr__ + +class diropargs3: + # XDR definition: + # struct diropargs3 { + # nfs_fh3 dir; + # filename3 name; + # }; + def __init__(self, dir=None, name=None): + self.dir = dir + self.name = name + + def __getattr__(self, attr): + return getattr(self.dir, attr) + + def __repr__(self): + out = [] + if self.dir is not None: + out += ['dir=%s' % repr(self.dir)] + if self.name is not None: + out += ['name=%s' % repr(self.name)] + return 'diropargs3(%s)' % ', '.join(out) + __str__ = __repr__ + +class diropres3ok: + # XDR definition: + # struct diropres3ok { + # post_op_fh3 obj; + # post_op_attr obj_attributes; + # wcc_data dir_wcc; + # }; + def __init__(self, obj=None, obj_attributes=None, dir_wcc=None): + self.obj = obj + self.obj_attributes = obj_attributes + self.dir_wcc = dir_wcc + + def __repr__(self): + out = [] + if self.obj is not None: + out += ['obj=%s' % repr(self.obj)] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.dir_wcc is not None: + out += ['dir_wcc=%s' % repr(self.dir_wcc)] + return 'diropres3ok(%s)' % ', '.join(out) + __str__ = __repr__ + +class diropres3: + # XDR definition: + # union diropres3 switch(nfsstat3 status) { + # case NFS3_OK: + # diropres3ok resok; + # default: + # wcc_data resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'diropres3(%s)' % ', '.join(out) + __str__ = __repr__ + +class wccstat3: + # XDR definition: + # union wccstat3 switch(nfsstat3 status) { + # case -1: + # void; + # default: + # wcc_data wcc; + # }; + def __init__(self, status=None, wcc=None): + self.status = status + self.wcc = wcc + + switch = property(lambda s: {-1:None,}.get(s.status, s.wcc)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.wcc is not None: + out += ['wcc=%s' % repr(self.wcc)] + return 'wccstat3(%s)' % ', '.join(out) + __str__ = __repr__ + +class getattr3res: + # XDR definition: + # union getattr3res switch(nfsstat3 status) { + # case NFS3_OK: + # fattr3 attributes; + # default: + # void; + # }; + def __init__(self, status=None, attributes=None): + self.status = status + self.attributes = attributes + + switch = property(lambda s: {const.NFS3_OK:s.attributes,}.get(s.status, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.attributes is not None: + out += ['attributes=%s' % repr(self.attributes)] + return 'getattr3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class sattrguard3: + # XDR definition: + # union sattrguard3 switch(bool check) { + # case TRUE: + # nfstime3 ctime; + # case FALSE: + # void; + # }; + def __init__(self, check=None, ctime=None): + self.check = check + self.ctime = ctime + + switch = property(lambda s: {const.TRUE:s.ctime,const.FALSE:None,}[s.check]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.check is not None: + out += ['check=%s' % repr(self.check)] + if self.ctime is not None: + out += ['ctime=%s' % repr(self.ctime)] + return 'sattrguard3(%s)' % ', '.join(out) + __str__ = __repr__ + +class setattr3args: + # XDR definition: + # struct setattr3args { + # nfs_fh3 object; + # sattr3 new_attributes; + # sattrguard3 guard; + # }; + def __init__(self, object=None, new_attributes=None, guard=None): + self.object = object + self.new_attributes = new_attributes + self.guard = guard + + def __repr__(self): + out = [] + if self.object is not None: + out += ['object=%s' % repr(self.object)] + if self.new_attributes is not None: + out += ['new_attributes=%s' % repr(self.new_attributes)] + if self.guard is not None: + out += ['guard=%s' % repr(self.guard)] + return 'setattr3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class lookup3resok: + # XDR definition: + # struct lookup3resok { + # nfs_fh3 object; + # post_op_attr obj_attributes; + # post_op_attr dir_attributes; + # }; + def __init__(self, object=None, obj_attributes=None, dir_attributes=None): + self.object = object + self.obj_attributes = obj_attributes + self.dir_attributes = dir_attributes + + def __repr__(self): + out = [] + if self.object is not None: + out += ['object=%s' % repr(self.object)] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.dir_attributes is not None: + out += ['dir_attributes=%s' % repr(self.dir_attributes)] + return 'lookup3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class lookup3res: + # XDR definition: + # union lookup3res switch(nfsstat3 status) { + # case NFS3_OK: + # lookup3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'lookup3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class access3args: + # XDR definition: + # struct access3args { + # nfs_fh3 object; + # uint32 access; + # }; + def __init__(self, object=None, access=None): + self.object = object + self.access = access + + def __getattr__(self, attr): + return getattr(self.object, attr) + + def __repr__(self): + out = [] + if self.object is not None: + out += ['object=%s' % repr(self.object)] + if self.access is not None: + out += ['access=%s' % repr(self.access)] + return 'access3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class access3resok: + # XDR definition: + # struct access3resok { + # post_op_attr obj_attributes; + # uint32 access; + # }; + def __init__(self, obj_attributes=None, access=None): + self.obj_attributes = obj_attributes + self.access = access + + def __getattr__(self, attr): + return getattr(self.obj_attributes, attr) + + def __repr__(self): + out = [] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.access is not None: + out += ['access=%s' % repr(self.access)] + return 'access3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class access3res: + # XDR definition: + # union access3res switch(nfsstat3 status) { + # case NFS3_OK: + # access3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'access3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class readlink3resok: + # XDR definition: + # struct readlink3resok { + # post_op_attr symlink_attributes; + # nfspath3 data; + # }; + def __init__(self, symlink_attributes=None, data=None): + self.symlink_attributes = symlink_attributes + self.data = data + + def __getattr__(self, attr): + return getattr(self.symlink_attributes, attr) + + def __repr__(self): + out = [] + if self.symlink_attributes is not None: + out += ['symlink_attributes=%s' % repr(self.symlink_attributes)] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'readlink3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class readlink3res: + # XDR definition: + # union readlink3res switch(nfsstat3 status) { + # case NFS3_OK: + # readlink3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'readlink3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class read3args: + # XDR definition: + # struct read3args { + # nfs_fh3 file; + # uint64 offset; + # uint32 count; + # }; + def __init__(self, file=None, offset=None, count=None): + self.file = file + self.offset = offset + self.count = count + + def __getattr__(self, attr): + return getattr(self.file, attr) + + def __repr__(self): + out = [] + if self.file is not None: + out += ['file=%s' % repr(self.file)] + if self.offset is not None: + out += ['offset=%s' % repr(self.offset)] + if self.count is not None: + out += ['count=%s' % repr(self.count)] + return 'read3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class read3resok: + # XDR definition: + # struct read3resok { + # post_op_attr file_attributes; + # uint32 count; + # bool eof; + # opaque data<>; + # }; + def __init__(self, file_attributes=None, count=None, eof=None, data=None): + self.file_attributes = file_attributes + self.count = count + self.eof = eof + self.data = data + + def __getattr__(self, attr): + return getattr(self.file_attributes, attr) + + def __repr__(self): + out = [] + if self.file_attributes is not None: + out += ['file_attributes=%s' % repr(self.file_attributes)] + if self.count is not None: + out += ['count=%s' % repr(self.count)] + if self.eof is not None: + out += ['eof=%s' % repr(self.eof)] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'read3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class read3res: + # XDR definition: + # union read3res switch(nfsstat3 status) { + # case NFS3_OK: + # read3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'read3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class write3args: + # XDR definition: + # struct write3args { + # nfs_fh3 file; + # uint64 offset; + # uint32 count; + # stable_how stable; + # opaque data<>; + # }; + def __init__(self, file=None, offset=None, count=None, stable=None, data=None): + self.file = file + self.offset = offset + self.count = count + self.stable = stable + self.data = data + + def __getattr__(self, attr): + return getattr(self.file, attr) + + def __repr__(self): + out = [] + if self.file is not None: + out += ['file=%s' % repr(self.file)] + if self.offset is not None: + out += ['offset=%s' % repr(self.offset)] + if self.count is not None: + out += ['count=%s' % repr(self.count)] + if self.stable is not None: + out += ['stable=%s' % const.stable_how.get(self.stable, self.stable)] + if self.data is not None: + out += ['data=%s' % repr(self.data)] + return 'write3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class write3resok: + # XDR definition: + # struct write3resok { + # wcc_data file_wcc; + # uint32 count; + # stable_how committed; + # writeverf3 verf; + # }; + def __init__(self, file_wcc=None, count=None, committed=None, verf=None): + self.file_wcc = file_wcc + self.count = count + self.committed = committed + self.verf = verf + + def __getattr__(self, attr): + return getattr(self.file_wcc, attr) + + def __repr__(self): + out = [] + if self.file_wcc is not None: + out += ['file_wcc=%s' % repr(self.file_wcc)] + if self.count is not None: + out += ['count=%s' % repr(self.count)] + if self.committed is not None: + out += ['committed=%s' % const.stable_how.get(self.committed, self.committed)] + if self.verf is not None: + out += ['verf=%s' % repr(self.verf)] + return 'write3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class write3res: + # XDR definition: + # union write3res switch(nfsstat3 status) { + # case NFS3_OK: + # write3resok resok; + # default: + # wcc_data resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'write3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class createhow3: + # XDR definition: + # union createhow3 switch(createmode3 mode) { + # case UNCHECKED: + # case GUARDED: + # sattr3 obj_attributes; + # case EXCLUSIVE: + # createverf3 verf; + # }; + def __init__(self, mode=None, obj_attributes=None, verf=None): + self.mode = mode + self.obj_attributes = obj_attributes + self.verf = verf + + switch = property(lambda s: {const.UNCHECKED:s.obj_attributes,const.GUARDED:s.obj_attributes,const.EXCLUSIVE:s.verf,}[s.mode]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.mode is not None: + out += ['mode=%s' % const.createmode3.get(self.mode, self.mode)] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.verf is not None: + out += ['verf=%s' % repr(self.verf)] + return 'createhow3(%s)' % ', '.join(out) + __str__ = __repr__ + +class create3args: + # XDR definition: + # struct create3args { + # diropargs3 where; + # createhow3 how; + # }; + def __init__(self, where=None, how=None): + self.where = where + self.how = how + + def __repr__(self): + out = [] + if self.where is not None: + out += ['where=%s' % repr(self.where)] + if self.how is not None: + out += ['how=%s' % repr(self.how)] + return 'create3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class mkdir3args: + # XDR definition: + # struct mkdir3args { + # diropargs3 where; + # sattr3 attributes; + # }; + def __init__(self, where=None, attributes=None): + self.where = where + self.attributes = attributes + + def __repr__(self): + out = [] + if self.where is not None: + out += ['where=%s' % repr(self.where)] + if self.attributes is not None: + out += ['attributes=%s' % repr(self.attributes)] + return 'mkdir3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class symlinkdata3: + # XDR definition: + # struct symlinkdata3 { + # sattr3 symlink_attributes; + # nfspath3 symlink_data; + # }; + def __init__(self, symlink_attributes=None, symlink_data=None): + self.symlink_attributes = symlink_attributes + self.symlink_data = symlink_data + + def __getattr__(self, attr): + return getattr(self.symlink_attributes, attr) + + def __repr__(self): + out = [] + if self.symlink_attributes is not None: + out += ['symlink_attributes=%s' % repr(self.symlink_attributes)] + if self.symlink_data is not None: + out += ['symlink_data=%s' % repr(self.symlink_data)] + return 'symlinkdata3(%s)' % ', '.join(out) + __str__ = __repr__ + +class symlink3args: + # XDR definition: + # struct symlink3args { + # diropargs3 where; + # symlinkdata3 symlink; + # }; + def __init__(self, where=None, symlink=None): + self.where = where + self.symlink = symlink + + def __repr__(self): + out = [] + if self.where is not None: + out += ['where=%s' % repr(self.where)] + if self.symlink is not None: + out += ['symlink=%s' % repr(self.symlink)] + return 'symlink3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class devicedata3: + # XDR definition: + # struct devicedata3 { + # sattr3 dev_attributes; + # specdata3 spec; + # }; + def __init__(self, dev_attributes=None, spec=None): + self.dev_attributes = dev_attributes + self.spec = spec + + def __repr__(self): + out = [] + if self.dev_attributes is not None: + out += ['dev_attributes=%s' % repr(self.dev_attributes)] + if self.spec is not None: + out += ['spec=%s' % repr(self.spec)] + return 'devicedata3(%s)' % ', '.join(out) + __str__ = __repr__ + +class mknoddata3: + # XDR definition: + # union mknoddata3 switch(ftype3 type) { + # case NF3CHR: + # case NF3BLK: + # devicedata3 device; + # case NF3SOCK: + # case NF3FIFO: + # sattr3 pipe_attributes; + # default: + # void; + # }; + def __init__(self, type=None, device=None, pipe_attributes=None): + self.type = type + self.device = device + self.pipe_attributes = pipe_attributes + + switch = property(lambda s: {const.NF3CHR:s.device,const.NF3BLK:s.device,const.NF3SOCK:s.pipe_attributes,const.NF3FIFO:s.pipe_attributes,}.get(s.type, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.type is not None: + out += ['type=%s' % const.ftype3.get(self.type, self.type)] + if self.device is not None: + out += ['device=%s' % repr(self.device)] + if self.pipe_attributes is not None: + out += ['pipe_attributes=%s' % repr(self.pipe_attributes)] + return 'mknoddata3(%s)' % ', '.join(out) + __str__ = __repr__ + +class mknod3args: + # XDR definition: + # struct mknod3args { + # diropargs3 where; + # mknoddata3 what; + # }; + def __init__(self, where=None, what=None): + self.where = where + self.what = what + + def __repr__(self): + out = [] + if self.where is not None: + out += ['where=%s' % repr(self.where)] + if self.what is not None: + out += ['what=%s' % repr(self.what)] + return 'mknod3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class rename3args: + # XDR definition: + # struct rename3args { + # diropargs3 from_dir; + # diropargs3 to_dir; + # }; + def __init__(self, from_dir=None, to_dir=None): + self.from_dir = from_dir + self.to_dir = to_dir + + def __repr__(self): + out = [] + if self.from_dir is not None: + out += ['from_dir=%s' % repr(self.from_dir)] + if self.to_dir is not None: + out += ['to_dir=%s' % repr(self.to_dir)] + return 'rename3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class rename3wcc: + # XDR definition: + # struct rename3wcc { + # wcc_data fromdir_wcc; + # wcc_data todir_wcc; + # }; + def __init__(self, fromdir_wcc=None, todir_wcc=None): + self.fromdir_wcc = fromdir_wcc + self.todir_wcc = todir_wcc + + def __repr__(self): + out = [] + if self.fromdir_wcc is not None: + out += ['fromdir_wcc=%s' % repr(self.fromdir_wcc)] + if self.todir_wcc is not None: + out += ['todir_wcc=%s' % repr(self.todir_wcc)] + return 'rename3wcc(%s)' % ', '.join(out) + __str__ = __repr__ + +class rename3res: + # XDR definition: + # union rename3res switch(nfsstat3 status) { + # case -1: + # void; + # default: + # rename3wcc res; + # }; + def __init__(self, status=None, res=None): + self.status = status + self.res = res + + switch = property(lambda s: {-1:None,}.get(s.status, s.res)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.res is not None: + out += ['res=%s' % repr(self.res)] + return 'rename3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class link3args: + # XDR definition: + # struct link3args { + # nfs_fh3 file; + # diropargs3 link; + # }; + def __init__(self, file=None, link=None): + self.file = file + self.link = link + + def __repr__(self): + out = [] + if self.file is not None: + out += ['file=%s' % repr(self.file)] + if self.link is not None: + out += ['link=%s' % repr(self.link)] + return 'link3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class link3wcc: + # XDR definition: + # struct link3wcc { + # post_op_attr file_attributes; + # wcc_data linkdir_wcc; + # }; + def __init__(self, file_attributes=None, linkdir_wcc=None): + self.file_attributes = file_attributes + self.linkdir_wcc = linkdir_wcc + + def __repr__(self): + out = [] + if self.file_attributes is not None: + out += ['file_attributes=%s' % repr(self.file_attributes)] + if self.linkdir_wcc is not None: + out += ['linkdir_wcc=%s' % repr(self.linkdir_wcc)] + return 'link3wcc(%s)' % ', '.join(out) + __str__ = __repr__ + +class link3res: + # XDR definition: + # union link3res switch(nfsstat3 status) { + # case -1: + # void; + # default: + # link3wcc res; + # }; + def __init__(self, status=None, res=None): + self.status = status + self.res = res + + switch = property(lambda s: {-1:None,}.get(s.status, s.res)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.res is not None: + out += ['res=%s' % repr(self.res)] + return 'link3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class readdir3args: + # XDR definition: + # struct readdir3args { + # nfs_fh3 dir; + # uint64 cookie; + # cookieverf3 cookieverf; + # uint32 count; + # }; + def __init__(self, dir=None, cookie=None, cookieverf=None, count=None): + self.dir = dir + self.cookie = cookie + self.cookieverf = cookieverf + self.count = count + + def __getattr__(self, attr): + return getattr(self.dir, attr) + + def __repr__(self): + out = [] + if self.dir is not None: + out += ['dir=%s' % repr(self.dir)] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.cookieverf is not None: + out += ['cookieverf=%s' % repr(self.cookieverf)] + if self.count is not None: + out += ['count=%s' % repr(self.count)] + return 'readdir3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class entry3: + # XDR definition: + # struct entry3 { + # uint64 fileid; + # filename3 name; + # uint64 cookie; + # entry3 nextentry<1>; + # }; + def __init__(self, fileid=None, name=None, cookie=None, nextentry=None): + self.fileid = fileid + self.name = name + self.cookie = cookie + self.nextentry = nextentry + + def __repr__(self): + out = [] + if self.fileid is not None: + out += ['fileid=%s' % repr(self.fileid)] + if self.name is not None: + out += ['name=%s' % repr(self.name)] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.nextentry is not None: + out += ['nextentry=%s' % repr(self.nextentry)] + return 'entry3(%s)' % ', '.join(out) + __str__ = __repr__ + +class dirlist3: + # XDR definition: + # struct dirlist3 { + # entry3 entries<1>; + # bool eof; + # }; + def __init__(self, entries=None, eof=None): + self.entries = entries + self.eof = eof + + def __repr__(self): + out = [] + if self.entries is not None: + out += ['entries=%s' % repr(self.entries)] + if self.eof is not None: + out += ['eof=%s' % repr(self.eof)] + return 'dirlist3(%s)' % ', '.join(out) + __str__ = __repr__ + +class readdir3resok: + # XDR definition: + # struct readdir3resok { + # post_op_attr dir_attributes; + # cookieverf3 cookieverf; + # dirlist3 reply; + # }; + def __init__(self, dir_attributes=None, cookieverf=None, reply=None): + self.dir_attributes = dir_attributes + self.cookieverf = cookieverf + self.reply = reply + + def __repr__(self): + out = [] + if self.dir_attributes is not None: + out += ['dir_attributes=%s' % repr(self.dir_attributes)] + if self.cookieverf is not None: + out += ['cookieverf=%s' % repr(self.cookieverf)] + if self.reply is not None: + out += ['reply=%s' % repr(self.reply)] + return 'readdir3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class readdir3res: + # XDR definition: + # union readdir3res switch(nfsstat3 status) { + # case NFS3_OK: + # readdir3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'readdir3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class readdirplus3args: + # XDR definition: + # struct readdirplus3args { + # nfs_fh3 dir; + # uint64 cookie; + # cookieverf3 cookieverf; + # uint32 dircount; + # uint32 maxcount; + # }; + def __init__(self, dir=None, cookie=None, cookieverf=None, dircount=None, maxcount=None): + self.dir = dir + self.cookie = cookie + self.cookieverf = cookieverf + self.dircount = dircount + self.maxcount = maxcount + + def __getattr__(self, attr): + return getattr(self.dir, attr) + + def __repr__(self): + out = [] + if self.dir is not None: + out += ['dir=%s' % repr(self.dir)] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.cookieverf is not None: + out += ['cookieverf=%s' % repr(self.cookieverf)] + if self.dircount is not None: + out += ['dircount=%s' % repr(self.dircount)] + if self.maxcount is not None: + out += ['maxcount=%s' % repr(self.maxcount)] + return 'readdirplus3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class entryplus3: + # XDR definition: + # struct entryplus3 { + # uint64 fileid; + # filename3 name; + # uint64 cookie; + # post_op_attr name_attributes; + # post_op_fh3 name_handle; + # entryplus3 nextentry<1>; + # }; + def __init__(self, fileid=None, name=None, cookie=None, name_attributes=None, name_handle=None, nextentry=None): + self.fileid = fileid + self.name = name + self.cookie = cookie + self.name_attributes = name_attributes + self.name_handle = name_handle + self.nextentry = nextentry + + def __repr__(self): + out = [] + if self.fileid is not None: + out += ['fileid=%s' % repr(self.fileid)] + if self.name is not None: + out += ['name=%s' % repr(self.name)] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.name_attributes is not None: + out += ['name_attributes=%s' % repr(self.name_attributes)] + if self.name_handle is not None: + out += ['name_handle=%s' % repr(self.name_handle)] + if self.nextentry is not None: + out += ['nextentry=%s' % repr(self.nextentry)] + return 'entryplus3(%s)' % ', '.join(out) + __str__ = __repr__ + +class dirlistplus3: + # XDR definition: + # struct dirlistplus3 { + # entryplus3 entries<1>; + # bool eof; + # }; + def __init__(self, entries=None, eof=None): + self.entries = entries + self.eof = eof + + def __repr__(self): + out = [] + if self.entries is not None: + out += ['entries=%s' % repr(self.entries)] + if self.eof is not None: + out += ['eof=%s' % repr(self.eof)] + return 'dirlistplus3(%s)' % ', '.join(out) + __str__ = __repr__ + +class readdirplus3resok: + # XDR definition: + # struct readdirplus3resok { + # post_op_attr dir_attributes; + # cookieverf3 cookieverf; + # dirlistplus3 reply; + # }; + def __init__(self, dir_attributes=None, cookieverf=None, reply=None): + self.dir_attributes = dir_attributes + self.cookieverf = cookieverf + self.reply = reply + + def __repr__(self): + out = [] + if self.dir_attributes is not None: + out += ['dir_attributes=%s' % repr(self.dir_attributes)] + if self.cookieverf is not None: + out += ['cookieverf=%s' % repr(self.cookieverf)] + if self.reply is not None: + out += ['reply=%s' % repr(self.reply)] + return 'readdirplus3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class readdirplus3res: + # XDR definition: + # union readdirplus3res switch(nfsstat3 status) { + # case NFS3_OK: + # readdirplus3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'readdirplus3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class fsstat3resok: + # XDR definition: + # struct fsstat3resok { + # post_op_attr obj_attributes; + # uint64 tbytes; + # uint64 fbytes; + # uint64 abytes; + # uint64 tfiles; + # uint64 ffiles; + # uint64 afiles; + # uint32 invarsec; + # }; + def __init__(self, obj_attributes=None, tbytes=None, fbytes=None, abytes=None, tfiles=None, ffiles=None, afiles=None, invarsec=None): + self.obj_attributes = obj_attributes + self.tbytes = tbytes + self.fbytes = fbytes + self.abytes = abytes + self.tfiles = tfiles + self.ffiles = ffiles + self.afiles = afiles + self.invarsec = invarsec + + def __getattr__(self, attr): + return getattr(self.obj_attributes, attr) + + def __repr__(self): + out = [] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.tbytes is not None: + out += ['tbytes=%s' % repr(self.tbytes)] + if self.fbytes is not None: + out += ['fbytes=%s' % repr(self.fbytes)] + if self.abytes is not None: + out += ['abytes=%s' % repr(self.abytes)] + if self.tfiles is not None: + out += ['tfiles=%s' % repr(self.tfiles)] + if self.ffiles is not None: + out += ['ffiles=%s' % repr(self.ffiles)] + if self.afiles is not None: + out += ['afiles=%s' % repr(self.afiles)] + if self.invarsec is not None: + out += ['invarsec=%s' % repr(self.invarsec)] + return 'fsstat3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class fsstat3res: + # XDR definition: + # union fsstat3res switch(nfsstat3 status) { + # case NFS3_OK: + # fsstat3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'fsstat3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class fsinfo3resok: + # XDR definition: + # struct fsinfo3resok { + # post_op_attr obj_attributes; + # uint32 rtmax; + # uint32 rtpref; + # uint32 rtmult; + # uint32 wtmax; + # uint32 wtpref; + # uint32 wtmult; + # uint32 dtpref; + # uint64 maxfilesize; + # nfstime3 time_delta; + # uint32 properties; + # }; + def __init__(self, obj_attributes=None, rtmax=None, rtpref=None, rtmult=None, wtmax=None, wtpref=None, wtmult=None, dtpref=None, maxfilesize=None, time_delta=None, properties=None): + self.obj_attributes = obj_attributes + self.rtmax = rtmax + self.rtpref = rtpref + self.rtmult = rtmult + self.wtmax = wtmax + self.wtpref = wtpref + self.wtmult = wtmult + self.dtpref = dtpref + self.maxfilesize = maxfilesize + self.time_delta = time_delta + self.properties = properties + + def __repr__(self): + out = [] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.rtmax is not None: + out += ['rtmax=%s' % repr(self.rtmax)] + if self.rtpref is not None: + out += ['rtpref=%s' % repr(self.rtpref)] + if self.rtmult is not None: + out += ['rtmult=%s' % repr(self.rtmult)] + if self.wtmax is not None: + out += ['wtmax=%s' % repr(self.wtmax)] + if self.wtpref is not None: + out += ['wtpref=%s' % repr(self.wtpref)] + if self.wtmult is not None: + out += ['wtmult=%s' % repr(self.wtmult)] + if self.dtpref is not None: + out += ['dtpref=%s' % repr(self.dtpref)] + if self.maxfilesize is not None: + out += ['maxfilesize=%s' % repr(self.maxfilesize)] + if self.time_delta is not None: + out += ['time_delta=%s' % repr(self.time_delta)] + if self.properties is not None: + out += ['properties=%s' % repr(self.properties)] + return 'fsinfo3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class fsinfo3res: + # XDR definition: + # union fsinfo3res switch(nfsstat3 status) { + # case NFS3_OK: + # fsinfo3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'fsinfo3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class pathconf3resok: + # XDR definition: + # struct pathconf3resok { + # post_op_attr obj_attributes; + # uint32 linkmax; + # uint32 name_max; + # bool no_trunc; + # bool chown_restricted; + # bool case_insensitive; + # bool case_preserving; + # }; + def __init__(self, obj_attributes=None, linkmax=None, name_max=None, no_trunc=None, chown_restricted=None, case_insensitive=None, case_preserving=None): + self.obj_attributes = obj_attributes + self.linkmax = linkmax + self.name_max = name_max + self.no_trunc = no_trunc + self.chown_restricted = chown_restricted + self.case_insensitive = case_insensitive + self.case_preserving = case_preserving + + def __getattr__(self, attr): + return getattr(self.obj_attributes, attr) + + def __repr__(self): + out = [] + if self.obj_attributes is not None: + out += ['obj_attributes=%s' % repr(self.obj_attributes)] + if self.linkmax is not None: + out += ['linkmax=%s' % repr(self.linkmax)] + if self.name_max is not None: + out += ['name_max=%s' % repr(self.name_max)] + if self.no_trunc is not None: + out += ['no_trunc=%s' % repr(self.no_trunc)] + if self.chown_restricted is not None: + out += ['chown_restricted=%s' % repr(self.chown_restricted)] + if self.case_insensitive is not None: + out += ['case_insensitive=%s' % repr(self.case_insensitive)] + if self.case_preserving is not None: + out += ['case_preserving=%s' % repr(self.case_preserving)] + return 'pathconf3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class pathconf3res: + # XDR definition: + # union pathconf3res switch(nfsstat3 status) { + # case NFS3_OK: + # pathconf3resok resok; + # default: + # post_op_attr resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'pathconf3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class commit3args: + # XDR definition: + # struct commit3args { + # nfs_fh3 file; + # uint64 offset; + # uint32 count; + # }; + def __init__(self, file=None, offset=None, count=None): + self.file = file + self.offset = offset + self.count = count + + def __getattr__(self, attr): + return getattr(self.file, attr) + + def __repr__(self): + out = [] + if self.file is not None: + out += ['file=%s' % repr(self.file)] + if self.offset is not None: + out += ['offset=%s' % repr(self.offset)] + if self.count is not None: + out += ['count=%s' % repr(self.count)] + return 'commit3args(%s)' % ', '.join(out) + __str__ = __repr__ + +class commit3resok: + # XDR definition: + # struct commit3resok { + # wcc_data file_wcc; + # writeverf3 verf; + # }; + def __init__(self, file_wcc=None, verf=None): + self.file_wcc = file_wcc + self.verf = verf + + def __getattr__(self, attr): + return getattr(self.file_wcc, attr) + + def __repr__(self): + out = [] + if self.file_wcc is not None: + out += ['file_wcc=%s' % repr(self.file_wcc)] + if self.verf is not None: + out += ['verf=%s' % repr(self.verf)] + return 'commit3resok(%s)' % ', '.join(out) + __str__ = __repr__ + +class commit3res: + # XDR definition: + # union commit3res switch(nfsstat3 status) { + # case NFS3_OK: + # commit3resok resok; + # default: + # wcc_data resfail; + # }; + def __init__(self, status=None, resok=None, resfail=None): + self.status = status + self.resok = resok + self.resfail = resfail + + switch = property(lambda s: {const.NFS3_OK:s.resok,}.get(s.status, s.resfail)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.status is not None: + out += ['status=%s' % const.nfsstat3.get(self.status, self.status)] + if self.resok is not None: + out += ['resok=%s' % repr(self.resok)] + if self.resfail is not None: + out += ['resfail=%s' % repr(self.resfail)] + return 'commit3res(%s)' % ', '.join(out) + __str__ = __repr__ + +class setaclargs: + # XDR definition: + # struct setaclargs { + # diropargs3 dargs; + # write3args wargs; + # }; + def __init__(self, dargs=None, wargs=None): + self.dargs = dargs + self.wargs = wargs + + def __repr__(self): + out = [] + if self.dargs is not None: + out += ['dargs=%s' % repr(self.dargs)] + if self.wargs is not None: + out += ['wargs=%s' % repr(self.wargs)] + return 'setaclargs(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/nfs3/nfs3lib.py b/nfs3/lib/nfs3/nfs3lib.py new file mode 100755 index 0000000..d71eb93 --- /dev/null +++ b/nfs3/lib/nfs3/nfs3lib.py @@ -0,0 +1,487 @@ +#!/usr/bin/env python +# nfs3lib.py - NFS3_PROTOCOL library for python + +import rpc +from xdrlib import Error as XDRError +from nfs3_const import * +from nfs3_type import * +from nfs3_pack import * +import time +import struct +import socket +import sys + +AuthSys = rpc.SecAuthSys(0, 'jupiter', 103558, 100, []) + + +class NFS3Exception(rpc.RPCError): + pass + + +# An NFS procedure returned an error +class BadNFS3Res(NFS3Exception): + def __init__(self, errcode, msg=None): + self.errcode = errcode + if msg: + self.msg = msg + ': ' + else: + self.msg = '' + + def __str__(self): + return self.msg + "should return NFS3_OK, instead got %s" % \ + (nfsstat3[self.errcode]) + + +class NFS3Client(rpc.RPCClient): + def __init__(self, id, host='localhost', port=300, homedir=['pynfs'], + sec_list=[AuthSys], opts=None, sym_resend=False): + self.ipv6 = getattr(opts, "ipv6", False) + self.packer = NFS3Packer() + self.unpacker = NFS3Unpacker('') + self.homedir = homedir + self.id = id + self.opts = opts + # uselowport = True + uselowport = getattr(opts, "secure", False) + rpc.RPCClient.__init__(self, host, port, program=NFS_PROGRAM, + version=NFS_V3, sec_list=sec_list, uselowport=uselowport, ipv6=self.ipv6, + sym_resend=sym_resend) + self.server_address = (host, port) + + def nfs3_pack(self, procedure, data): + p = self.packer + + ### ToDo: refactor to use a dict ... should give better perf + if procedure == NFSPROC3_NULL: + pass + elif procedure == NFSPROC3_GETATTR: + p.pack_nfs_fh3(data) + elif procedure == NFSPROC3_SETATTR: + p.pack_setattr3args(data) + elif procedure == NFSPROC3_LOOKUP: + p.pack_diropargs3(data) + elif procedure == NFSPROC3_ACCESS: + p.pack_access3args(data) + elif procedure == NFSPROC3_READLINK: + p.pack_nfs_fh3(data) + elif procedure == NFSPROC3_READ: + p.pack_read3args(data) + elif procedure == NFSPROC3_WRITE: + p.pack_write3args(data) + elif procedure == NFSPROC3_CREATE: + p.pack_create3args(data) + elif procedure == NFSPROC3_MKDIR: + p.pack_mkdir3args(data) + elif procedure == NFSPROC3_SYMLINK: + p.pack_symlink3args(data) + elif procedure == NFSPROC3_MKNOD: + p.pack_mknod3args(data) + elif procedure == NFSPROC3_REMOVE: + p.pack_diropargs3(data) + elif procedure == NFSPROC3_RMDIR: + p.pack_diropargs3(data) + elif procedure == NFSPROC3_RENAME: + p.pack_rename3args(data) + elif procedure == NFSPROC3_LINK: + p.pack_link3args(data) + elif procedure == NFSPROC3_READDIR: + p.pack_readdir3args(data) + elif procedure == NFSPROC3_READDIRPLUS: + p.pack_readdirplus3args(data) + elif procedure == NFSPROC3_FSSTAT: + p.pack_nfs_fh3(data) + elif procedure == NFSPROC3_FSINFO: + p.pack_nfs_fh3(data) + elif procedure == NFSPROC3_PATHCONF: + p.pack_nfs_fh3(data) + elif procedure == NFSPROC3_COMMIT: + p.pack_commit3args(data) + else: + raise XDRError('bad switch=%s' % procedure) + + # XXX Fancy unpacking, into status, data, etc + def nfs3_unpack(self, procedure): + un_p = self.unpacker + + ### ToDo: refactor to use a dict ... should give better perf + if procedure == NFSPROC3_NULL: + return + elif procedure == NFSPROC3_GETATTR: + return un_p.unpack_getattr3res() + elif procedure == NFSPROC3_SETATTR: + return un_p.unpack_wccstat3() + elif procedure == NFSPROC3_LOOKUP: + return un_p.unpack_lookup3res() + elif procedure == NFSPROC3_ACCESS: + return un_p.unpack_access3res() + elif procedure == NFSPROC3_READLINK: + return un_p.unpack_readlink3res() + elif procedure == NFSPROC3_READ: + return un_p.unpack_read3res() + elif procedure == NFSPROC3_WRITE: + return un_p.unpack_write3res() + elif procedure == NFSPROC3_CREATE: + return un_p.unpack_diropres3() + elif procedure == NFSPROC3_MKDIR: + return un_p.unpack_diropres3() + elif procedure == NFSPROC3_SYMLINK: + return un_p.unpack_diropres3() + elif procedure == NFSPROC3_MKNOD: + return un_p.unpack_diropres3() + elif procedure == NFSPROC3_REMOVE: + return un_p.unpack_wccstat3() + elif procedure == NFSPROC3_RMDIR: + return un_p.unpack_wccstat3() + elif procedure == NFSPROC3_RENAME: + return un_p.unpack_rename3res() + elif procedure == NFSPROC3_LINK: + return un_p.unpack_link3res() + elif procedure == NFSPROC3_READDIR: + return un_p.unpack_readdir3res() + elif procedure == NFSPROC3_READDIRPLUS: + return un_p.unpack_readdirplus3res() + elif procedure == NFSPROC3_FSSTAT: + return un_p.unpack_fsstat3res() + elif procedure == NFSPROC3_FSINFO: + return un_p.unpack_fsinfo3res() + elif procedure == NFSPROC3_PATHCONF: + return un_p.unpack_pathconf3res() + elif procedure == NFSPROC3_COMMIT: + return un_p.unpack_commit3res() + else: + raise XDRError('bad switch=%s' % procedure) + + def nfs3_call(self, procedure, data=''): + # Pack Request + p = self.packer + un_p = self.unpacker + p.reset() + + self.nfs3_pack(procedure, data) + + # Make Call + res = self.call(procedure, p.get_buffer()) + + # Unpack Reply + un_p.reset(res) + res = self.nfs3_unpack(procedure) + un_p.done() + + # XXX Error checking? + return res + + """ + BASIC NFS3 OPERATIONS + """ + + def null(self): + return self.nfs3_call(NFSPROC3_NULL) + + def getattr(self, file_handle=None): + arg_list = nfs_fh3(file_handle) + return self.nfs3_call(NFSPROC3_GETATTR, arg_list) + + def setattr(self, file_handle=None, mode_set=0, mode_val=0o777, + uid_set=0, uid_val=None, gid_set=0, gid_val=None, + size_set=0, size_val=0, atime_set=0, atime_val=None, + mtime_set=0, mtime_val=None, + guard_check=False, guard_time=None): + if uid_val is None: + uid_val = self.opts.uid + if gid_val is None: + gid_val = self.opts.gid + curr_time = ("%s" % time.time()).split('.') + if atime_val is None: + atime_val = nfstime3(curr_time[0], curr_time[1]) + if mtime_val is None: + mtime_val = nfstime3(curr_time[0], curr_time[1]) + if guard_time is None: + guard_time = nfstime3(curr_time[0], curr_time[1]) + arg_list = setattr3args(nfs_fh3(file_handle), + sattr3( + set_uint32(mode_set, mode_val), + set_uint32(uid_set, uid_val), + set_uint32(gid_set, gid_val), + set_uint64(size_set, size_val), + set_time(atime_set, atime_val), + set_time(mtime_set, mtime_val) + ), + sattrguard3(guard_check, guard_time)) + return self.nfs3_call(NFSPROC3_SETATTR, arg_list) + + def lookup(self, dir_fh=None, name=None): + arg_list = diropargs3(nfs_fh3(dir_fh), name) + return self.nfs3_call(NFSPROC3_LOOKUP, arg_list) + + def access(self, file_handle=None, access=None): + arg_list = access3args(nfs_fh3(file_handle), access) + return self.nfs3_call(NFSPROC3_ACCESS, arg_list) + + def readlink(self, link_fh=None): + arg_list = nfs_fh3(link_fh) + return self.nfs3_call(NFSPROC3_READLINK, arg_list) + + def read(self, file_handle=None, offset=0, count=0): + arg_list = read3args(nfs_fh3(file_handle), offset, count) + return self.nfs3_call(NFSPROC3_READ, arg_list) + + def write(self, file_handle=None, offset=0, count=0, stable=None, + data=None): + arg_list = write3args(nfs_fh3(file_handle), offset, count, + stable, data) + return self.nfs3_call(NFSPROC3_WRITE, arg_list) + + def create(self, dir_fh=None, name=None, nfs3_mode=UNCHECKED, + file_mode_set=0, file_mode_val=0o777, uid_set=0, uid_val=None, + gid_set=0, gid_val=None, size_set=0, size_val=0, + atime_set=0, atime_val=None, mtime_set=0, mtime_val=None, + exclusive_verf=0): + ### ToDo: add input validation? + curr_time = ("%s" % time.time()).split('.') + if atime_val is None: + atime_val = nfstime3(curr_time[0], curr_time[1]) + if mtime_val is None: + mtime_val = nfstime3(curr_time[0], curr_time[1]) + if uid_val is None: + uid_val = self.opts.uid + if gid_val is None: + gid_val = self.opts.gid + + arg_list = create3args( + diropargs3(nfs_fh3(dir_fh), name), + createhow3(nfs3_mode, + sattr3( + set_uint32(file_mode_set, file_mode_val), + set_uint32(uid_set, uid_val), + set_uint32(gid_set, gid_val), + set_uint64(size_set, size_val), + set_time(atime_set, atime_val), + set_time(mtime_set, mtime_val) + ), + exclusive_verf + )) + return self.nfs3_call(NFSPROC3_CREATE, arg_list) + + def mkdir(self, parent_fh=None, name=None, + dir_mode_set=0, dir_mode_val=0o777, uid_set=0, uid_val=None, + gid_set=0, gid_val=None, size_set=0, size_val=0, + atime_set=0, atime_val=None, mtime_set=0, mtime_val=None): + ### ToDo: add input validation? + curr_time = ("%s" % time.time()).split('.') + if atime_val is None: + atime_val = nfstime3(curr_time[0], curr_time[1]) + if mtime_val is None: + mtime_val = nfstime3(curr_time[0], curr_time[1]) + if uid_val is None: + uid_val = self.opts.uid + if gid_val is None: + gid_val = self.opts.gid + arg_list = mkdir3args(diropargs3(nfs_fh3(parent_fh), name), + sattr3( + set_uint32(dir_mode_set, dir_mode_val), + set_uint32(uid_set, uid_val), + set_uint32(gid_set, gid_val), + set_uint64(size_set, size_val), + set_time(atime_set, atime_val), + set_time(mtime_set, mtime_val) + )) + return self.nfs3_call(NFSPROC3_MKDIR, arg_list) + + def symlink(self, dir_fh=None, link_name=None, + mode_set=0, mode_val=0o777, uid_set=0, uid_val=None, + gid_set=0, gid_val=None, size_set=0, size_val=0, + atime_set=0, atime_val=None, mtime_set=0, mtime_val=None, + data=None): + ### ToDo: add input validation? + curr_time = ("%s" % time.time()).split('.') + if atime_val is None: + atime_val = nfstime3(curr_time[0], curr_time[1]) + if mtime_val is None: + mtime_val = nfstime3(curr_time[0], curr_time[1]) + if uid_val is None: + uid_val = self.opts.uid + if gid_val is None: + gid_val = self.opts.gid + arg_list = symlink3args( + diropargs3(nfs_fh3(dir_fh), link_name), + symlinkdata3( + sattr3( + set_uint32(mode_set, mode_val), + set_uint32(uid_set, uid_val), + set_uint32(gid_set, gid_val), + set_uint64(size_set, size_val), + set_time(atime_set, atime_val), + set_time(mtime_set, mtime_val) + ), + data + )) + return self.nfs3_call(NFSPROC3_SYMLINK, arg_list) + + def mknod(self, dir_fh=None, name=None, type=None, + mode_set=0, mode_val=0o777, uid_set=0, uid_val=None, + gid_set=0, gid_val=None, size_set=0, size_val=0, + atime_set=0, atime_val=None, mtime_set=0, mtime_val=None): + curr_time = ("%s" % time.time()).split('.') + if atime_val is None: + atime_val = nfstime3(curr_time[0], curr_time[1]) + if mtime_val is None: + mtime_val = nfstime3(curr_time[0], curr_time[1]) + if uid_val is None: + uid_val = self.opts.uid + if gid_val is None: + gid_val = self.opts.gid + attr = sattr3( + set_uint32(mode_set, mode_val), + set_uint32(uid_set, uid_val), + set_uint32(gid_set, gid_val), + set_uint64(size_set, size_val), + set_time(atime_set, atime_val), + set_time(mtime_set, mtime_val) + ) + arg_list = mknod3args(diropargs3(nfs_fh3(dir_fh), name), + mknoddata3(type, devicedata3(attr, specdata3(1, 2)), attr)) + return self.nfs3_call(NFSPROC3_MKNOD, arg_list) + + def remove(self, dir_handle=None, file_name=None): + arg_list = diropargs3(nfs_fh3(dir_handle), file_name) + return self.nfs3_call(NFSPROC3_REMOVE, arg_list) + + def rmdir(self, parent_dir_handle=None, target_dir_name=None): + arg_list = diropargs3(nfs_fh3(parent_dir_handle), target_dir_name) + return self.nfs3_call(NFSPROC3_RMDIR, arg_list) + + def rename(self, old_parent_fh=None, old_file=None, new_parent_fh=None, + new_file=None): + arg_list = rename3args(diropargs3(nfs_fh3(old_parent_fh), old_file), + diropargs3(nfs_fh3(new_parent_fh), new_file)) + return self.nfs3_call(NFSPROC3_RENAME, arg_list) + + def link(self, target_file_fh=None, dir_fh=None, link_name=None): + arg_list = link3args(nfs_fh3(target_file_fh), diropargs3(nfs_fh3(dir_fh), link_name)) + return self.nfs3_call(NFSPROC3_LINK, arg_list) + + def readdir(self, dir_fh=None, cookie=0, cookieverf='0', count=0): + if type(cookieverf) is not str: + cookieverf = cookieverf.__str__() + arg_list = readdir3args(nfs_fh3(dir_fh), cookie, cookieverf, count) + return self.nfs3_call(NFSPROC3_READDIR, arg_list) + + def readdirplus(self, dir_fh=None, cookie=0, cookieverf='0', dircount=0, maxcount=0): + if type(cookieverf) is not str: + cookieverf = cookieverf.__str__() + arg_list = readdirplus3args(nfs_fh3(dir_fh), cookie, cookieverf, dircount, maxcount) + return self.nfs3_call(NFSPROC3_READDIRPLUS, arg_list) + + def fsstat(self, file_fh=None): + arg_list = nfs_fh3(file_fh) + return self.nfs3_call(NFSPROC3_FSSTAT, arg_list) + + def fsinfo(self, file_fh=None): + arg_list = nfs_fh3(file_fh) + return self.nfs3_call(NFSPROC3_FSINFO, arg_list) + + def pathconf(self, file_fh=None): + arg_list = nfs_fh3(file_fh) + return self.nfs3_call(NFSPROC3_PATHCONF, arg_list) + + def commit(self, file_fh=None, offset=0, count=0): + arg_list = commit3args(nfs_fh3(file_fh), offset, count) + return self.nfs3_call(NFSPROC3_COMMIT, arg_list) + + """ + UTILITY FUNCTIONS + """ + + # Verify a NFS3 call was successful, + # raise BadNFS3Res otherwise + def nfs3_check_result(self, res, msg=None): + if not res.status: + return + raise BadNFS3Res(res.status, msg) + + def do_readdir(self, dir_fh, cookie=0, cookieverf='0', maxcount=4096): + """ Since we may not get the whole directory listing in one readdir + request, loop until we do. For each request result, create a flat + list with objects. + """ + entries = [] + count = 0 + while 1: + count += 1 + res = self.readdir(dir_fh, cookie, cookieverf, maxcount) + self.nfs3_check_result(res, msg="READDIR response #%i" % count) + cookieverf = res.resok.cookieverf + reply = res.resok.reply + if not reply.entries: + if not reply.eof: + raise BadNFS3Res("READDIR had no entries") + else: + break + entry = reply.entries[0] + # Loop over all entries in result. + while 1: + entries.append(entry) + if not entry.nextentry: + break + entry = entry.nextentry[0] + if reply.eof: + break + cookie = entry.cookie + # Remove the entry lists so that the return value isn't + # exponentially large + for entry in entries: + entry.nextentry = None + return entries + + def do_readdirplus(self, dir_fh, cookie=0, cookieverf='0', dircount=512, maxcount=4096): + """ Since we may not get the whole directory listing in one readdirplus + request, loop until we do. For each request result, create a flat + list with objects. + """ + entries = [] + count = 0 + while 1: + count += 1 + res = self.readdirplus(dir_fh, cookie, cookieverf, dircount, maxcount) + self.nfs3_check_result(res, msg="READDIR response #%i" % count) + cookieverf = res.resok.cookieverf + reply = res.resok.reply + if not reply.entries: + if not reply.eof: + raise BadNFS3Res("READDIR had no entries") + else: + break + entry = reply.entries[0] + # Loop over all entries in result. + while 1: + entries.append(entry) + if not entry.nextentry: + break + entry = entry.nextentry[0] + if reply.eof: + break + cookie = entry.cookie + # Remove the entry lists so that the return value isn't + # exponentially large + for entry in entries: + entry.nextentry = None + return entries + + def clean_dir(self, dir_fh): + entries = self.do_readdir(dir_fh) + for e in entries: + # don't delete folders starting with '.' + # makes not only '.' and '..' safe, but hidden folders too + # e.name is bytes; e.name[0] would be an int in py3, so slice to keep it bytes + if e.name[:1] != b'.': + # add perms check to remove? if not, add try/catch? + res = self.rmdir(dir_fh, e.name) + if res.status == NFS3ERR_NOTEMPTY: + lookup_res = self.lookup(dir_fh, e.name) + if lookup_res.status == NFS3_OK: + self.clean_dir(lookup_res.object.data) + res = self.rmdir(dir_fh, e.name) + else: + if res.status == NFS3ERR_NOTDIR: + res = self.remove(dir_fh, e.name) + self.nfs3_check_result(res, "Attempted to remove %s" % repr(e.name)) diff --git a/nfs3/lib/nfs3/rpcb.x b/nfs3/lib/nfs3/rpcb.x new file mode 100644 index 0000000..b66a1b1 --- /dev/null +++ b/nfs3/lib/nfs3/rpcb.x @@ -0,0 +1,328 @@ +/* + * rpcb_prot.x + * rpcbind protocol, versions 3 and 4, in RPC Language + */ + +/* Port mapper protocol, taken from RFC 1057 + * Edited by Zack Kirsch, for consumption by pynfs + */ + struct mapping { + unsigned int prog; + unsigned int vers; + unsigned int prot; + unsigned int port; + }; + + const IPPROTO_TCP = 6; /* protocol number for TCP/IP */ + const IPPROTO_UDP = 17; /* protocol number for UDP/IP */ + + /* XXX ZACK Had to edit this structure */ + typedef struct { + mapping map; + pmaplist *next; + } pmaplist; + + struct call_args { + unsigned int prog; + unsigned int vers; + unsigned int proc; + opaque args<>; + }; + + struct call_result { + unsigned int port; + opaque res<>; + }; + +/* END port mapper */ + +/* + * rpcbind address for TCP/UDP + */ +const RPCB_PORT = 111; + +/* + * A mapping of (program, version, network ID) to address + * + * The network identifier (r_netid): + * This is a string that represents a local identification for a + * network. This is defined by a system administrator based on local + * conventions, and cannot be depended on to have the same value on + * every system. + */ +struct rpcb { + unsigned int r_prog; /* program number */ + unsigned int r_vers; /* version number */ + string r_netid<>; /* network id */ + string r_addr<>; /* universal address */ + string r_owner<>; /* owner of this service */ +}; + +struct rp__list { + rpcb rpcb_map; + rp__list *rpcb_next; /* XXX ZACK Removed struct */ +}; + +typedef rp__list *rpcblist_ptr; /* results of RPCBPROC_DUMP */ + + +/* + * Arguments of remote calls + */ +struct rpcb_rmtcallargs { + unsigned int prog; /* program number */ + unsigned int vers; /* version number */ + unsigned int proc; /* procedure number */ + opaque args<>; /* argument */ +}; + + +/* + * Results of the remote call + */ +struct rpcb_rmtcallres { + string addr<>; /* remote universal address */ + opaque results<>; /* result */ +}; + + +/* + * rpcb_entry contains a merged address of a service on a particular + * transport, plus associated netconfig information. A list of + * rpcb_entry items is returned by RPCBPROC_GETADDRLIST. The meanings + * and values used for the r_nc_* fields are given below. + * + * The network identifier (r_nc_netid): + + * This is a string that represents a local identification for a + * network. This is defined by a system administrator based on + * local conventions, and cannot be depended on to have the same + * value on every system. + * + * Transport semantics (r_nc_semantics): + * This represents the type of transport, and has the following values: + * NC_TPI_CLTS (1) Connectionless + * NC_TPI_COTS (2) Connection oriented + * NC_TPI_COTS_ORD (3) Connection oriented with graceful close + * NC_TPI_RAW (4) Raw transport + * + * Protocol family (r_nc_protofmly): + * This identifies the family to which the protocol belongs. The + * following values are defined: + * NC_NOPROTOFMLY "-" + * NC_LOOPBACK "loopback" + * NC_INET "inet" + * NC_IMPLINK "implink" + * NC_PUP "pup" + * NC_CHAOS "chaos" + * NC_NS "ns" + * NC_NBS "nbs" + * NC_ECMA "ecma" + * NC_DATAKIT "datakit" + * NC_CCITT "ccitt" + * NC_SNA "sna" + * NC_DECNET "decnet" + * NC_DLI "dli" + * NC_LAT "lat" + * NC_HYLINK "hylink" + * NC_APPLETALK "appletalk" + * NC_NIT "nit" + * NC_IEEE802 "ieee802" + * NC_OSI "osi" + * NC_X25 "x25" + * NC_OSINET "osinet" + * NC_GOSIP "gosip" + * + * Protocol name (r_nc_proto): + * This identifies a protocol within a family. The following are + * currently defined: + * NC_NOPROTO "-" + * NC_TCP "tcp" + * NC_UDP "udp" + * NC_ICMP "icmp" + */ +struct rpcb_entry { + string r_maddr<>; /* merged address of service */ + string r_nc_netid<>; /* netid field */ + unsigned int r_nc_semantics; /* semantics of transport */ + string r_nc_protofmly<>; /* protocol family */ + string r_nc_proto<>; /* protocol name */ +}; + +/* + * A list of addresses supported by a service. + */ +struct rpcb_entry_list { + rpcb_entry rpcb_entry_map; + rpcb_entry_list *rpcb_entry_next; /* XXX ZACK Removed struct */ +}; + +typedef rpcb_entry_list *rpcb_entry_list_ptr; + +/* + * rpcbind statistics + */ + +/* XXX ZACK +const rpcb_highproc_2 = RPCBPROC_CALLIT; +const rpcb_highproc_3 = RPCBPROC_TADDR2UADDR; +const rpcb_highproc_4 = RPCBPROC_GETSTAT; +*/ + +const RPCBSTAT_HIGHPROC = 13; /* # of procs in rpcbind V4 plus one */ +const RPCBVERS_STAT = 3; /* provide only for rpcbind V2, V3 and V4 */ +const RPCBVERS_4_STAT = 2; +const RPCBVERS_3_STAT = 1; +const RPCBVERS_2_STAT = 0; + +/* Link list of all the stats about getport and getaddr */ +struct rpcbs_addrlist { + unsigned int prog; + unsigned int vers; + int success; + int failure; + string netid<>; + rpcbs_addrlist *next; /* XXX ZACK Removed struct */ +}; + +/* Link list of all the stats about rmtcall */ +struct rpcbs_rmtcalllist { + unsigned int prog; + unsigned int vers; + unsigned int proc; + int success; + int failure; + int indirect; /* whether callit or indirect */ + string netid<>; + rpcbs_rmtcalllist *next; /* XXX ZACK Removed struct */ +}; + +typedef int rpcbs_proc[RPCBSTAT_HIGHPROC]; +typedef rpcbs_addrlist *rpcbs_addrlist_ptr; +typedef rpcbs_rmtcalllist *rpcbs_rmtcalllist_ptr; + +struct rpcb_stat { + rpcbs_proc info; + int setinfo; + int unsetinfo; + rpcbs_addrlist_ptr addrinfo; + rpcbs_rmtcalllist_ptr rmtinfo; +}; + +/* + * One rpcb_stat structure is returned for each version of rpcbind + * being monitored. + */ + +typedef rpcb_stat rpcb_stat_byvers[RPCBVERS_STAT]; + +/* + * netbuf structure, used to store the transport specific form of + * a universal transport address. + */ +struct netbuf { + unsigned int maxlen; + opaque buf<>; +}; + +/* XXX ZACK ADDED */ +typedef string astring<>; + +/* + * rpcbind procedures$a + * XXX ZACK: PMAP_VERS taken from portmap protocol + */ +program RPCBPROG { + version PMAP_VERS { + void + PMAPPROC_NULL(void) = 0; + + bool + PMAPPROC_SET(mapping) = 1; + + bool + PMAPPROC_UNSET(mapping) = 2; + + unsigned int + PMAPPROC_GETPORT(mapping) = 3; + + pmaplist + PMAPPROC_DUMP(void) = 4; + + call_result + PMAPPROC_CALLIT(call_args) = 5; + } = 2; + + version RPCBVERS { + bool + RPCBPROC3_SET(rpcb) = 1; + + bool + RPCBPROC3_UNSET(rpcb) = 2; + + astring + RPCBPROC3_GETADDR(rpcb) = 3; + + rpcblist_ptr + RPCBPROC3_DUMP(void) = 4; + + rpcb_rmtcallres + RPCBPROC3_CALLIT(rpcb_rmtcallargs) = 5; + + unsigned int + RPCBPROC3_GETTIME(void) = 6; + + netbuf + RPCBPROC3_UADDR2TADDR(foo) = 7; + + astring + RPCBPROC3_TADDR2UADDR(netbuf) = 8; + } = 3; + + version RPCBVERS4 { + bool + RPCBPROC_SET(rpcb) = 1; + + bool + RPCBPROC_UNSET(rpcb) = 2; + + astring + RPCBPROC_GETADDR(rpcb) = 3; + + rpcblist_ptr + RPCBPROC_DUMP(void) = 4; + + /* + * NOTE: RPCBPROC_BCAST has the same functionality as CALLIT; + * the new name is intended to indicate that this + * procedure should be used for broadcast RPC, and + * RPCBPROC_INDIRECT should be used for indirect calls. + */ + /* XXX Commented out + rpcb_rmtcallres + RPCBPROC_BCAST(rpcb_rmtcallargs) = RPCBPROC_CALLIT; + */ + + unsigned int + RPCBPROC_GETTIME(void) = 6; + + netbuf + RPCBPROC_UADDR2TADDR(astring) = 7; + + astring + RPCBPROC_TADDR2UADDR(netbuf) = 8; + + astring + RPCBPROC_GETVERSADDR(rpcb) = 9; + + rpcb_rmtcallres + RPCBPROC_INDIRECT(rpcb_rmtcallargs) = 10; + + rpcb_entry_list_ptr + RPCBPROC_GETADDRLIST(rpcb) = 11; + + rpcb_stat_byvers + RPCBPROC_GETSTAT(void) = 12; + } = 4; +} = 100000; + diff --git a/nfs3/lib/nfs3/rpcb_const.py b/nfs3/lib/nfs3/rpcb_const.py new file mode 100644 index 0000000..abe42c6 --- /dev/null +++ b/nfs3/lib/nfs3/rpcb_const.py @@ -0,0 +1,38 @@ +# Generated by rpcgen.py from rpcb.x on Wed Jun 24 11:38:48 2026 +PMAPPROC_NULL = 0 +PMAPPROC_SET = 1 +PMAPPROC_UNSET = 2 +PMAPPROC_GETPORT = 3 +PMAPPROC_DUMP = 4 +PMAPPROC_CALLIT = 5 +RPCBPROC3_SET = 1 +RPCBPROC3_UNSET = 2 +RPCBPROC3_GETADDR = 3 +RPCBPROC3_DUMP = 4 +RPCBPROC3_CALLIT = 5 +RPCBPROC3_GETTIME = 6 +RPCBPROC3_UADDR2TADDR = 7 +RPCBPROC3_TADDR2UADDR = 8 +RPCBPROC_SET = 1 +RPCBPROC_UNSET = 2 +RPCBPROC_GETADDR = 3 +RPCBPROC_DUMP = 4 +RPCBPROC_GETTIME = 6 +RPCBPROC_UADDR2TADDR = 7 +RPCBPROC_TADDR2UADDR = 8 +RPCBPROC_GETVERSADDR = 9 +RPCBPROC_INDIRECT = 10 +RPCBPROC_GETADDRLIST = 11 +RPCBPROC_GETSTAT = 12 +IPPROTO_TCP = 6 +IPPROTO_UDP = 17 +RPCB_PORT = 111 +RPCBSTAT_HIGHPROC = 13 +RPCBVERS_STAT = 3 +RPCBVERS_4_STAT = 2 +RPCBVERS_3_STAT = 1 +RPCBVERS_2_STAT = 0 +RPCBPROG = 100000 +PMAP_VERS = 2 +RPCBVERS = 3 +RPCBVERS4 = 4 diff --git a/nfs3/lib/nfs3/rpcb_pack.py b/nfs3/lib/nfs3/rpcb_pack.py new file mode 100644 index 0000000..fe9caf9 --- /dev/null +++ b/nfs3/lib/nfs3/rpcb_pack.py @@ -0,0 +1,524 @@ +# Generated by rpcgen.py from rpcb.x on Wed Jun 24 11:38:48 2026 +import rpcb_const as const +import rpcb_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class RPCBPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + def pack_mapping(self, data): + if hasattr(self, 'filter_mapping'): + data = getattr(self, 'filter_mapping')(data) + if data.prog is None: + raise TypeError('data.prog == None') + self.pack_uint(data.prog) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.prot is None: + raise TypeError('data.prot == None') + self.pack_uint(data.prot) + if data.port is None: + raise TypeError('data.port == None') + self.pack_uint(data.port) + + def pack_pmaplist(self, data): + if hasattr(self, 'filter_pmaplist'): + data = getattr(self, 'filter_pmaplist')(data) + if data.map is None: + raise TypeError('data.map == None') + self.pack_mapping(data.map) + if data.next is None: + raise TypeError('data.next == None') + if len(data.next) > 1 and self.check_array: + raise XDRError('array length too long for data.next') + self.pack_array(data.next, self.pack_pmaplist) + + def pack_call_args(self, data): + if hasattr(self, 'filter_call_args'): + data = getattr(self, 'filter_call_args')(data) + if data.prog is None: + raise TypeError('data.prog == None') + self.pack_uint(data.prog) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.proc is None: + raise TypeError('data.proc == None') + self.pack_uint(data.proc) + if data.args is None: + raise TypeError('data.args == None') + self.pack_opaque(data.args) + + def pack_call_result(self, data): + if hasattr(self, 'filter_call_result'): + data = getattr(self, 'filter_call_result')(data) + if data.port is None: + raise TypeError('data.port == None') + self.pack_uint(data.port) + if data.res is None: + raise TypeError('data.res == None') + self.pack_opaque(data.res) + + def pack_rpcb(self, data): + if hasattr(self, 'filter_rpcb'): + data = getattr(self, 'filter_rpcb')(data) + if data.r_prog is None: + raise TypeError('data.r_prog == None') + self.pack_uint(data.r_prog) + if data.r_vers is None: + raise TypeError('data.r_vers == None') + self.pack_uint(data.r_vers) + if data.r_netid is None: + raise TypeError('data.r_netid == None') + self.pack_string(data.r_netid) + if data.r_addr is None: + raise TypeError('data.r_addr == None') + self.pack_string(data.r_addr) + if data.r_owner is None: + raise TypeError('data.r_owner == None') + self.pack_string(data.r_owner) + + def pack_rp__list(self, data): + if hasattr(self, 'filter_rp__list'): + data = getattr(self, 'filter_rp__list')(data) + if data.rpcb_map is None: + raise TypeError('data.rpcb_map == None') + self.pack_rpcb(data.rpcb_map) + if data.rpcb_next is None: + raise TypeError('data.rpcb_next == None') + if len(data.rpcb_next) > 1 and self.check_array: + raise XDRError('array length too long for data.rpcb_next') + self.pack_array(data.rpcb_next, self.pack_rp__list) + + def pack_rpcblist_ptr(self, data): + if hasattr(self, 'filter_rpcblist_ptr'): + data = getattr(self, 'filter_rpcblist_ptr')(data) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + self.pack_array(data, self.pack_rp__list) + + def pack_rpcb_rmtcallargs(self, data): + if hasattr(self, 'filter_rpcb_rmtcallargs'): + data = getattr(self, 'filter_rpcb_rmtcallargs')(data) + if data.prog is None: + raise TypeError('data.prog == None') + self.pack_uint(data.prog) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.proc is None: + raise TypeError('data.proc == None') + self.pack_uint(data.proc) + if data.args is None: + raise TypeError('data.args == None') + self.pack_opaque(data.args) + + def pack_rpcb_rmtcallres(self, data): + if hasattr(self, 'filter_rpcb_rmtcallres'): + data = getattr(self, 'filter_rpcb_rmtcallres')(data) + if data.addr is None: + raise TypeError('data.addr == None') + self.pack_string(data.addr) + if data.results is None: + raise TypeError('data.results == None') + self.pack_opaque(data.results) + + def pack_rpcb_entry(self, data): + if hasattr(self, 'filter_rpcb_entry'): + data = getattr(self, 'filter_rpcb_entry')(data) + if data.r_maddr is None: + raise TypeError('data.r_maddr == None') + self.pack_string(data.r_maddr) + if data.r_nc_netid is None: + raise TypeError('data.r_nc_netid == None') + self.pack_string(data.r_nc_netid) + if data.r_nc_semantics is None: + raise TypeError('data.r_nc_semantics == None') + self.pack_uint(data.r_nc_semantics) + if data.r_nc_protofmly is None: + raise TypeError('data.r_nc_protofmly == None') + self.pack_string(data.r_nc_protofmly) + if data.r_nc_proto is None: + raise TypeError('data.r_nc_proto == None') + self.pack_string(data.r_nc_proto) + + def pack_rpcb_entry_list(self, data): + if hasattr(self, 'filter_rpcb_entry_list'): + data = getattr(self, 'filter_rpcb_entry_list')(data) + if data.rpcb_entry_map is None: + raise TypeError('data.rpcb_entry_map == None') + self.pack_rpcb_entry(data.rpcb_entry_map) + if data.rpcb_entry_next is None: + raise TypeError('data.rpcb_entry_next == None') + if len(data.rpcb_entry_next) > 1 and self.check_array: + raise XDRError('array length too long for data.rpcb_entry_next') + self.pack_array(data.rpcb_entry_next, self.pack_rpcb_entry_list) + + def pack_rpcb_entry_list_ptr(self, data): + if hasattr(self, 'filter_rpcb_entry_list_ptr'): + data = getattr(self, 'filter_rpcb_entry_list_ptr')(data) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + self.pack_array(data, self.pack_rpcb_entry_list) + + def pack_rpcbs_addrlist(self, data): + if hasattr(self, 'filter_rpcbs_addrlist'): + data = getattr(self, 'filter_rpcbs_addrlist')(data) + if data.prog is None: + raise TypeError('data.prog == None') + self.pack_uint(data.prog) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.success is None: + raise TypeError('data.success == None') + self.pack_int(data.success) + if data.failure is None: + raise TypeError('data.failure == None') + self.pack_int(data.failure) + if data.netid is None: + raise TypeError('data.netid == None') + self.pack_string(data.netid) + if data.next is None: + raise TypeError('data.next == None') + if len(data.next) > 1 and self.check_array: + raise XDRError('array length too long for data.next') + self.pack_array(data.next, self.pack_rpcbs_addrlist) + + def pack_rpcbs_rmtcalllist(self, data): + if hasattr(self, 'filter_rpcbs_rmtcalllist'): + data = getattr(self, 'filter_rpcbs_rmtcalllist')(data) + if data.prog is None: + raise TypeError('data.prog == None') + self.pack_uint(data.prog) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.proc is None: + raise TypeError('data.proc == None') + self.pack_uint(data.proc) + if data.success is None: + raise TypeError('data.success == None') + self.pack_int(data.success) + if data.failure is None: + raise TypeError('data.failure == None') + self.pack_int(data.failure) + if data.indirect is None: + raise TypeError('data.indirect == None') + self.pack_int(data.indirect) + if data.netid is None: + raise TypeError('data.netid == None') + self.pack_string(data.netid) + if data.next is None: + raise TypeError('data.next == None') + if len(data.next) > 1 and self.check_array: + raise XDRError('array length too long for data.next') + self.pack_array(data.next, self.pack_rpcbs_rmtcalllist) + + def pack_rpcbs_proc(self, data): + if hasattr(self, 'filter_rpcbs_proc'): + data = getattr(self, 'filter_rpcbs_proc')(data) + self.pack_farray(const.RPCBSTAT_HIGHPROC, data, self.pack_int) + + def pack_rpcbs_addrlist_ptr(self, data): + if hasattr(self, 'filter_rpcbs_addrlist_ptr'): + data = getattr(self, 'filter_rpcbs_addrlist_ptr')(data) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + self.pack_array(data, self.pack_rpcbs_addrlist) + + def pack_rpcbs_rmtcalllist_ptr(self, data): + if hasattr(self, 'filter_rpcbs_rmtcalllist_ptr'): + data = getattr(self, 'filter_rpcbs_rmtcalllist_ptr')(data) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + self.pack_array(data, self.pack_rpcbs_rmtcalllist) + + def pack_rpcb_stat(self, data): + if hasattr(self, 'filter_rpcb_stat'): + data = getattr(self, 'filter_rpcb_stat')(data) + if data.info is None: + raise TypeError('data.info == None') + self.pack_rpcbs_proc(data.info) + if data.setinfo is None: + raise TypeError('data.setinfo == None') + self.pack_int(data.setinfo) + if data.unsetinfo is None: + raise TypeError('data.unsetinfo == None') + self.pack_int(data.unsetinfo) + if data.addrinfo is None: + raise TypeError('data.addrinfo == None') + self.pack_rpcbs_addrlist_ptr(data.addrinfo) + if data.rmtinfo is None: + raise TypeError('data.rmtinfo == None') + self.pack_rpcbs_rmtcalllist_ptr(data.rmtinfo) + + def pack_rpcb_stat_byvers(self, data): + if hasattr(self, 'filter_rpcb_stat_byvers'): + data = getattr(self, 'filter_rpcb_stat_byvers')(data) + self.pack_farray(const.RPCBVERS_STAT, data, self.pack_rpcb_stat) + + def pack_netbuf(self, data): + if hasattr(self, 'filter_netbuf'): + data = getattr(self, 'filter_netbuf')(data) + if data.maxlen is None: + raise TypeError('data.maxlen == None') + self.pack_uint(data.maxlen) + if data.buf is None: + raise TypeError('data.buf == None') + self.pack_opaque(data.buf) + + def pack_astring(self, data): + if hasattr(self, 'filter_astring'): + data = getattr(self, 'filter_astring')(data) + self.pack_string(data) + +class RPCBUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + def unpack_mapping(self): + data = types.mapping() + data.prog = self.unpack_uint() + data.vers = self.unpack_uint() + data.prot = self.unpack_uint() + data.port = self.unpack_uint() + if hasattr(self, 'filter_mapping'): + data = getattr(self, 'filter_mapping')(data) + return data + + def unpack_pmaplist(self): + data = types.pmaplist() + data.map = self.unpack_mapping() + data.next = self.unpack_array(self.unpack_pmaplist) + if len(data.next) > 1 and self.check_array: + raise XDRError('array length too long for data.next') + if hasattr(self, 'filter_pmaplist'): + data = getattr(self, 'filter_pmaplist')(data) + return data + + def unpack_call_args(self): + data = types.call_args() + data.prog = self.unpack_uint() + data.vers = self.unpack_uint() + data.proc = self.unpack_uint() + data.args = self.unpack_opaque() + if hasattr(self, 'filter_call_args'): + data = getattr(self, 'filter_call_args')(data) + return data + + def unpack_call_result(self): + data = types.call_result() + data.port = self.unpack_uint() + data.res = self.unpack_opaque() + if hasattr(self, 'filter_call_result'): + data = getattr(self, 'filter_call_result')(data) + return data + + def unpack_rpcb(self): + data = types.rpcb() + data.r_prog = self.unpack_uint() + data.r_vers = self.unpack_uint() + data.r_netid = self.unpack_string() + data.r_addr = self.unpack_string() + data.r_owner = self.unpack_string() + if hasattr(self, 'filter_rpcb'): + data = getattr(self, 'filter_rpcb')(data) + return data + + def unpack_rp__list(self): + data = types.rp__list() + data.rpcb_map = self.unpack_rpcb() + data.rpcb_next = self.unpack_array(self.unpack_rp__list) + if len(data.rpcb_next) > 1 and self.check_array: + raise XDRError('array length too long for data.rpcb_next') + if hasattr(self, 'filter_rp__list'): + data = getattr(self, 'filter_rp__list')(data) + return data + + def unpack_rpcblist_ptr(self): + data = self.unpack_array(self.unpack_rp__list) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_rpcblist_ptr'): + data = getattr(self, 'filter_rpcblist_ptr')(data) + return data + + def unpack_rpcb_rmtcallargs(self): + data = types.rpcb_rmtcallargs() + data.prog = self.unpack_uint() + data.vers = self.unpack_uint() + data.proc = self.unpack_uint() + data.args = self.unpack_opaque() + if hasattr(self, 'filter_rpcb_rmtcallargs'): + data = getattr(self, 'filter_rpcb_rmtcallargs')(data) + return data + + def unpack_rpcb_rmtcallres(self): + data = types.rpcb_rmtcallres() + data.addr = self.unpack_string() + data.results = self.unpack_opaque() + if hasattr(self, 'filter_rpcb_rmtcallres'): + data = getattr(self, 'filter_rpcb_rmtcallres')(data) + return data + + def unpack_rpcb_entry(self): + data = types.rpcb_entry() + data.r_maddr = self.unpack_string() + data.r_nc_netid = self.unpack_string() + data.r_nc_semantics = self.unpack_uint() + data.r_nc_protofmly = self.unpack_string() + data.r_nc_proto = self.unpack_string() + if hasattr(self, 'filter_rpcb_entry'): + data = getattr(self, 'filter_rpcb_entry')(data) + return data + + def unpack_rpcb_entry_list(self): + data = types.rpcb_entry_list() + data.rpcb_entry_map = self.unpack_rpcb_entry() + data.rpcb_entry_next = self.unpack_array(self.unpack_rpcb_entry_list) + if len(data.rpcb_entry_next) > 1 and self.check_array: + raise XDRError('array length too long for data.rpcb_entry_next') + if hasattr(self, 'filter_rpcb_entry_list'): + data = getattr(self, 'filter_rpcb_entry_list')(data) + return data + + def unpack_rpcb_entry_list_ptr(self): + data = self.unpack_array(self.unpack_rpcb_entry_list) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_rpcb_entry_list_ptr'): + data = getattr(self, 'filter_rpcb_entry_list_ptr')(data) + return data + + def unpack_rpcbs_addrlist(self): + data = types.rpcbs_addrlist() + data.prog = self.unpack_uint() + data.vers = self.unpack_uint() + data.success = self.unpack_int() + data.failure = self.unpack_int() + data.netid = self.unpack_string() + data.next = self.unpack_array(self.unpack_rpcbs_addrlist) + if len(data.next) > 1 and self.check_array: + raise XDRError('array length too long for data.next') + if hasattr(self, 'filter_rpcbs_addrlist'): + data = getattr(self, 'filter_rpcbs_addrlist')(data) + return data + + def unpack_rpcbs_rmtcalllist(self): + data = types.rpcbs_rmtcalllist() + data.prog = self.unpack_uint() + data.vers = self.unpack_uint() + data.proc = self.unpack_uint() + data.success = self.unpack_int() + data.failure = self.unpack_int() + data.indirect = self.unpack_int() + data.netid = self.unpack_string() + data.next = self.unpack_array(self.unpack_rpcbs_rmtcalllist) + if len(data.next) > 1 and self.check_array: + raise XDRError('array length too long for data.next') + if hasattr(self, 'filter_rpcbs_rmtcalllist'): + data = getattr(self, 'filter_rpcbs_rmtcalllist')(data) + return data + + def unpack_rpcbs_proc(self): + data = self.unpack_farray(const.RPCBSTAT_HIGHPROC, self.unpack_int) + if hasattr(self, 'filter_rpcbs_proc'): + data = getattr(self, 'filter_rpcbs_proc')(data) + return data + + def unpack_rpcbs_addrlist_ptr(self): + data = self.unpack_array(self.unpack_rpcbs_addrlist) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_rpcbs_addrlist_ptr'): + data = getattr(self, 'filter_rpcbs_addrlist_ptr')(data) + return data + + def unpack_rpcbs_rmtcalllist_ptr(self): + data = self.unpack_array(self.unpack_rpcbs_rmtcalllist) + if len(data) > 1 and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_rpcbs_rmtcalllist_ptr'): + data = getattr(self, 'filter_rpcbs_rmtcalllist_ptr')(data) + return data + + def unpack_rpcb_stat(self): + data = types.rpcb_stat() + data.info = self.unpack_rpcbs_proc() + data.setinfo = self.unpack_int() + data.unsetinfo = self.unpack_int() + data.addrinfo = self.unpack_rpcbs_addrlist_ptr() + data.rmtinfo = self.unpack_rpcbs_rmtcalllist_ptr() + if hasattr(self, 'filter_rpcb_stat'): + data = getattr(self, 'filter_rpcb_stat')(data) + return data + + def unpack_rpcb_stat_byvers(self): + data = self.unpack_farray(const.RPCBVERS_STAT, self.unpack_rpcb_stat) + if hasattr(self, 'filter_rpcb_stat_byvers'): + data = getattr(self, 'filter_rpcb_stat_byvers')(data) + return data + + def unpack_netbuf(self): + data = types.netbuf() + data.maxlen = self.unpack_uint() + data.buf = self.unpack_opaque() + if hasattr(self, 'filter_netbuf'): + data = getattr(self, 'filter_netbuf')(data) + return data + + def unpack_astring(self): + data = self.unpack_string() + if hasattr(self, 'filter_astring'): + data = getattr(self, 'filter_astring')(data) + return data + diff --git a/nfs3/lib/nfs3/rpcb_type.py b/nfs3/lib/nfs3/rpcb_type.py new file mode 100644 index 0000000..1021d49 --- /dev/null +++ b/nfs3/lib/nfs3/rpcb_type.py @@ -0,0 +1,377 @@ +# Generated by rpcgen.py from rpcb.x on Wed Jun 24 11:38:48 2026 +import rpcb_const as const +class mapping: + # XDR definition: + # struct mapping { + # uint prog; + # uint vers; + # uint prot; + # uint port; + # }; + def __init__(self, prog=None, vers=None, prot=None, port=None): + self.prog = prog + self.vers = vers + self.prot = prot + self.port = port + + def __repr__(self): + out = [] + if self.prog is not None: + out += ['prog=%s' % repr(self.prog)] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.prot is not None: + out += ['prot=%s' % repr(self.prot)] + if self.port is not None: + out += ['port=%s' % repr(self.port)] + return 'mapping(%s)' % ', '.join(out) + __str__ = __repr__ + +class pmaplist: + # XDR definition: + # struct pmaplist { + # mapping map; + # pmaplist next<1>; + # }; + def __init__(self, map=None, next=None): + self.map = map + self.next = next + + def __getattr__(self, attr): + return getattr(self.map, attr) + + def __repr__(self): + out = [] + if self.map is not None: + out += ['map=%s' % repr(self.map)] + if self.next is not None: + out += ['next=%s' % repr(self.next)] + return 'pmaplist(%s)' % ', '.join(out) + __str__ = __repr__ + +class call_args: + # XDR definition: + # struct call_args { + # uint prog; + # uint vers; + # uint proc; + # opaque args<>; + # }; + def __init__(self, prog=None, vers=None, proc=None, args=None): + self.prog = prog + self.vers = vers + self.proc = proc + self.args = args + + def __repr__(self): + out = [] + if self.prog is not None: + out += ['prog=%s' % repr(self.prog)] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.proc is not None: + out += ['proc=%s' % repr(self.proc)] + if self.args is not None: + out += ['args=%s' % repr(self.args)] + return 'call_args(%s)' % ', '.join(out) + __str__ = __repr__ + +class call_result: + # XDR definition: + # struct call_result { + # uint port; + # opaque res<>; + # }; + def __init__(self, port=None, res=None): + self.port = port + self.res = res + + def __repr__(self): + out = [] + if self.port is not None: + out += ['port=%s' % repr(self.port)] + if self.res is not None: + out += ['res=%s' % repr(self.res)] + return 'call_result(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcb: + # XDR definition: + # struct rpcb { + # uint r_prog; + # uint r_vers; + # string r_netid<>; + # string r_addr<>; + # string r_owner<>; + # }; + def __init__(self, r_prog=None, r_vers=None, r_netid=None, r_addr=None, r_owner=None): + self.r_prog = r_prog + self.r_vers = r_vers + self.r_netid = r_netid + self.r_addr = r_addr + self.r_owner = r_owner + + def __repr__(self): + out = [] + if self.r_prog is not None: + out += ['r_prog=%s' % repr(self.r_prog)] + if self.r_vers is not None: + out += ['r_vers=%s' % repr(self.r_vers)] + if self.r_netid is not None: + out += ['r_netid=%s' % repr(self.r_netid)] + if self.r_addr is not None: + out += ['r_addr=%s' % repr(self.r_addr)] + if self.r_owner is not None: + out += ['r_owner=%s' % repr(self.r_owner)] + return 'rpcb(%s)' % ', '.join(out) + __str__ = __repr__ + +class rp__list: + # XDR definition: + # struct rp__list { + # rpcb rpcb_map; + # rp__list rpcb_next<1>; + # }; + def __init__(self, rpcb_map=None, rpcb_next=None): + self.rpcb_map = rpcb_map + self.rpcb_next = rpcb_next + + def __getattr__(self, attr): + return getattr(self.rpcb_map, attr) + + def __repr__(self): + out = [] + if self.rpcb_map is not None: + out += ['rpcb_map=%s' % repr(self.rpcb_map)] + if self.rpcb_next is not None: + out += ['rpcb_next=%s' % repr(self.rpcb_next)] + return 'rp__list(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcb_rmtcallargs: + # XDR definition: + # struct rpcb_rmtcallargs { + # uint prog; + # uint vers; + # uint proc; + # opaque args<>; + # }; + def __init__(self, prog=None, vers=None, proc=None, args=None): + self.prog = prog + self.vers = vers + self.proc = proc + self.args = args + + def __repr__(self): + out = [] + if self.prog is not None: + out += ['prog=%s' % repr(self.prog)] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.proc is not None: + out += ['proc=%s' % repr(self.proc)] + if self.args is not None: + out += ['args=%s' % repr(self.args)] + return 'rpcb_rmtcallargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcb_rmtcallres: + # XDR definition: + # struct rpcb_rmtcallres { + # string addr<>; + # opaque results<>; + # }; + def __init__(self, addr=None, results=None): + self.addr = addr + self.results = results + + def __repr__(self): + out = [] + if self.addr is not None: + out += ['addr=%s' % repr(self.addr)] + if self.results is not None: + out += ['results=%s' % repr(self.results)] + return 'rpcb_rmtcallres(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcb_entry: + # XDR definition: + # struct rpcb_entry { + # string r_maddr<>; + # string r_nc_netid<>; + # uint r_nc_semantics; + # string r_nc_protofmly<>; + # string r_nc_proto<>; + # }; + def __init__(self, r_maddr=None, r_nc_netid=None, r_nc_semantics=None, r_nc_protofmly=None, r_nc_proto=None): + self.r_maddr = r_maddr + self.r_nc_netid = r_nc_netid + self.r_nc_semantics = r_nc_semantics + self.r_nc_protofmly = r_nc_protofmly + self.r_nc_proto = r_nc_proto + + def __repr__(self): + out = [] + if self.r_maddr is not None: + out += ['r_maddr=%s' % repr(self.r_maddr)] + if self.r_nc_netid is not None: + out += ['r_nc_netid=%s' % repr(self.r_nc_netid)] + if self.r_nc_semantics is not None: + out += ['r_nc_semantics=%s' % repr(self.r_nc_semantics)] + if self.r_nc_protofmly is not None: + out += ['r_nc_protofmly=%s' % repr(self.r_nc_protofmly)] + if self.r_nc_proto is not None: + out += ['r_nc_proto=%s' % repr(self.r_nc_proto)] + return 'rpcb_entry(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcb_entry_list: + # XDR definition: + # struct rpcb_entry_list { + # rpcb_entry rpcb_entry_map; + # rpcb_entry_list rpcb_entry_next<1>; + # }; + def __init__(self, rpcb_entry_map=None, rpcb_entry_next=None): + self.rpcb_entry_map = rpcb_entry_map + self.rpcb_entry_next = rpcb_entry_next + + def __getattr__(self, attr): + return getattr(self.rpcb_entry_map, attr) + + def __repr__(self): + out = [] + if self.rpcb_entry_map is not None: + out += ['rpcb_entry_map=%s' % repr(self.rpcb_entry_map)] + if self.rpcb_entry_next is not None: + out += ['rpcb_entry_next=%s' % repr(self.rpcb_entry_next)] + return 'rpcb_entry_list(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcbs_addrlist: + # XDR definition: + # struct rpcbs_addrlist { + # uint prog; + # uint vers; + # int success; + # int failure; + # string netid<>; + # rpcbs_addrlist next<1>; + # }; + def __init__(self, prog=None, vers=None, success=None, failure=None, netid=None, next=None): + self.prog = prog + self.vers = vers + self.success = success + self.failure = failure + self.netid = netid + self.next = next + + def __repr__(self): + out = [] + if self.prog is not None: + out += ['prog=%s' % repr(self.prog)] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.success is not None: + out += ['success=%s' % repr(self.success)] + if self.failure is not None: + out += ['failure=%s' % repr(self.failure)] + if self.netid is not None: + out += ['netid=%s' % repr(self.netid)] + if self.next is not None: + out += ['next=%s' % repr(self.next)] + return 'rpcbs_addrlist(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcbs_rmtcalllist: + # XDR definition: + # struct rpcbs_rmtcalllist { + # uint prog; + # uint vers; + # uint proc; + # int success; + # int failure; + # int indirect; + # string netid<>; + # rpcbs_rmtcalllist next<1>; + # }; + def __init__(self, prog=None, vers=None, proc=None, success=None, failure=None, indirect=None, netid=None, next=None): + self.prog = prog + self.vers = vers + self.proc = proc + self.success = success + self.failure = failure + self.indirect = indirect + self.netid = netid + self.next = next + + def __repr__(self): + out = [] + if self.prog is not None: + out += ['prog=%s' % repr(self.prog)] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.proc is not None: + out += ['proc=%s' % repr(self.proc)] + if self.success is not None: + out += ['success=%s' % repr(self.success)] + if self.failure is not None: + out += ['failure=%s' % repr(self.failure)] + if self.indirect is not None: + out += ['indirect=%s' % repr(self.indirect)] + if self.netid is not None: + out += ['netid=%s' % repr(self.netid)] + if self.next is not None: + out += ['next=%s' % repr(self.next)] + return 'rpcbs_rmtcalllist(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpcb_stat: + # XDR definition: + # struct rpcb_stat { + # rpcbs_proc info; + # int setinfo; + # int unsetinfo; + # rpcbs_addrlist_ptr addrinfo; + # rpcbs_rmtcalllist_ptr rmtinfo; + # }; + def __init__(self, info=None, setinfo=None, unsetinfo=None, addrinfo=None, rmtinfo=None): + self.info = info + self.setinfo = setinfo + self.unsetinfo = unsetinfo + self.addrinfo = addrinfo + self.rmtinfo = rmtinfo + + def __repr__(self): + out = [] + if self.info is not None: + out += ['info=%s' % repr(self.info)] + if self.setinfo is not None: + out += ['setinfo=%s' % repr(self.setinfo)] + if self.unsetinfo is not None: + out += ['unsetinfo=%s' % repr(self.unsetinfo)] + if self.addrinfo is not None: + out += ['addrinfo=%s' % repr(self.addrinfo)] + if self.rmtinfo is not None: + out += ['rmtinfo=%s' % repr(self.rmtinfo)] + return 'rpcb_stat(%s)' % ', '.join(out) + __str__ = __repr__ + +class netbuf: + # XDR definition: + # struct netbuf { + # uint maxlen; + # opaque buf<>; + # }; + def __init__(self, maxlen=None, buf=None): + self.maxlen = maxlen + self.buf = buf + + def __repr__(self): + out = [] + if self.maxlen is not None: + out += ['maxlen=%s' % repr(self.maxlen)] + if self.buf is not None: + out += ['buf=%s' % repr(self.buf)] + return 'netbuf(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/nfs3/rpcblib.py b/nfs3/lib/nfs3/rpcblib.py new file mode 100644 index 0000000..6d8c0f7 --- /dev/null +++ b/nfs3/lib/nfs3/rpcblib.py @@ -0,0 +1,205 @@ +#!/usr/bin/env python +# rpcblib.py - RPCBIND and PORTMAP library for python + +# Implemented by hand by Zack Kirsch, but could be easily auto-generated + +import rpc +from xdrlib import Error as XDRError +from rpcb_const import * +from rpcb_type import * +from rpcb_pack import * +import time +import struct +import socket +import sys + +AuthSys = rpc.SecAuthSys(0,'jupiter',103558,100,[]) + +class RpcbException(rpc.RPCError): + pass + +class RpcbClient(rpc.RPCClient): + def __init__(self, id, host='localhost', port=RPCB_PORT, homedir=['pynfs'], + sec_list=[AuthSys], opts = None): + self.ipv6 = getattr(opts,"ipv6", False) + self.packer = RPCBPacker() + self.unpacker = RPCBUnpacker('') + self.homedir = homedir + self.id = id + self.opts = opts + self.uselowport = getattr(opts, "secure", False) + self.host = host + self.port = port + self.sec_list = sec_list + + def rpcb_pack(self, version, procedure, data): + if version == PMAP_VERS: + self.rpcb2_pack(procedure, data) + elif version == RPCBVERS: + self.rpcb3_pack(procedure, data) + elif version == RPCBVERS4: + self.rpcb4_pack(procedure, data) + else: + raise RpcbException('bad version = %s' % version) + + def rpcb2_pack(self, procedure, data): + p = self.packer + + if procedure == PMAPPROC_NULL: + pass + elif procedure == PMAPPROC_SET: + p.pack_mapping(data) + elif procedure == PMAPPROC_UNSET: + p.pack_mapping(data) + elif procedure == PMAPPROC_GETPORT: + p.pack_mapping(data) + elif procedure == PMAPPROC_DUMP: + pass + elif procedure == PMAPPROC_CALLIT: + p.pack_call_args(data) + else: + raise XDRError('bad switch=%s' % procedure) + + # XXX TODO + def rpcb3_pack(self, procedure, data): + p = self.packer + raise XDRError('unimplemented') + + def rpcb4_pack(self, procedure, data): + p = self.packer + + if procedure == const.RPCBPROC_SET: + p.pack_rpcb(data) + elif procedure == RPCBPROC_UNSET: + p.pack_rpcb(data) + elif procedure == RPCBPROC_GETADDR: + p.pack_rpcb(data) + elif procedure == RPCBPROC_DUMP: + pass + elif procedure == RPCBPROC_GETTIME: + pass + elif procedure == RPCBPROC_UADDR2TADDR: + p.pack_astring(data) + elif procedure == RPCBPROC_TADDR2UADDR: + p.pack_netbuf(data) + elif procedure == RPCBPROC_GETVERSADDR: + p.pack_rpcb(data) + elif procedure == RPCBPROC_INDIRECT: + p.pack_rpcb_rmtcallargs(data) + elif procedure == RPCBPROC_GETADDRLIST: + p.pack_rpcb(data) + elif procedure == RPCBPROC_GETSTAT: + pass + else: + raise XDRError('bad switch=%s' % procedure) + + def rpcb_unpack(self, version, procedure): + if version == PMAP_VERS: + return self.rpcb2_unpack(procedure) + elif version == RPCBVERS: + return self.rpcb3_unpack(procedure) + elif version == RPCBVERS4: + return self.rpcb4_unpack(procedure) + else: + raise RpcbException('bad version = %s' % version) + + def rpcb2_unpack(self, procedure): + un_p = self.unpacker + + if procedure == PMAPPROC_NULL: + pass + elif procedure == PMAPPROC_SET: + return un_p.unpack_bool() + elif procedure == PMAPPROC_UNSET: + return un_p.unpack_bool() + elif procedure == PMAPPROC_GETPORT: + return un_p.unpack_uint() + elif procedure == PMAPPROC_DUMP: + return un_p.unpack_pmaplist() + elif procedure == PMAPPROC_CALLIT: + return un_p.unpack_call_result() + else: + raise XDRError('bad switch=%s' % procedure) + + # XXX TODO + def rpcb3_unpack(self, procedure): + un_p = self.unpacker + raise XDRError('unimplemented') + + # XXX Fancy unpacking, into status, data, etc + def rpcb4_unpack(self, procedure): + un_p = self.unpacker + + if procedure == const.RPCBPROC_SET: + return un_p.unpack_bool() + elif procedure == RPCBPROC_UNSET: + return un_p.unpack_bool() + elif procedure == RPCBPROC_GETADDR: + return un_p.unpack_astring() + elif procedure == RPCBPROC_DUMP: + return un_p.unpack_rpcblist_ptr() + elif procedure == RPCBPROC_GETTIME: + return un_p.unpack_unsigned() + elif procedure == RPCBPROC_UADDR2TADDR: + return un_p.unpack_netbuf() + elif procedure == RPCBPROC_TADDR2UADDR: + return un_p.unpack_astring() + elif procedure == RPCBPROC_GETVERSADDR: + return un_p.unpack_astring() + elif procedure == RPCBPROC_INDIRECT: + return un_p.unpack_rpcb_rmtcallres() + elif procedure == RPCBPROC_GETADDRLIST: + return un_p.unpack_rpcb_entry_list_ptr() + elif procedure == RPCBPROC_GETSTAT: + return un_p.unpack_rpcb_stat_byvers() + else: + raise XDRError('bad switch=%s' % procedure) + + def rpcb_call(self, version, procedure, data=''): + rpc.RPCClient.__init__(self, self.host, self.port, program=RPCBPROG, + version=version, sec_list=self.sec_list, + uselowport=self.uselowport,ipv6=self.ipv6) + + # Pack Request + p = self.packer + un_p = self.unpacker + p.reset() + + self.rpcb_pack(version, procedure, data) + + # Make Call + res = self.call(procedure, p.get_buffer()) + + # Unpack Reply + un_p.reset(res) + res = self.rpcb_unpack(version, procedure) + un_p.done() + + # XXX Error checking? + return res + + """ + Basic RPCB ops + """ + # XXX Many are missing right now + + def rpcb2_getport(self, program, version, prot=IPPROTO_TCP, port=0): + data = types.mapping() + data.prog = program + data.vers = version + data.prot = prot + data.port = port + return self.rpcb_call(PMAP_VERS, PMAPPROC_GETPORT, data) + + def rpcb4_getaddr(self, program, version, netid="", addr="", owner=""): + data = types.rpcb() + data.r_prog = program + data.r_vers = version + data.r_netid = netid + data.r_addr = addr + data.r_owner = owner + return self.rpcb_call(RPCBVERS4, RPCBPROC_GETADDR, data) + + """ + Utility functions + """ diff --git a/nfs3/lib/nfs3/servertests/__init__.py b/nfs3/lib/nfs3/servertests/__init__.py new file mode 100644 index 0000000..22ac318 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/__init__.py @@ -0,0 +1,27 @@ +__all__ = [ "st_mount", + "st_null", + "st_create", + "st_mkdir", + "st_lookup", + "st_getattr", + "st_setattr", + "st_access", + "st_read", + "st_write", + "st_remove", + "st_rmdir", + "st_rename", + "st_link", + "st_readlink", + "st_symlink", + "st_readdir", + "st_readdirplus", + "st_fsinfo", + "st_fsstat", + "st_mknod", + "st_pathconf", + "st_commit", + "st_nlm", + "st_nsm", + "st_acl" + ] diff --git a/nfs3/lib/nfs3/servertests/environment.py b/nfs3/lib/nfs3/servertests/environment.py new file mode 100644 index 0000000..ee74d69 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/environment.py @@ -0,0 +1,240 @@ +# +# environment.py for NFSV3 +# +# Requires python 2.3 +# +# Written by Zack Kirsch +# + +import time +import testmod +import rpc +import os +import socket + +from nfs3.acllib import * +from nfs3.mountlib import * +from nfs3.mount_const import * +from nfs3.mount_type import * +from nfs3.nfs3lib import * +from nfs3.rpcblib import * +from nlm.nlm import * +from nsm.nsm import * + + +# NFSv3 environment, consists of: +# 1) RPCB to find protocol ports +# 2) MOUNT to get initial file handle +# 3) NFSv3 for testing +# 4) NLM for locking +# 5) NSM for monitoring hosts that are locking +# XXX Not all of these are actually implemented. + +class Environment(testmod.Environment): + def __init__(self, opts): + self.sec1, sec2, sec3 = self._get_security(opts) + rootsec = opts.flavor(0, opts.machinename, 0, 0, [0]) + + # Get protocol port + rpcb = RpcbClient('client1_pid%i' % os.getpid(), opts.server, + sec_list=[self.sec1], opts=opts) + mountport = rpcb.rpcb2_getport(MOUNT_PROGRAM, MOUNT_V3) + self.nfs3port = rpcb.rpcb2_getport(NFS_PROGRAM, NFS_V3) + + self.mc = MountClient('client1_pid%i' % os.getpid(), opts.server, + mountport, opts.path, sec_list=[self.sec1], opts=opts) + self.mc_v1 = MountClient('client2_pid%i' % os.getpid(), opts.server, + mountport, opts.path, sec_list=[self.sec1], opts=opts, mount_version=MOUNT_V1) + self.rootclient = MountClient('client1_pid%i' % os.getpid(), + opts.server, mountport, opts.path, sec_list=[rootsec], opts=opts) + + self.ipv6 = opts.ipv6 + + # Only initialize NLM client if specified on command line + # to work around BVT errors and the fact that this screws up the + # client's rpc.lockd + if opts.nlm and not opts.ipv6: + nlmport = rpcb.rpcb2_getport(NLM_PROG, NLM4_VERS) + self.nlm = NLM4Client('client1_pid%i' % os.getpid(), opts.server, + nlmport, opts.path[-1], sec_list=[self.sec1], opts=opts) + else: + self.nlm = None + + # NSM is similar + if opts.nsm: + rpcb_local = RpcbClient('client2_pid%i' % os.getpid(), "localhost", + sec_list=[self.sec1], opts=opts) + nsmport = rpcb.rpcb2_getport(SM_PROG, SM_VERS) + nsmport_local = rpcb_local.rpcb2_getport(SM_PROG, SM_VERS) + self.nsm = NSMClient('client1_pid%i' % os.getpid(), opts.server, + nsmport, sec_list=[self.sec1], opts=opts) + self.nsm_local = NSMClient('client2_pid%i' % os.getpid(), "localhost", + nsmport_local, sec_list=[self.sec1], opts=opts) + else: + self.nsm = None + + self.c1 = NFS3Client('client1_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[self.sec1], opts=opts) + self.c2 = NFS3Client('client2_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[sec2], opts=opts) + self.c3 = NFS3Client('client3_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[sec3], opts=opts) + self.c4_resend_sym = NFS3Client('client3_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[sec3], opts=opts, + sym_resend=True) + + self.acl_c2 = ACLClient('client1_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[self.sec1], opts=opts, + acl_version=NFS_ACL_V2) + self.acl_c3 = ACLClient('client1_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[self.sec1], opts=opts, + acl_version=NFS_ACL_V3) + self.acl_c4 = ACLClient('client1_pid%i' % os.getpid(), + opts.server, self.nfs3port, opts.path[-1], sec_list=[self.sec1], opts=opts, + acl_version=NFS_ACL_V4) + # if opts.secondserver: + # print "Using secondserver = %s" % opts.secondserver + # self.c1node2 = NFS4Client('client1_pid%i' % os.getpid(), + # opts.secondserver, opts.port, opts.path, + # sec_list=[self.sec1], opts=opts) + # self.c3node2 = NFS4Client('client3_pid%i' % os.getpid(), + # opts.secondserver, opts.port, opts.path, + # sec_list=[self.sec1], opts=opts) + # self.secondconns = [("clientid3", self.c3), ("clientid3-node2", self.c3node2)] + # self.secondconn = None + # else: + # self.secondconns = [("clientid3", self.c3)] + # #self.secondconns = [] + # self.secondconn = None + + self.longname = "a" * 512 + self.uid = 0 + self.gid = 0 + self.pid = os.getpid() + self.opts = opts + self.filedata = "This is the file test data." + self.linkdata = "/etc/X11" + + def _get_security(self, opts): + if opts.security == 'none': + return [opts.flavor(), opts.flavor()] + elif opts.security == 'sys': + sec1 = opts.flavor(0, opts.machinename, opts.uid, opts.gid, []) + sec2 = opts.flavor(0, opts.machinename, opts.uid + 1, opts.gid + 1, []) + sec3 = opts.flavor(0, opts.machinename, 10, 10, []) + return [sec1, sec2, sec3] + elif opts.security.startswith('krb5'): + sec1 = opts.flavor(opts.service) + sec2 = opts.flavor(opts.service) + sec3 = opts.flavor(opts.service) + return [sec1, sec2, sec3] + else: + raise RuntimeError('Bad security %s' % opts.security) + + """ + XXX These are defined for NFSv4, and could be defined for NFSv3 as + well. + """ + + def init(self): + """Run once before any test is run""" + c = self.c1 + if self.opts.maketree: + self._maketree() + if self.opts.noinit: + return + + # Make sure homedir is empty + c.clean_dir(homedir_fh(self.mc, c)) + + def _maketree(self): + # Make the homedir which will contain all test files for v3 tests + if self.opts.uid != 0 or self.opts.gid != 0: + print("WARNING: need root for privileged mount port") + + c = self.c1 + mnt_fh = self.mc.mount_getfh('/' + '/'.join(self.mc.opts.path[:-1])) + res = c.mkdir(mnt_fh, c.homedir, dir_mode_set=1, dir_mode_val=0o777) + checklist(res, [NFS3ERR_EXIST, NFS3_OK], + "Trying to create /%s," % '/'.join(self.opts.path)) + + def finish(self): + """Run once after all tests are run""" + if self.opts.nocleanup: + return + c = self.c1 + # Null call twice so it's easier to pick out in a pcap + c.null() + c.null() + self.c2.null() + self.c3.null() + + # Clean the homedir + c.clean_dir(homedir_fh(self.mc, c)) + + def startUp(self): + """Run before each test""" + self.c1.null() + + def sleep(self, sec, msg=''): + """Sleep for given seconds""" + print("Sleeping for %i seconds:" % sec, msg) + time.sleep(sec) + print("Woke up") + + def get_and_init_secondconn(self, firstconn, default_secondconn=None): + pass + + +######################################### +debug_fail = False + + +def check(res, stat=NFS3_OK, msg=None, warnlist=[]): + if res.status == stat: + if not (debug_fail and msg): + return + if type(stat) is str: + raise RuntimeError("You forgot to put 'msg=' in front of check's string arg") + desired = nfsstat3[stat] + received = nfsstat3[res.status] + if msg: + msg = "%s should return %s, instead got %s" % (msg, desired, received) + if res.status in warnlist: + raise testmod.WarningException(msg) + else: + raise testmod.FailureException(msg) + + +def checklist(res, statlist, msg=None): + if res.status in statlist: + return + statnames = [nfsstat3[stat] for stat in statlist] + desired = ' or '.join(statnames) + if not desired: + desired = 'one of ' + received = nfsstat3[res.status] + if msg: + failedop_name = msg + msg = "%s should return %s, instead got %s" % \ + (failedop_name, desired, received) + raise testmod.FailureException(msg) + + +def checkdict(expected, got, translate={}, failmsg=''): + pass + + +def checkvalid(cond, failmsg): + if not cond: raise testmod.FailureException(failmsg) + + +def homedir_fh(mc, c): + mnt_fh = mc.mount_getfh('/' + '/'.join(mc.opts.path[:-1])) + res = c.lookup(mnt_fh, c.homedir) + check(res, msg="Could not access homedir %s" % c.homedir) + return res.object.data + + +def get_invalid_utf8strings(): + pass diff --git a/nfs3/lib/nfs3/servertests/st_access.py b/nfs3/lib/nfs3/servertests/st_access.py new file mode 100755 index 0000000..007d2b7 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_access.py @@ -0,0 +1,41 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Access_Read(t, env): + """ Create a file, and check access permissions with ACCESS rpc + + FLAGS: nfsv3 access all + DEPEND: + CODE: ACCESS1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.access(test_file_fh, ACCESS3_READ) + + ### Verification Phase ### + check(res, msg="ACCESS - file %s" % test_file) + if res.resok.access != ACCESS3_READ: + t.fail_support(" ".join([ + "ACCESS - response: access bit mask [%s]" % res.resok.access, + "is not the correct value [%s]" % ACCESS3_READ])) + +### Add test cases for: +# ACCESS3_LOOKUP = 0x0002 +# ACCESS3_MODIFY = 0x0004 +# ACCESS3_EXTEND = 0x0008 +# ACCESS3_DELETE = 0x0010 +# ACCESS3_EXECUTE = 0x0020 +### ToDo: Add basic negative cases. Beef up coverage diff --git a/nfs3/lib/nfs3/servertests/st_acl.py b/nfs3/lib/nfs3/servertests/st_acl.py new file mode 100644 index 0000000..1381bd0 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_acl.py @@ -0,0 +1,84 @@ +from nfs3.nfs3_const import * +from nfs3.acl_const import * +from .environment import check, checkvalid, homedir_fh +from nfs3.nfs3lib import * +from nfs3.servertests import utils +from rpc import RPCError + + +def testNfs3ACL_BasicACLv3Operations(t, env): + """ Create a file with all _set bits = 0 + Failure is expected due to bug #76982 + + FLAGS: nfsv3 acl all + DEPEND: + CODE: POSIXACL01 + """ + ### Setup Phase ### + test_file = b"_file_1" + test_dir = t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=0, + file_mode_val=0o777) + test_file_fh = res.resok.obj.handle.data + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + env.acl_c3.acl_null() + env.acl_c3.acl_setacl(test_file_fh, [(0x1, 1000, 0o777), (0x2, 2000, 0o777), (0x3, 0, 0o777)], + mask=0x0) + res = env.acl_c3.acl_getacl(test_file_fh, 0x1) + print("###DEBUG - GETACL3 RESULTS:", res, "\n") + try: + res = env.acl_c3.acl_getxattrdir(test_file_fh, True) + except Exception as e: + print(("{}".format(e))) + + +def testNfs3ACL_BadACLOps(t, env): + """ Create a file with all _set bits = 0 + Failure is expected due to bug #76982 + + FLAGS: nfsv3 acl all + DEPEND: + CODE: POSIXACL02 + """ + ### Setup Phase ### + test_file = b"_file_1" + test_dir = t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=0, + file_mode_val=0o777) + test_file_fh = res.resok.obj.handle.data + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + + utils.assert_raises(RPCError, env.acl_c2.acl2_null) + utils.assert_raises(RPCError, env.acl_c2.acl2_setacl, test_file_fh, [(0x1, 1000, 0o777), (0x2, 2000, 0o777), + (0x3, 0, 0o777)], mask=0x0) + utils.assert_raises(RPCError, env.acl_c2.acl2_getacl, test_file_fh, 0x1) + utils.assert_raises(RPCError, env.acl_c2.acl2_getxattrdir, test_file_fh, True) + utils.assert_raises(RPCError, env.acl_c2.acl2_access, test_file_fh, 0o777) + utils.assert_raises(RPCError, env.acl_c2.acl2_getattr, test_file_fh) + + utils.assert_raises(RPCError, env.acl_c4.acl4_null) + utils.assert_raises(RPCError, env.acl_c4.acl4_setacl, test_file_fh, [(0x1, 1000, 0o777), (0x2, 2000, 0o777), + (0x3, 0, 0o777)], mask=0x0) + utils.assert_raises(RPCError, env.acl_c4.acl4_getacl, test_file_fh, 0x1) diff --git a/nfs3/lib/nfs3/servertests/st_commit.py b/nfs3/lib/nfs3/servertests/st_commit.py new file mode 100755 index 0000000..842371b --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_commit.py @@ -0,0 +1,114 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Commit(t, env): + """Commits changes to a file via the COMMIT rpc + + + FLAGS: nfsv3 commit all + DEPEND: + CODE: COMMIT1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + test_data = "Test String" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + res = env.c1.write(test_file_fh, offset=0, count=len(test_data), stable=FILE_SYNC, data=test_data) + check(res, msg="WRITE - file %s" % test_file) + + ### Execution Phase ### + res = env.c1.commit(test_file_fh) + + ### Verification Phase ### + check(res, msg="COMMIT of test file %s" % test_file) + +### Variations: +# Dir +# Different file types (nodes, symlinks, links, etc) +# No Permission +# Different permissions + +# XXX Once we have a "--long" option, we should bump up the datalen to 8GB +def testNfs3CommitLarge(t, env): + """ Tests COMMIT with large amounts of writes beforehand. Dial up the + datalen for an even larger filesize. + + FLAGS: nfsv3 commit all + DEPEND: + CODE: COMMIT2 + """ + ### Setup Phase ### + datalen = 512 * 1024 * 1024 + writesize = 512 * 1024 + test_data = "a" * writesize + + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + # WRITE in a loop until we write datalen + offset = 0 + wlen = writesize + while (offset < datalen): + if (datalen - offset < writesize): + wlen = datalen - offset + test_data = "a" * wlen + + print("Writing offset = %ld, length = %d" % (offset, wlen)) + res = env.c1.write(test_file_fh, offset=offset, count=wlen, stable=UNSTABLE, data=test_data) + check(res, msg="WRITE - file %s - offset=%ld - len=%d" % (test_file, offset, wlen)) + + offset = offset + wlen + + ### Execution Phase ### + offset = 0 + print("Committing %d data at offset %d" % (datalen, offset)) + res = env.c1.commit(test_file_fh, offset, datalen) + + ### Verification Phase ### + check(res, msg="COMMIT of test file %s" % test_file) + +def testNfs3CommitLargeValuesNoWrite(t, env): + """ Tests COMMIT with large values. No reason to write beforehand. This + repros bug 77753. + + FLAGS: nfsv3 commit all + DEPEND: + CODE: COMMIT3 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + offset = 3500000000 + datalen = 4000000000 + res = env.c1.commit(test_file_fh, offset, datalen) + check(res, msg="COMMIT of test file %s" % test_file) diff --git a/nfs3/lib/nfs3/servertests/st_create.py b/nfs3/lib/nfs3/servertests/st_create.py new file mode 100755 index 0000000..5223c7e --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_create.py @@ -0,0 +1,502 @@ +from nfs3.nfs3_const import * +from .environment import check, checkvalid, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Create_AllUnset(t, env): + """ Create a file with all _set bits = 0 + Failure is expected due to bug #76982 + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=0, + file_mode_val=0o777) + #print "###DEBUG - CREATE_ALLUNSET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + #test_file_fh = res.resok.obj.handle.data + +def testNfs3Create_FileModeSet(t, env): + """ Create a file with file_mode_set=1 + Use this as a work around until bug #76982 is closed + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE2 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.mode == 0o777, + "CREATE - file %s (mode=%d expected %d)" % + (test_file, res.attributes.mode, 0o777)) + +def testNfs3Create_FileModeReset(t, env): + """ Create a file with one mode and then recreate it with another mode. + Expect the first mode to remain. (Unchecked is the default creation type.) + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE2R + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o321) + check(res, msg="CREATE(1) - file %s" % test_file) + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o654) + check(res, msg="CREATE(2) - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.mode == 0o321, + "CREATE - file %s (mode=%d expected %d)" % + (test_file, res.attributes.mode, 0o321)) + +def testNfs3Create_SizeSet(t, env): + """ Create a file with file_mode_set=1 and Size + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE3 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, size_set=1, size_val=9876543210) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.size == 9876543210, \ + "CREATE - file %s (size=%d expected %d)" % \ + (test_file, res.attributes.size, 9876543210)) + +def testNfs3Create_SizeTruncate(t, env): + """ Create a file with a specified size and then truncate it with + another create. (Unchecked is the default creation type.) + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE3T + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, size_set=1, size_val=9876543210) + check(res, msg="CREATE(1) - file %s" % test_file) + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, size_set=1, size_val=1234567890) + check(res, msg="CREATE(2) - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.size == 9876543210, + "CREATE - file %s (size=%d expected %d)" % + (test_file, res.attributes.size, 9876543210)) + + ### Execution Phase 2 ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, size_set=1, size_val=0) + check(res, msg="CREATE(3) - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase 2 ### + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.size == 0, + "CREATE - file %s (size=%d expected %d)" % + (test_file, res.attributes.size, 0)) + +def testNfs3Create_MtimeSet(t, env): + """ Create a file with mtime_set=2 + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE4 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, mtime_set=2, mtime_val=nfstime3(1234, 5678)) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.mtime.seconds == 1234 and \ + res.attributes.mtime.nseconds == 5678, \ + "CREATE - file %s (mtime=%s expected %s)" \ + % (test_file, str(res.attributes.mtime), \ + str(nfstime3(1234, 5678)))) + + +def testNfs3Create_AtimeSet(t, env): + """ Create a file with atime_set=2 + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE5 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, + mtime_set=2, mtime_val=nfstime3(1234, 5678), + atime_set=2, atime_val=nfstime3(1234, 5678)) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + checkvalid(res.attributes.atime.seconds == 1234 and \ + res.attributes.atime.nseconds == 5678, \ + "CREATE - file %s (atime=%s expected %s)" \ + % (test_file, str(res.attributes.atime), \ + str(nfstime3(1234, 5678)))) + + +def testNfs3Create_UidRoot(t, env): + """ Create a file with uid_set=1 as root + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE6 + """ + ### Setup Phase ### + c = env.rootclient + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, + uid_set=1, uid_val=1234, + gid_set=1, gid_val=5678) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c1.getattr(test_file_fh) + # Allow maproot=nobody + checkvalid(res.attributes.uid == 1234 or \ + res.attributes.uid == 65534, \ + "CREATE - file %s (uid=%d expected %d)" \ + % (test_file, res.attributes.uid, 1234)) + checkvalid(res.attributes.gid == 5678 or \ + res.attributes.gid == 0, \ + "CREATE - file %s (gid=%d expected %d)" \ + % (test_file, res.attributes.gid, 5678)) + + +def testNfs3Create_UidAdmin(t, env): + """ Create a file with uid_set=1 as second user + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE7 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c3.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, + uid_set=1, uid_val=10, + gid_set=1, gid_val=10) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c3.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c3.getattr(test_file_fh) + note = "Is vfs.nfsrv.create_attributes_ids_enabled set?" + checkvalid(res.attributes.uid == 10, \ + "CREATE - file %s (uid=%d expected %d) %s" \ + % (test_file, res.attributes.uid, 10, note)) + checkvalid(res.attributes.gid == 10, \ + "CREATE - file %s (gid=%d expected %d) %s" \ + % (test_file, res.attributes.gid, 10, note)) + + +def testNfs3Create_UidAdminFail(t, env): + """ Create a file with uid_set=1 as second user + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE8 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c3.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777, + uid_set=1, uid_val=1234, + gid_set=1, gid_val=5678) + test_file_fh = res.resok.obj.handle.data + #print "###DEBUG - CREATE_FILEMODESET RESULTS:", res, "\n" + + ### Verification Phase ### + check(res, msg="CREATE - file %s" % test_file) + res = env.c3.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + res = env.c3.getattr(test_file_fh) + checkvalid(res.attributes.uid == 10, \ + "CREATE - file %s (uid=%d expected %d)" \ + % (test_file, res.attributes.uid, 10)) + checkvalid(res.attributes.gid == 10 or \ + res.attributes.gid == 0, \ + "CREATE - file %s (gid=%d expected %d)" \ + % (test_file, res.attributes.gid, 10)) + +def testNfs3Create_Exclusive(t, env): + """ Create a file in exclusive mode + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE9 + """ + ### Setup Phase ### + #verf = '12345678' + verf = str(0x3B9ACA01) + wrongverf = '87654321' + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.create(test_dir_fh, test_file, + nfs3_mode=EXCLUSIVE, exclusive_verf=verf) + check(res, msg="CREATE - file %s" % test_file) + fh1 = res.resok.obj.handle.data + + res = env.c1.lookup(test_dir_fh, test_file) + check(res, msg="LOOKUP - file %s" % test_file) + + # Create with same verifier should return same object + res = env.c1.create(test_dir_fh, test_file, + nfs3_mode=EXCLUSIVE, exclusive_verf=verf) + check(res, msg="2nd CREATE with correct verifier") + fh2 = res.resok.obj.handle.data + + # Compare file handles + checkvalid(fh1 == fh2, "Filehandle changed on 2nd exclusive create" + "(fh1 = %s, fh2 = %s)" % (fh1, fh2)) + + # Create the file again, should return an error + res = env.c1.create(test_dir_fh, test_file, + nfs3_mode=EXCLUSIVE, exclusive_verf=wrongverf) + check(res, NFS3ERR_EXIST, msg="3rd CREATE with wrong verifier") + + # Create with same verifier should return same object + res = env.c1.create(test_dir_fh, test_file, + nfs3_mode=EXCLUSIVE, exclusive_verf=verf) + check(res, msg="3rd CREATE with correct verifier") + fh2 = res.resok.obj.handle.data + + # Compare file handles + checkvalid(fh1 == fh2, "Filehandle changed on 3rd exclusive create" + "(fh1 = %s, fh2 = %s)" % (fh1, fh2)) + + +def testNfs3Create_ExclusiveSupported(t, env): + """ Test for support for exclusive mode + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE9a + """ + ### Setup Phase ### + verf = '12345678' + verf = str(0x3B9ACA01) + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + ### Execution Phase ### + res = env.c1.create(mnt_fh, test_file, + nfs3_mode=EXCLUSIVE, exclusive_verf=verf) + check(res, msg="CREATE - file %s" % test_file) + + +### ToDo: Add basic negative cases. Beef up coverage + +def testNfs3Create_EmptyFileName(t, env): + """ Create a file with all _set bits = 0 + Failure is expected due to bug #76982 + + FLAGS: nfsv3 create all + DEPEND: + CODE: CREATE10 + """ + ### Setup Phase ### + test_file = b"" + empty_dir = b"" + playground_file = t.name + "_f_1" + test_dir = t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - test dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + res = env.c1.create(test_dir_fh, playground_file, file_mode_set=0, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % playground_file) + test_file_fh = res.resok.obj.handle.data + + # CREATE + res = env.c1.create(test_dir_fh, test_file, file_mode_set=0, + file_mode_val=0o777) + check(res, NFS3ERR_ACCES, msg="CREATE - file %s" % test_file) + + #MKDIR + res = env.c1.mkdir(test_dir_fh, empty_dir, dir_mode_set=1, + dir_mode_val=0o777) + check(res, NFS3ERR_ACCES, msg="CREATE - dir %s" % empty_dir) + print("validated mkdir fails with NFS3ERR_ACCES") + + #LOOKUP file + dir + res = env.c1.lookup(test_dir_fh, empty_dir) + check(res, NFS3ERR_ACCES, msg="LOOKUP - dir %s" % empty_dir) + res = env.c1.lookup(test_dir_fh, test_file) + check(res, NFS3ERR_ACCES, msg="LOOKUP - file %s" % test_file) + print("validated lookup fails with NFS3ERR_ACCES") + + #MKNOD + res = env.c1.mknod(test_dir_fh, test_file, NF3FIFO, mode_set=1, mode_val=0o777) + check(res, NFS3ERR_ACCES, msg="MKNOD - file %s" % test_file) + print("validated mknod fails with NFS3ERR_ACCES") + + #RENAME + res = env.c1.rename(test_dir_fh, playground_file, test_dir_fh, test_file) + check(res, NFS3ERR_ACCES, msg="RENAME - file %s" % test_file) + print("validated rename fails with NFS3ERR_ACCES") + + #LINK + res = env.c1.link(test_file_fh, test_dir_fh, test_file) + check(res, NFS3ERR_ACCES, msg="LINK - file %s" % test_file) + print("validated link fails with NFS3ERR_ACCES") + + #REMOVE + res = env.c1.remove(test_dir_fh, test_file) + check(res, NFS3ERR_ACCES, msg="REMOVE - file %s" % test_file) + print("validated remove fails with NFS3ERR_ACCES") + + print("Cleaning-up") + res = env.c1.remove(test_dir_fh, playground_file) + check(res, msg="REMOVE should have succeeded %s " % playground_file) + res = env.c1.rmdir(mnt_fh, test_dir) + check(res, msg="RMDIR should have succeeded %s " % test_dir) diff --git a/nfs3/lib/nfs3/servertests/st_fsinfo.py b/nfs3/lib/nfs3/servertests/st_fsinfo.py new file mode 100755 index 0000000..b31a144 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_fsinfo.py @@ -0,0 +1,36 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3FSInfo(t, env): + """Retrieve the information of a file via the FSINFO rpc + + + FLAGS: nfsv3 fsinfo all + DEPEND: + CODE: FSINFO1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.fsinfo(test_file_fh) + + ### Verification Phase ###s + check(res, msg="FSINFO - file %s" % test_file) + +### Variations: +# Dir +# Different file types (nodes, symlinks, links, etc) +# No Read/lookup/search Permission +# Different permissions diff --git a/nfs3/lib/nfs3/servertests/st_fsstat.py b/nfs3/lib/nfs3/servertests/st_fsstat.py new file mode 100755 index 0000000..dd16ba5 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_fsstat.py @@ -0,0 +1,36 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3FSStat(t, env): + """Retrieve the statistics of a file via the FSSTAT rpc + + + FLAGS: nfsv3 fsstat all + DEPEND: + CODE: FSSTAT1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.fsstat(test_file_fh) + + ### Verification Phase ### + check(res, msg="FSSTAT of test file %s" % test_file) + +### Variations: +# Dir +# Different file types (nodes, symlinks, links, etc) +# No Read/lookup/search Permission +# Different permissions diff --git a/nfs3/lib/nfs3/servertests/st_getattr.py b/nfs3/lib/nfs3/servertests/st_getattr.py new file mode 100755 index 0000000..5a11490 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_getattr.py @@ -0,0 +1,31 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3GetAttr(t, env): + """ Get the attributes of a file via the GETATTR rpc + + + FLAGS: nfsv3 getattr all + DEPEND: + CODE: GATTR1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s " % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.getattr(test_file_fh) + + ### Verification Phase ### + check(res, msg="GETATTR - %s" % test_file) + #ToDo: beef up this check. Verify attribs match those set by create diff --git a/nfs3/lib/nfs3/servertests/st_link.py b/nfs3/lib/nfs3/servertests/st_link.py new file mode 100755 index 0000000..80cde73 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_link.py @@ -0,0 +1,40 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Link(t, env): + """ Create a hard-link to a file via LINK rpc + + + FLAGS: nfsv3 link all + DEPEND: + CODE: LINK1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + test_link=t.name + "_link_1" + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.link(test_file_fh, test_dir_fh, test_link) + + ### Verification Phase ### + check(res, msg="LINK - file %s" % test_file) + + +###### Other variations: +### Linking to dir +### Linking to read-only file +### Linking to a file that user doesn't have perms on +### Link over-writting existing file +### Link over-writting existing link +### etc. diff --git a/nfs3/lib/nfs3/servertests/st_lookup.py b/nfs3/lib/nfs3/servertests/st_lookup.py new file mode 100755 index 0000000..dc25c3d --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_lookup.py @@ -0,0 +1,36 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Lookup(t, env): + """ Get the handle for a file via the LOOKUP rpc + + + FLAGS: nfsv3 lookup all + DEPEND: + CODE: LOOKUP1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s " % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.lookup(test_dir_fh, test_file) + + check(res, msg="LOOKUP - file %s" % test_file) + if res.object.data != test_file_fh: + t.fail.support(" ".join([ + "LOOKUP - file handle returned [%s]" % res.object.data , + "is different than return of CREATE [%s]" % test_file_fh])) + + +### ToDo: Add basic negative cases ... follow pattern set up in nfs4. Beef up coverage diff --git a/nfs3/lib/nfs3/servertests/st_mkdir.py b/nfs3/lib/nfs3/servertests/st_mkdir.py new file mode 100755 index 0000000..37500e0 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_mkdir.py @@ -0,0 +1,27 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3MkDir(t, env): + """ Create a target dir and execute the LOOKUP RPC to verify success + + + FLAGS: nfsv3 mkdir all + DEPEND: + CODE: MKDIR1 + """ + ### Setup Phase ### + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + ### Execution Phase ### + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + + ### Verification Phase ### + check(res, msg="MKDIR - dir %s" % test_dir) + res = env.c1.lookup(mnt_fh, test_dir) + check(res, msg="LOOKUP - dir %s" % test_dir) + + +### ToDo: Add basic negative cases. Beef up coverage + diff --git a/nfs3/lib/nfs3/servertests/st_mknod.py b/nfs3/lib/nfs3/servertests/st_mknod.py new file mode 100755 index 0000000..3180ab2 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_mknod.py @@ -0,0 +1,45 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3MkNod(t, env): + """Create a special device file via the MKNOD rpc. + ... requires nfs root user to be mapped to root instead of nobody + + FLAGS: nfsv3 mknod all + DEPEND: + CODE: MKNOD1 + """ + ### Setup Phase ### + test_dir=t.name + "_dir_1" + type_list = [NF3BLK, NF3CHR, NF3SOCK, NF3FIFO] + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR of new test dir %s" % test_dir) + res = env.c1.lookup(mnt_fh, test_dir) + check(res, msg="LOOKUP of new dir %s" % test_dir) + test_dir_fh = res.object.data + + ### Execution Phase ### + for type in type_list: + # remove mode_set and _val args once bug #76982 is closed + test_file = "".join([t.name, "_", ftype3[type]]) + #test_file = "".join([mount_path, "/", test_dir, "/", t.name, "_", ftype3[type], "/"]) + res = env.c1.mknod(test_dir_fh, test_file, type, mode_set=1, mode_val=0o777) + #res = env.c1.mknod(mnt_fh, test_file, type, mode_set=1, mode_val=0777) + check(res, msg="MKNOD of test file %s" % test_file) + + ### Verification Phase ### + for type in type_list: + test_file = "".join([t.name, "_", ftype3[type]]) + res = env.c1.lookup(test_dir_fh, test_file) + #res = env.c1.lookup(mnt_fh, test_file) + check(res, msg="LOOKUP test file %s" % test_file) + + +### Variations: +# Overwrite existing file +# Overwrite existing dir +# Overwrite file without permissions +# Overwrite non-empty diff --git a/nfs3/lib/nfs3/servertests/st_mount.py b/nfs3/lib/nfs3/servertests/st_mount.py new file mode 100644 index 0000000..bd9265e --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_mount.py @@ -0,0 +1,102 @@ +from nfs3.mount_const import * +from .environment import check, checklist, checkdict, get_invalid_utf8strings +from nfs3.mountlib import * + +""" +MOUNT_V3 tests +""" + + +def testMountNull(t, env): + """ MOUNTPROC3_NULL + + FLAGS: mount nfsv3 + DEPEND: + CODE: MOUNT_NULL + """ + res = env.mc.mount_null() + print("MNT_NULL RESULTS:", res, "\n") + + +def testMountMnt(t, env): + """ MOUNTPROC3_MNT + + FLAGS: mount nfsv3 + DEPEND: MOUNT_NULL + CODE: MOUNT_MNT + """ + res = env.mc.mount_mnt('/' + '/'.join(env.mc.opts.path[:-1])) + print("MNT RESULTS:", res, "\n") + + +def testMountDump(t, env): + """ MOUNTPROC3_DUMP + + FLAGS: mount nfsv3 + DEPEND: MOUNT_NULL + CODE: MOUNT_DUMP + """ + res = env.mc.mount_dump() + print("DUMP results: ", res, "\n") + + +def testMountExport(t, env): + """ MOUNTPROC3_EXPORT + + FLAGS: mount nfsv3 + DEPEND: MOUNT_NULL + CODE: MOUNT_EXPORT + """ + c = env.rootclient + res = env.mc.mount_export() + print("EXPORT results: ", res, "\n") + + +""" +MOUNT_V1 tests +""" + + +def testMountNull_v1(t, env): + """ MOUNTPROC3_NULL + + FLAGS: mount nfsv3 + DEPEND: + CODE: MOUNT_NULL_V1 + """ + res = env.mc_v1.mount_null_v1() + print("MNT_NULL RESULTS:", res, "\n") + + +def testMountMnt_v1(t, env): + """ MOUNTPROC3_MNT + + FLAGS: mount nfsv3 + DEPEND: MOUNT_NULL + CODE: MOUNT_MNT_V1 + """ + res = env.mc_v1.mount_mnt_v1('/' + '/'.join(env.mc.opts.path[:-1])) + print("MNT RESULTS:", res, "\n") + + +def testMountDump_v1(t, env): + """ MOUNTPROC3_DUMP + + FLAGS: mount nfsv3 + DEPEND: MOUNT_NULL + CODE: MOUNT_DUMP_V1 + """ + res = env.mc_v1.mount_dump_v1() + print("DUMP results: ", res, "\n") + + +def testMountExport_v1(t, env): + """ MOUNTPROC3_EXPORT + + FLAGS: mount nfsv3 + DEPEND: MOUNT_NULL + CODE: MOUNT_EXPORT_V1 + """ + c = env.rootclient + res = env.mc_v1.mount_export_v1() + print("EXPORT results: ", res, "\n") diff --git a/nfs3/lib/nfs3/servertests/st_nlm.py b/nfs3/lib/nfs3/servertests/st_nlm.py new file mode 100644 index 0000000..b3b37cf --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_nlm.py @@ -0,0 +1,334 @@ +import random +from nfs3.nfs3_const import * +from nlm.nlm_prot_const import * +from .environment import homedir_fh +from nfs3.nfs3lib import * +from nlm.nlm import * + +def testNLM(t, env): + """ Just checks the NLM option + + FLAGS: nfsv3 nlm + DEPEND: + CODE: NLM0 + """ + + print("Checking for --nlm support:") + if env.ipv6: + t.fail(" IPv6 is not yet supported for the NLM tests.") + elif not env.nlm: + t.fail(" NLM not supported. You need to run with --nlm") + print(" Supported") + +def testNLM4Test(t, env): + """ Test the NLM TEST op. + It's a test to test TEST. + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLM1 + """ + ### Setup Phase ### + mnt_fh = homedir_fh(env.mc, env.c1) + + ### Execution Phase ### + res = env.nlm.test(nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + ,'cookie', True) + + ### Verification Phase ### + nlm4check(res.stat, msg="TEST") + +def testNLM4Lock(t,env): + """ Lock and unlock a directory. + + + FLAGS: nfsv3 nlm + DEPEND: NLM0 NLM1 + CODE: NLM2 + """ + ### Setup Phase ### + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + res = env.nlm.test(lock, 'cookie', True) + nlm4check(res.stat, msg="Initial TEST of unlocked dir") + + ### Execution Phase ### + res = env.nlm.lockk(lock, 'cookie', False, True, False, 1) + nlm4check(res.stat,msg="LOCK") + + ### Verification Phase ### + res = env.nlm.test(lock, 'cookie', True) + nlm4check(res.stat, msg="TEST of previously locked dir") + + lock2 = nlm4_lock(t.name + 'bad', mnt_fh, 'owner', env.pid, 0, 1024) + res = env.nlm.test(lock2, 'badcookie', True) + nlm4check(res.stat, msg="TEST of previously locked dir with bad creds", stat=NLM4_DENIED) + + res = env.nlm.unlock(lock, 'cookie') + nlm4check(res.stat,msg="UNLOCK") + + res = env.nlm.test(lock, 'cookie', True) + nlm4check(res.stat, msg="Final TEST of unlocked dir") + + +def testNLM4Cancel(t, env): + """ Send LOCK and then CANCEL RPC. + + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLMCANCEL1 + """ + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + res = env.nlm.lockk(lock, 'cookie', True) + lock = env.nlm.cancel(lock, netobj_cookie='cookie123', block=True, exclusive=True) + + +def testNLM4LoopTestExclusive(t,env): + """ Loop, sending NLM4TEST(Exclusive) messages. This is to find a specific + LK bug (related to SAS escalation bug 85961). + + To run, use multiple clients to run this test against multiple nodes. + + This test should be SAFE to run alongside itself or NLMLOOP2. + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLMLOOP1 + """ + + failed = False + + for i in range(10000): + # Do an EXCLUSIVE Test + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + res = env.nlm.test(lock, 'cookie', True) + if res.stat.stat != NLM4_GRANTED: + print("(%d) res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + if failed: + t.fail("FAILED TestExclusive test") + +def testNLM4LoopTestExclusive2(t,env): + """ Loop, sending NLM4TEST(Exclusive) messages. This is to find a specific + LK bug (related to SAS escalation bug 85961). + + To run, use multiple clients to run this test against multiple nodes. + + This test should be SAFE to run alongside itself or NLMLOOP1 or + NLMLOOPLOCK2. + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLMLOOP2 + """ + + failed = False + count = 0 + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + + for i in range(10000): + # Do an EXCLUSIVE Test + res = env.nlm.test(lock, 'cookie', True) + if res.stat.stat != NLM4_GRANTED: + count = count + 1 + if res.holder.exclusive: + print("(%d) res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + if count > 0: + print("Got %d shared BLOCKED messages (which may be a bug " \ + "depending on what other tests are running)" % (count)) + + if failed: + t.fail("FAILED TestExclusive test") + +def testNLM4LoopLocks(t,env): + """ Loop, sending NLM4LOCK(Shared) and NLM4LOCK(Exclusive) messages. In + Posix, a particular locker can own both a shared and an exclusive. + + This test is NOT SAFE to run concurrently with other tests. + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLMLOOPLOCK1 + """ + + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + failed = False + + for i in range(10000): + # Do a SHARED lock + res = env.nlm.lockk(lock, 'cookie', True, False) + if res.stat.stat != NLM4_GRANTED: + print("(%d) res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + res = env.nlm.lockk(lock, 'cookie', True, True) + if res.stat.stat != NLM4_GRANTED: + print("(%d) res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + + for i in range(10000): + # Unlock SHARED locks + res = env.nlm.unlock(lock, 'cookie') + nlm4check(res.stat, msg="UNLOCK") + + if failed: + t.fail("FAILED TestSharedLock test") + +def testNLM4LoopLockAndTest(t,env): + """ Loop, sending NLM4LOCK(Shared) and NLM4TEST(Exclusive) messages. + + This is to find a specific LK bug (related to SAS escalation bug 85961) + + To run, use multiple clients to run this test against multiple nodes. + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLMLOOPLOCK2 + """ + + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, t.name, env.pid, 0, 1024) + testlock = nlm4_lock(t.name, mnt_fh, t.name, env.pid + 1, 0, 1024) + #lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + failed = False + te_count = 0 + blocked_count = 0 + + for i in range(10000): + # Do a SHARED lock, alternating blocked and not + if i % 2 == 0: + blocked = False + else: + blocked = True + + res = env.nlm.lockk(lock, 'cookie', blocked, False) + if res.stat.stat != NLM4_GRANTED: + if res.stat.stat == NLM4_BLOCKED: + blocked_count = blocked_count + 1 + else: + print("(%d) LOCK_SHARED: res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + # TEST for shared, should succeed + res = env.nlm.test(testlock, 'cookie', False) + if res.stat.stat != NLM4_GRANTED: + print("(%d) TEST_SHARED: res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + # TEST for exclusive, should fail + res = env.nlm.test(testlock, 'cookie', True) + if res.stat.stat == NLM4_GRANTED: + te_count = te_count + 1 + print("(%d) TEST_EXCLUSIVE: res.stat = GRANTED") + failed = True + elif res.holder.exclusive: + print("(%d) TEST_EXCLUSIVE: res.stat = %s" % (i, nlm4_stats[res.stat.stat])) + print(res) + failed = True + + # Unlock SHARED locks + res = env.nlm.unlock(lock, 'cookie') + nlm4check(res.stat, msg="UNLOCK") + + if te_count > 0: + print("%d TEST_EXCLUSIVEs returned GRANTED and should have failed!" % te_count) + if blocked_count > 0: + print("%d LOCK_SHARED returned BLOCKED" % blocked_count) + + if failed: + t.fail("FAILED TestSharedLock test") + +# XXX FIXME lock_msg() doesn't seem to work if you pass in "True" for blocking. +# It just times out. +def testNLM4LockAsync(t,env): + """ Asynchronously lock and unlock + + FLAGS: nsv3 nlm + DEPEND: NLM0 + CODE: NLM3 + """ + + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + event = threading.Event() + + env.nlm.lock_msg(lock, 'cookie', False, True, False, 1, None, event) + if event.wait(10.0): + raise FailureException("NLM Async lock request timed out!") + else: + res = env.nlm.cb_server.get_cb_res('cookie') + if res: + nlm4check(res.stat, msg="Async LOCK") + else: + raise FailureException("NLM Async lock request timed out!") + + env.nlm.unlock_msg(lock, 'cookie', None, event) + if event.wait(10.0): + raise FailureException("NLM Async unlock request timed out!") + else: + res = env.nlm.cb_server.get_cb_res('cookie') + if res: + nlm4check(res.stat, msg="Async UNLOCK") + else: + raise FailureException("NLM Async lock request timed out!") + +# XXX TODO This mucks up the client because it opens and uses ALL reserved +# ports! After one run, you'll get: +# RPCError: MSG_DENIED: AUTH_ERROR: AUTH_TOOWEAK +# Maybe there is a way to reuse ports or close them properly +def testNLMathon(t, env): + """ NLM it up! + + FLAGS: nfsv3 nlm + DEPEND: NLM0 + CODE: NLM4 + """ + print("Running NLM Stress...") + mnt_fh = homedir_fh(env.mc, env.c1) + lock = nlm4_lock(t.name, mnt_fh, 'owner', env.pid, 0, 1024) + threads = [] + for i in range(0,1000): + threads.append(threading.Thread(target=runRandomProc,args=(lock,i,env))) + threads[i].start() + for i in range(0,1000): + threads[i].join() + +def runRandomProc(lock, n, env): + random.seed() + proc = random.randint(0, 12) + if proc >= 5: + proc += 1 #skip GRANTED + if proc >= 10: + proc += 6 #skip callbacks + if proc == 0: + env.nlm.nlm4_call(NLMPROC4_NULL, '') + elif proc <= 9: + functs = {1:env.nlm.test,2:env.nlm.lockk,3:env.nlm.unlock, + 4:env.nlm.cancel, 6:env.nlm.test_msg,7:env.nlm.lock_msg, + 8:env.nlm.unlock_msg,9:env.nlm.cancel_msg} + if proc < 5: + res = functs[proc](lock, netobj_cookie="cookie"+str(n)) + #print "%i: %s" % (n, res.stat) + elif proc < 10: + event = threading.Event() + functs[proc](lock, netobj_cookie="cookie%i"%n,cb_event=event) + event.wait(10) + res = env.nlm.cb_server.get_cb_res("cookie%i"%n) + #if(res): + # print "%i: %s" % (n,res.stat) + diff --git a/nfs3/lib/nfs3/servertests/st_nsm.py b/nfs3/lib/nfs3/servertests/st_nsm.py new file mode 100644 index 0000000..61aec1a --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_nsm.py @@ -0,0 +1,96 @@ +from nsm.nsm_const import * +from nsm.nsm import * + +def testNSM(t, env): + """ Just checks the NSM option. + + FLAGS: nfsv3 nsm + DEPEND: + CODE: NSM0 + """ + + print("Checking for --nsm support:") + if not env.nsm: + t.fail(" NSM not supported. You need to run with --nsm") + print(" Supported") + +def testNSMNull(t, env): + """ NSM null call. + + FLAGS: nfsv3 nsm + DEPEND: NSM0 + CODE: NSM1 + """ + env.nsm.null() + env.nsm_local.null() + +def testNSMSimuCrash(t, env): + """ Calls the simulate crash routine. + + FLAGS: nfsv3 nsm + DEPEND: NSM0 + CODE: NSM2 + """ + env.nsm.simu_crash() + +def testNSMMonClient(t, env): + """ Monitor and unmonitor the test machine. + + FLAGS: nfsv3 nsm + DEPEND: NSM0 + CODE: NSM3 + """ + # In the RPC library, ipaddress is the local IP + # Monitor the test client + res = env.nsm.mon(env.nsm.ipaddress) + nsmcheck(res, msg="Monitor self", state="up") + + # Monitor a nonsense client + res = env.nsm.mon("1.2.3.4") + nsmcheck(res, msg="Monitor bogus", state="up") + + # Unmonitor them + res = env.nsm.unmon(env.nsm.ipaddress) + nsmcheck(res, msg="Unmonitor self", state="down", state_only=True) + res = env.nsm.unmon("1.2.3.4") + nsmcheck(res, msg="Unmonitor bogus", state="down", state_only=True) + +def testNSMMonInvalid(t, env): + """ Monitor invalid hosts + + FLAGS: nfsv3 nsm + DEPEND: NSM0 + CODE: NSM4 + """ + res = env.nsm.mon("") + nsmcheck(res, STAT_FAIL, "Monitor a blank string") + # I guess this is actually valid: + # res = env.nsm.mon("localhost") + # nsmcheck(res, STAT_FAIL, "Monitor localhost") + +def testNSMUnmonAll(t, env): + """ We can't really see what hosts the server is monitoring, so this test + just checks to make sure it doesn't fail at the RPC layer. + + FLAGS: nfsv3 nsm + DEPEND: NSM0 + CODE: NSM5 + """ + res = env.nsm.mon(env.nsm.ipaddress) + nsmcheck(res, state="up") + res = env.nsm.unmon_all() + nsmcheck(res, state="down", state_only=True) + +def testNotify(t, env): + """ This test monitors a client and then notifies that the client crashed. + + FLAGS: nfsv3 nsm + DEPEND: NSM0 + CODE: NSM6 + """ + res = env.nsm.mon(env.nsm.ipaddress) + nsmcheck(res, state="up") + state = res.state + env.nsm.notify(env.nsm.ipaddress, state+1) + res = env.nsm.stat(env.nsm.ipaddress) + nsmcheck(res, state="down") diff --git a/nfs3/lib/nfs3/servertests/st_null.py b/nfs3/lib/nfs3/servertests/st_null.py new file mode 100755 index 0000000..b5846e4 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_null.py @@ -0,0 +1,19 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Null(t, env): + """ NFSPROC3_NULL + + FLAGS: nfsv3 all + DEPEND: + CODE: NULL1 + """ + ### Setup Phase ### + mnt_fh = homedir_fh(env.mc, env.c1) + + ### Execution Phase ### + res = env.c1.null() + + ### Verification Phase ### + # No check needed since res = None? diff --git a/nfs3/lib/nfs3/servertests/st_pathconf.py b/nfs3/lib/nfs3/servertests/st_pathconf.py new file mode 100755 index 0000000..e832f56 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_pathconf.py @@ -0,0 +1,36 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3PathConf(t, env): + """Retrieve the pathconf information of a file via the PATHCONF rpc + + + FLAGS: nfsv3 pathconf all + DEPEND: + CODE: PTHCNF1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.pathconf(test_file_fh) + + ### Verification Phase ### + check(res, msg="PATHCONF - file %s" % test_file) + +### Variations: +# Dir +# Different file types (nodes, symlinks, links, etc) +# No Permission +# Different permissions diff --git a/nfs3/lib/nfs3/servertests/st_read.py b/nfs3/lib/nfs3/servertests/st_read.py new file mode 100755 index 0000000..c5e78d9 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_read.py @@ -0,0 +1,48 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Read(t, env): + """ Read the contents of a file with the READ rpc + + + FLAGS: nfsv3 read all + DEPEND: + CODE: READ1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + test_data = "Test String" + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + res = env.c1.write(test_file_fh, offset=0, count=len(test_data), stable=FILE_SYNC, data=test_data) + check(res, msg="WRITE - file %s" % test_file) + + ### Execution Phase ### + res = env.c1.read(test_file_fh, offset=0, count=len(test_data)) + + ### Verification Phase ### + check(res, msg="READ - file %s" % test_file) + if res.resok.data != test_data: + t.fail.support(" ".join([ + "READ - verification: Data returned [%s]" % res.resok.data, + "did not match expected [%s]." % test_data])) + if len(res.resok.data) != len(test_data): + t.fail.support(" ".join([ + "READ - verification: [%d] bytes returned" % len(res.resok.data), + "[%d] bytes expected." % len(test_data)])) + + if res.eof != True: + t.fail("No EOF sent!") + + ### Clean-up Phase? ### + +### ToDo: Add basic negative cases. Beef up coverage diff --git a/nfs3/lib/nfs3/servertests/st_readdir.py b/nfs3/lib/nfs3/servertests/st_readdir.py new file mode 100755 index 0000000..7f834a1 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_readdir.py @@ -0,0 +1,54 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3ReadDir(t, env): + """ Retrieve entries sequentially from a dir via the READDIR rpc + + + FLAGS: nfsv3 readdir all + DEPEND: + CODE: RDDIR1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + created_files=[] + cookie = 0 + cookie_verf = 0 + count = 300 + test_file_count = 15 + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + for i in range(1, test_file_count + 1): + temp_name = "%s_%s" % (test_file, i) + res = env.c1.create(test_dir_fh, temp_name, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % temp_name) + created_files.append(temp_name) + + ### Execution Phase ### + entries = env.c1.do_readdir(test_dir_fh, cookie, cookie_verf, count) + + ### Verification Phase ### + if len(entries) != test_file_count + 2: + t.fail_support(" ".join([ + "READDIR - number of dir entries returned [%s]" % len(entries), + "does not match number created [%s]" % (test_file_count + 2)])) + for e in entries: + if e.name not in created_files: + if e.name != "." and e.name != "..": + t.fail_support(" ".join([ + "READDIR - returned entry name [%s]" % e.name, + "was not in the list of created files [%s]" %\ + ("\n".join(created_files)) + ])) + + +### Variations: +# NFS3ERR_BAD_COOKIE detection and handling? +# size = 0 --> NFS3ERR_TOOSMALL diff --git a/nfs3/lib/nfs3/servertests/st_readdirplus.py b/nfs3/lib/nfs3/servertests/st_readdirplus.py new file mode 100755 index 0000000..a9095a4 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_readdirplus.py @@ -0,0 +1,59 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3ReadDirPlus(t, env): + """ Retrieve entries sequentially from a dir via the READDIRPLUS rpc + + + FLAGS: nfsv3 readdirplus all + DEPEND: + CODE: RDDIRPLS1 + #ToDo: switch depend to create1 once bug #76982 is closed + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + created_files=[] + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + cookie = 0 + cookie_verf = 0 + dir_count = 150 + max_count = 1200 + test_file_count = 15 + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + for i in range(1, test_file_count + 1): + temp_name = "%s_%s" % (test_file, i) + res = env.c1.create(test_dir_fh, temp_name, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % temp_name) + created_files.append(temp_name) + + ### Execution Phase ### + entries = env.c1.do_readdirplus(test_dir_fh, cookie, cookie_verf, dir_count, max_count) + + ### Verification Phase ### + # Add 2 to the count to account for "." and ".." entries + if len(entries) != test_file_count + 2: + t.fail_support(" ".join([ + "READDIR - number of dir entries returned [%s]" % len(entries), + "does not match number created [%s]" % (test_file_count + 2)])) + for e in entries: + if e.name not in created_files: + if e.name != "." and e.name != "..": + t.fail_support(" ".join([ + "READDIR - returned entry name [%s]" % e.name, + "was not in the list of created files [%s]" %\ + ("\n".join(created_files)) + ])) + + +### Variations: +# NFS3ERR_BAD_COOKIE detection and handling? +# size = 0 --> NFS3ERR_TOOSMALL +# verify the returned attributes againts a single read call +# dirsize > maxsize diff --git a/nfs3/lib/nfs3/servertests/st_readlink.py b/nfs3/lib/nfs3/servertests/st_readlink.py new file mode 100755 index 0000000..8030894 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_readlink.py @@ -0,0 +1,58 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3ReadLink(t, env): + """ Create a symlink to a file and read the link via the READLINK rpc + + + FLAGS: nfsv3 readlink all + DEPEND: + CODE: RDLINK1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + test_link=t.name + "_link_1" + mount_path='/' + '/'.join(env.mc.opts.path[:-1]) + link_path='/'.join([mount_path, test_dir, test_file]) + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s " % test_file) + res = env.c1.symlink(test_dir_fh, test_link, mode_set=1, mode_val=0o777, + size_set=1, size_val=len(link_path), data=link_path) + check(res, msg="SYMLINK - link %s" % test_link) + res = env.c1.lookup(test_dir_fh, test_link) + check(res, msg="LOOKUP of test symlink %s" % test_link) + test_link_fh = res.object.data + + ### Execution Phase ### + res = env.c1.readlink(test_link_fh) + + ### Verification Phase ### + check(res, msg="READLINK on existing file %s" % test_file) + if res.resok.type != NF3LNK: + t.fail_support(" ".join([ + "READLINK - data type returned [%s]" % res.resok.type, + "does not match expected NF3LNK[%s]." % NF3LNK])) + if res.resok.data != link_path: + t.fail_support(" ".join([ + "READLINK - data returned [%s]" % res.resok.data, + "does not match expected [%s]." % link_path])) + if len(res.resok.data) != len(link_path): + t.fail_support(" ".join([ + "READLINK - bytes returned [%d]" % len(res.resok.data), + "does not match expected bytes [%d]." % len(link_path)])) + +###### Other variations: +### Linking to dir +### Linking to read-only file +### Linking to a file that user doesn't have perms on +### Link over-writting existing file +### Link over-writting existing link +### etc. diff --git a/nfs3/lib/nfs3/servertests/st_remove.py b/nfs3/lib/nfs3/servertests/st_remove.py new file mode 100755 index 0000000..d6c0caf --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_remove.py @@ -0,0 +1,38 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Remove(t, env): + """ Create a file and remove it with the REMOVE rpc + + + FLAGS: nfsv3 remove all + DEPEND: + CODE: REMOVE1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s " % test_file) + + ### Execution Phase ### + res = env.c1.remove(test_dir_fh, test_file) + + ### Verification Phase ### + check(res, msg="REMOVE - file %s" % test_file) + res = env.c1.lookup(test_dir_fh, test_file) + if res.status == NFS3_OK: + t.fail_support("REMOVE FAILED: File [%] still exists." % test_file) + +###### Other variations: +### verify removing a file that was written to +### ... different params +### ... different file types +### ... directories (even though)) diff --git a/nfs3/lib/nfs3/servertests/st_rename.py b/nfs3/lib/nfs3/servertests/st_rename.py new file mode 100755 index 0000000..9a43a48 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_rename.py @@ -0,0 +1,45 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Rename(t, env): + """ Rename a file with the RENAME rpc + + + FLAGS: nfsv3 rename all + DEPEND: + CODE: RENAME1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + new_test_file=test_file + "_renamed" + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + + ### Execution Phase ### + res = env.c1.rename(test_dir_fh, test_file, test_dir_fh, new_test_file) + + ### Verification Phase ### + check_msg="RENAME - file %s" % test_file + check(res, msg=check_msg) + res = env.c1.lookup(test_dir_fh, new_test_file) + check(res, msg="LOOKUP - file %s" % new_test_file) + if res.status != NFS3_OK: + t.fail_support("RENAME FAILED: File [%s] does not exist." \ + % new_test_file) + + #ToDo: Add negative LOOKUP call to verify old file/dir is gone + +###### Other variations: +### Rename dir +### Rename non-existant file +### Rename over existing file +### Rename without permissions +### Rename over existing file without permissions on the target file diff --git a/nfs3/lib/nfs3/servertests/st_rmdir.py b/nfs3/lib/nfs3/servertests/st_rmdir.py new file mode 100755 index 0000000..0e01df8 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_rmdir.py @@ -0,0 +1,32 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3Rmdir(t, env): + """ Remove a directory with the RMDIR rpc + + + FLAGS: nfsv3 rmdir all + DEPEND: + CODE: RMDIR1 + """ + ### Setup Phase ### + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + + ### Execution Phase ### + res = env.c1.rmdir(mnt_fh, test_dir) + + ### Verification Phase ### + check(res, msg="RMDIR - dir %s" % test_dir) + res = env.c1.lookup(mnt_fh, test_dir) + if res.status == NFS3_OK: + t.fail_support("REMOVE FAILED: Dir [%] still exists." % test_dir) + + +###### Other variations: +### Removing a dir with contents +### Removing a dir without permissions diff --git a/nfs3/lib/nfs3/servertests/st_setattr.py b/nfs3/lib/nfs3/servertests/st_setattr.py new file mode 100755 index 0000000..322fb5e --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_setattr.py @@ -0,0 +1,59 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3SetAttr(t, env): + """ Set the attributes of a file via the SETATTR rpc + and verify they change correctly + + FLAGS: nfsv3 setattr all + DEPEND: + CODE: SATTR1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + old_mode=0o777 + new_mode=0o755 + old_size=111 + new_size=333 + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, + file_mode_set=1, file_mode_val=old_mode, + size_set=1, size_val=old_size) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + res = env.c1.getattr(test_file_fh) + check(res, msg="GETATTR - file %s" % test_file) + if res.attributes.size != old_size: + t.fail_support(" ".join([ + "GETATTR - Initial file size [%s]" % res.attributes.size, + "does not match specified value [%s]" % old_size])) + if res.attributes.mode != old_mode: + t.fail_support(" ".join([ + "GETATTR - Initial file mode [%s]" % res.attributes.mode, + "does not match specified value [%s]" % old_mode])) + + ### Execution Phase ### + res = env.c1.setattr(test_file_fh, + mode_set=1, mode_val=new_mode, + size_set=1, size_val=new_size) + + ### Verification Phase ### + check(res, msg="SETATTR - file %s" % test_file) + if res.wcc.after.attributes.mode != new_mode: + t.fail_support(" ".join([ + "SETATTR - mode value [%s]" % res.wcc.after.attributes.mode, + "does not match specified value [%s]" % new_mode])) + if res.wcc.after.attributes.size != new_size: + t.fail_support(" ".join([ + "SETATTR - size attr value [%s]" % res.wcc.after.attributes.size, + "does not match specified value [%s]" % new_size])) + + +### Expand to cover each attr change + diff --git a/nfs3/lib/nfs3/servertests/st_symlink.py b/nfs3/lib/nfs3/servertests/st_symlink.py new file mode 100755 index 0000000..c8ff629 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_symlink.py @@ -0,0 +1,44 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * + +def testNfs3SymLink(t, env): + """ Create a symlink to a file via the SYMLINK rpc + + + FLAGS: nfsv3 symlink all + DEPEND: + CODE: SLINK1 + """ + ### Setup Phase ### + test_file=t.name + "_file_1" + test_dir=t.name + "_dir_1" + test_link=t.name + "_link_1" + mount_path='/' + '/'.join(env.mc.opts.path[:-1]) + link_path='/'.join([mount_path, test_dir, test_file]) + mnt_fh = homedir_fh(env.mc, env.c1) + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + # once bug 76982 is closed, drop the mode arguments + res = env.c1.symlink(test_dir_fh, test_link, mode_set=1, mode_val=0o777, + size_set=1, size_val=len(link_path), data=link_path) + + ### Verification Phase ### + check(res, msg="SYMLINK - link %s" % test_link) + res = env.c1.lookup(test_dir_fh, test_link) + check(res, msg="LOOKUP - link %s" % test_link) + if res.status != NFS3_OK: + t.fail_support("SYMLINK FAILED: File [%] still exists." % test_link) + + +### Variations: +# see hardlink (LINK) variations +# create symlinks with different perms/groups/owners? diff --git a/nfs3/lib/nfs3/servertests/st_write.py b/nfs3/lib/nfs3/servertests/st_write.py new file mode 100755 index 0000000..3fe3b8a --- /dev/null +++ b/nfs3/lib/nfs3/servertests/st_write.py @@ -0,0 +1,295 @@ +from nfs3.nfs3_const import * +from .environment import check, homedir_fh +from nfs3.nfs3lib import * +import threading +import time +import os + + +def testNfs3Write(t, env): + """ Write test data into a file via WRITE rpc, + read the file and verify the output + + FLAGS: nfsv3 write all + DEPEND: + CODE: WRITE1 + """ + ### Setup Phase ### + test_file = t.name + "_file_1" + test_dir = t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + test_data = "Test String" + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + res = env.c1.write(test_file_fh, offset=0, count=len(test_data), stable=FILE_SYNC, data=test_data) + + ### Verification Phase ### + check(res, msg="WRITE - file %s" % test_file) + if res.resok.count != len(test_data): + t.fail_support(" ".join([ + "WRITE - response: data returned [%d]" % res.resok.count, + "bytes of data written. [%d] bytes expected" % len(test_data)])) + res = env.c1.read(test_file_fh, offset=0, count=len(test_data)) + check(res, msg="READ - file %s" % test_file) + if res.resok.data != test_data: + t.fail.support(" ".join([ + "WRITE - operation returned [%s]." % res.resok.data, + "[%s] expected." % test_data])) + if res.resok.count != len(test_data): + t.fail_support(" ".join([ + "WRITE - operation returned [%d] bytes." % res.resok.count, + "[%d] bytes expected." % len(test_data)])) + + ### Clean-up Phase? ### + + +def testNfs3MultiWriter(t, env): + """ Testcase for Mavericks multiwriter + + FLAGS: nfsv3 write all + DEPEND: + CODE: WRITEMW1 + """ + + WRITECOUNT = 1024 * 1024 * 20 + OFFSET = 1024 * WRITECOUNT + THREADS = 10 + + test_file = t.name + test_dir = t.name + mnt_fh = homedir_fh(env.mc, env.c1) + + data = "" + for i in range(0, 256): + data = data + chr(i) + + # Setup + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="mkdir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="create %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + # Preallocate + print("Preallocating") + clients = {} + for thread in range(0, THREADS): + print("Preallocating at offset = %d" % (thread * OFFSET)) + writeThread(t, env, env.c1, test_file_fh, thread * OFFSET, WRITECOUNT, + FILE_SYNC, "*") + + # Use a different client connection for each thread + clients[thread] = NFS3Client('client1_pid%i_thread%i' % (os.getpid(), thread), + env.opts.server, env.nfs3port, env.opts.path[-1], + sec_list=[env.sec1], opts=env.opts) + + # Sleep to allow preallocation to settle + # time.sleep(1) + + # XXX Start timer and write to multiple places at the same time via + # multiple threads + + print("Running threads") + threads = [] + fail_event = threading.Event() + for thread in range(0, THREADS): + threads.append(threading.Thread(target=writeThread, + args=(t, env, clients[thread], test_file_fh, thread * OFFSET, + WRITECOUNT, FILE_SYNC, data, fail_event))) + + start = time.time() + for thread in range(0, THREADS): + threads[thread].start() + for thread in range(0, THREADS): + threads[thread].join() + elapsed = time.time() - start + print("Elapsed time = " + str(elapsed)) + + if fail_event.is_set(): + t.fail("One or more of the write threads failed!") + + print("Verifying, threaded") + threads = [] + for thread in range(0, THREADS): + threads.append(threading.Thread(target=verifyWriteThread, + args=(t, env, clients[thread], test_file_fh, thread * OFFSET, + WRITECOUNT, data, fail_event))) + for thread in range(0, THREADS): + threads[thread].start() + for thread in range(0, THREADS): + threads[thread].join() + + if fail_event.is_set(): + t.fail("One or more of the write threads failed!") + + +def verifyWriteThread(t, env, client, test_file_fh, offset, size, exp_data, + fail_event=None): + READSIZE = 32 * 1024 + # READSIZE=1024 + + try: + if size % READSIZE != 0: + t.fail("Read size is not a multiple of total data size!") + + exp_datalen = len(exp_data) + # print "READ: expected=%d" % exp_datalen + if size % exp_datalen != 0: + t.fail("Expected data length is not a multiple of total size!") + diff = size // exp_datalen + exp_newdata = exp_data * diff + exp_newdatalen = exp_datalen * diff + # print "READ: exp_total=%d" % exp_newdatalen + + if exp_newdatalen != size: + t.fail("ERROR with converting data length to write size!") + + eof = False + totaldata = "" + totalcount = 0 + + for off in range(offset, offset + size, READSIZE): + if eof: + t.fail("ERROR: Hit EOF, but not expecting it") + + # print "Reading offset=%d, count=%d" % \ + # (off, READSIZE) + res = client.read(test_file_fh, offset=off, count=READSIZE) + check(res, msg="READ: offset = %d, count = %d" % (off, READSIZE)) + # print res + count = res.resok.count + eof = res.resok.eof + data = res.resok.data + # print "DATA READ: Read %d bytes at offset %d" % (count, off) + + if len(data) != count: + t.fail("ERROR: Length of data = %d, count = %d" % + (len(data), count)) + + if count != READSIZE: + t.fail("ERROR: SHORT READ. Expected %d, read %d" % + (READSIZE, count)) + + totalcount = totalcount + count + totaldata = totaldata + data + + print("Total data read = %d" % totalcount) + + # Verify read data against expected + if totalcount != size: + t.fail("READ: Expected %d bytes, read %d bytes" % + (exp_newdatalen, totalcount)) + + if totaldata != exp_newdata: + t.fail("READ: Got bad data!") + + except Exception: + if fail_event is not None: + fail_event.set() + raise + + +# Write (some data) in chunks of a writeable size +# TODO This could be abstracted out more to provide more to callers +def writeThread(t, env, client, test_file_fh, offset, size, stable, data, + fail_event=None): + WRITESIZE = 32 * 1024 + # WRITESIZE=1024 + + try: + if size % WRITESIZE != 0: + t.fail("Write size is not a multiple of total data size!") + + datalen = len(data) + if WRITESIZE % datalen != 0: + t.fail("Individual data length is not a multiple of write size!") + diff = WRITESIZE // datalen + newdata = data * diff + + if len(newdata) != WRITESIZE: + t.fail("ERROR with converting data length to write size!") + + datadone = 0 + + for off in range(offset, offset + size, WRITESIZE): + # print "Writing type=%d, offset=%d, count=%d" % \ + # (stable, off, WRITESIZE) + res = client.write(test_file_fh, offset=off, count=WRITESIZE, + stable=stable, data=newdata) + check(res, msg="WRITE: type = %d, offset = %d, count = %d" % + (stable, off, WRITESIZE)) + # print res + + datadone = datadone + WRITESIZE + + print("Data done = %d" % datadone) + + except Exception: + if fail_event is not None: + fail_event.set() + raise + + +def testNfs3WriteDRC(t, env): + """ DRC data corruption test case + + FLAGS: nfsv3 write all + DEPEND: + CODE: WRITEDRC1 + """ + ### Setup Phase ### + test_file = t.name + "_file_1" + test_dir = t.name + "_dir_1" + mnt_fh = homedir_fh(env.mc, env.c1) + test_data = "A" * 16 + test_data2 = "B" * 16 + + res = env.c1.mkdir(mnt_fh, test_dir, dir_mode_set=1, dir_mode_val=0o777) + check(res, msg="MKDIR - dir %s" % test_dir) + test_dir_fh = res.resok.obj.handle.data + res = env.c1.create(test_dir_fh, test_file, file_mode_set=1, + file_mode_val=0o777) + check(res, msg="CREATE - file %s" % test_file) + test_file_fh = res.resok.obj.handle.data + + ### Execution Phase ### + env.c4_resend_sym.write(test_file_fh, offset=0, count=len(test_data), stable=FILE_SYNC, data=test_data) + env.c1.write(test_file_fh, offset=0, count=len(test_data2), stable=FILE_SYNC, data=test_data2) + time.sleep(61) + res = env.c4_resend_sym.write(test_file_fh, offset=0, count=len(test_data), stable=FILE_SYNC, data=test_data) + + ### Verification Phase ### + check(res, msg="WRITE - file %s" % test_file) + if res.resok.count != len(test_data): + t.fail_support(" ".join([ + "WRITE - response: data returned [%d]" % res.resok.count, + "bytes of data written. [%d] bytes expected" % len(test_data)])) + res = env.c1.read(test_file_fh, offset=0, count=len(test_data)) + check(res, msg="READ - file %s" % test_file) + if res.resok.data != test_data2: + t.fail(" ".join([ + "WRITE - operation returned [%s]." % res.resok.data, + "[%s] expected." % test_data2])) + if res.resok.count != len(test_data2): + t.fail(" ".join([ + "WRITE - operation returned [%d] bytes." % res.resok.count, + "[%d] bytes expected." % len(test_data2)])) + +### ToDo: Add basic negative cases. Beef up coverage + +### Append +### Overwrite +### Offset write +### Partial write (i.e. testing the count param) +### Negative cases (i.e. no permsm diff --git a/nfs3/lib/nfs3/servertests/utils.py b/nfs3/lib/nfs3/servertests/utils.py new file mode 100644 index 0000000..39f7f27 --- /dev/null +++ b/nfs3/lib/nfs3/servertests/utils.py @@ -0,0 +1,9 @@ +def assert_raises(exc_class, func, *args, **kwargs): + try: + func(*args, **kwargs) + except exc_class as e: + return e + except Exception as e: + raise AssertionError("{} raised - when {} was expected".format(e, exc_class)) + else: + raise AssertionError("{} not raised".format(exc_class)) diff --git a/nfs3/lib/nlm/__init__.py b/nfs3/lib/nlm/__init__.py new file mode 100644 index 0000000..4619673 --- /dev/null +++ b/nfs3/lib/nlm/__init__.py @@ -0,0 +1,4 @@ +import os as _os, sys as _sys +# Python 3: make the package directory importable so the historic bare +# (implicit-relative) imports such as ``import nlm_const`` keep working. +_sys.path.insert(1, _os.path.dirname(_os.path.abspath(__file__))) diff --git a/nfs3/lib/nlm/nlm.py b/nfs3/lib/nlm/nlm.py new file mode 100644 index 0000000..f228aa3 --- /dev/null +++ b/nfs3/lib/nlm/nlm.py @@ -0,0 +1,380 @@ +#!/usr/bin/env python +# nlm.py - NLM protocol library for python + +import rpc +import threading +import socket +import os +from xdrlib import Error as XDRError +from nlm_prot_const import * +from nlm_prot_type import * +from nlm_prot_pack import * +from testmod import WarningException, FailureException + +try: + import portmap +except: + # XXX missing portmap prevents anything from running. Handle missing + # portmap gracefully? + pass + +AuthSys = rpc.SecAuthSys(0,'jupiter',103558,100,[]) + +class NLMCBServer(rpc.RPCServer): + def __init__(self, client,ipv6=False): + self.prog = 100021 + self.port = 50000 + self.client = client + rpc.RPCServer.__init__(self, prog=self.prog, vers=4, + port=self.port) + self.packer = NLM_PROTPacker() + self.unpacker = NLM_PROTUnpacker('') + self.cb_lock = threading.Lock() + self.cb_lock.acquire() + self.cb_funct = {} + self.cb_res = {} + self.cb_event = {} + self.cb_granted_funct = None + self.cb_granted_event = None + self.cb_lock.release() + + def set_cb(self, cookie, funct, event): + self.cb_lock.acquire() + if funct is not None: + self.cb_funct[cookie] = funct + if event is not None: + self.cb_event[cookie] = event + self.cb_lock.release() + + def clear_cb(self, cookie): + self.cb_lock.acquire() + if cookie in self.cb_event: + del self.cb_event[cookie] + if cookie in self.cb_res: + del self.cb_res[cookie] + if cookie in self.cb_funct: + del self.cb_funct[cookie] + self.cb_lock.release() + + def get_cb_res(self, cookie): + self.cb_lock.acquire() + res = self.cb_res.get(cookie, None) + self.cb_lock.release() + return res + + def run(self): + # XXX TODO: Replace portmap with something that supports ipv6 + print("Starting NLM Call Back server on port %i" % self.port) + portmap.unset(100021, 0) + portmap.unset(100021, 1) + portmap.unset(100021, 3) + portmap.unset(100021, 4) + portmap.set(100021, 4, 6, self.port) + # portmap.set(100021, 4, 17, self.port) + rpc.RPCServer.run(self) + + def handle_res(self, data, cred): + self.unpacker.reset(data) + res = self.unpacker.unpack_nlm4_res() + try: + self.unpacker.done() + except XDRError: + return rpc.GARBAGE_ARGS, '' + self.cb_lock.acquire() + if res.cookie in self.cb_funct: + self.cb_funct[res.cookie](res) + del self.cb_funct[res.cookie] + if res.cookie in self.cb_event: + self.cb_event[res.cookie].set() + del self.cb_event[res.cookie] + self.cb_res[res.cookie] = res + self.cb_lock.release() + + def handle_0(self, data, cred): + """ NULL op """ + if data != '': + return rpc.GARBAGE_ARGS, '' + else: + return rpc.SUCCESS, '' + + def handle_11(self, data, cred): + """ TEST_RES op """ + self.unpacker.reset(data) + res = self.unpacker.unpack_nlm4_testres() + try: + self.unpacker.done() + except XDRError: + return rpc.GARBAGE_ARGS, '' + self.cb_lock.acquire() + if res.cookie in self.cb_funct: + self.cb_funct[res.cookie](res) + del self.cb_funct[res.cookie] + if res.cookie in self.cb_event: + self.cb_event[res.cookie].set() + del self.cb_event[res.cookie] + self.cb_res[res.cookie] = res + self.cb_lock.release() + + return rpc.SUCCESS, '' + + def handle_12(self, data, cred): + """ LOCK_RES op """ + self.handle_res(data,cred) + return rpc.SUCCESS, '' + + def handle_13(self, data, cred): + """ CANCEL_RES op """ + self.handle_res(data,cred) + return rpc.SUCCESS, '' + + def handle_14(self, data, cred): + """ UNLOCK_RES op """ + self.handle_res(data,cred) + return rpc.SUCCESS, '' + + def handle_5(self, data, cred): + """ GRANTED op """ + p = self.packer + un_p = self.unpacker + p.reset() + un_p.reset(data) + + res = un_p.unpack_nlm4_testargs() + cookie = res.cookie + try: + self.unpacker.done() + except XDRError: + return rpc.GARBAGE_ARGS, '' + response = NLM4_GRANTED + if self.cb_granted_funct is not None: + response = self.cb_granted_funct(res) + self.cb_granted_funct = None + if self.cb_granted_event is not None: + self.cb_granted_event.set() + self.cb_granted_event = None + p.pack_nlm4_res(cookie, response) + return rpc.SUCCESS, p.get_buffer() + + def handle_10(self, data, cred): + """ GRANTED_MSG op """ + un_p = self.unpacker + un_p.reset(data) + + res = un_p.unpack_nlm4_testargs() + try: + self.unpacker.done() + except XDRError: + return rpc.GARBAGE_ARGS, '' + if self.cb_granted_funct is None and self.cb_granted_event is None: + print("WARNING: Got a GRANTED_MSG, but have no callback or event.\ + The lock will not be held!") + return rpc.SUCCESS, '' + if self.cb_granted_funct is not None: + self.cb_granted_funct(res) + self.cb_granted_funct = None + if self.cb_granted_event is not None: + self.cb_granted_event.set() + self.cb_granted_event = None + return rpc.SUCCESS, '' + + +class NLM4Client(rpc.RPCClient): + def __init__(self, id, host='localhost', port=300, homedir=['pynfs'], + sec_list=[AuthSys], opts = None): + self.ipv6 = getattr(opts, "ipv6", False) + self._start_cb_server("cb_server_%s" % id) + self.packer = NLM_PROTPacker() + self.unpacker = NLM_PROTUnpacker('') + self.homedir = homedir + self.id = id + self.opts = opts + uselowport = True + rpc.RPCClient.__init__(self, host, port, program=NLM_PROG, + version=NLM4_VERS, sec_list=sec_list, + uselowport=uselowport,ipv6=self.ipv6) + self.server_address = (host,port) + + def _start_cb_server(self, name=None): + self.cb_server = NLMCBServer(self,self.ipv6) + self.thread = threading.Thread(target=self.cb_server.run, name=name) + self.thread.setDaemon(True) + self.thread.start() + + self.cb_control = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + while 1: + try: + self.cb_control.connect(('127.0.0.1', self.cb_server.port)) + break + except socket.error: + print("Waiting for CB Server to start") + time.sleep(1) + + def nlm4_pack(self, procedure, data): + p = self.packer + if procedure == NLMPROC4_NULL: + pass + #Main procs + elif procedure == NLMPROC4_TEST: + p.pack_nlm4_testargs(data) + elif procedure == NLMPROC4_TEST_MSG: + p.pack_nlm4_testargs(data) + elif procedure == NLMPROC4_LOCK: + p.pack_nlm4_lockargs(data) + elif procedure == NLMPROC4_LOCK_MSG: + p.pack_nlm4_lockargs(data) + elif procedure == NLMPROC4_UNLOCK: + p.pack_nlm4_unlockargs(data) + elif procedure == NLMPROC4_UNLOCK_MSG: + p.pack_nlm4_unlockargs(data) + elif procedure == NLMPROC4_CANCEL: + p.pack_nlm4_cancargs(data) + elif procedure == NLMPROC4_CANCEL_MSG: + p.pack_nlm4_cancargs(data) + #DOS-style + elif procedure == NLMPROC4_SHARE: + p.pack_nlm4_shareargs(data) + elif procedure == NLMPROC4_UNSHARE: + p.pack_nlm4_unshareargs(data) + elif procedure == NLMPROC4_NM_LOCK: + p.pack_nlm4_lockargs(data) + elif procedure == NLMPROC4_FREE_ALL: + p.pack_nlm4_notify(data) + else: + raise XDRError('bad switch=%s' % procedure) + + def nlm4_unpack(self, procedure): + un_p = self.unpacker + + if procedure == NLMPROC4_NULL: + return + elif procedure == NLMPROC4_TEST: + return un_p.unpack_nlm4_testres() + elif procedure == NLMPROC4_LOCK: + return un_p.unpack_nlm4_res() + elif procedure == NLMPROC4_UNLOCK: + return un_p.unpack_nlm4_res() + elif procedure == NLMPROC4_CANCEL: + return un_p.unpack_nlm4_res() + elif procedure == NLMPROC4_SHARE: + return un_p.unpack_nlm4_shareres() + elif procedure == NLMPROC4_UNSHARE: + return un_p.unpack_nlm4_shareres() + elif procedure >= NLMPROC4_TEST_MSG and procedure <= \ + NLMPROC4_GRANTED_MSG: + return + elif procedure == NLMPROC4_NM_LOCK: + return un_p.unpack_nlm4_res() + elif procedure == NLMPROC4_FREE_ALL: + return + else: + raise XDRError('bad switch=%s' % procedure) + + def nlm4_call(self, procedure, data=''): + p = self.packer + un_p = self.unpacker + + # Pack + p.reset() + self.nlm4_pack(procedure, data) + + # Call + res = self.call(procedure, p.get_buffer()) + + # Unpack + un_p.reset(res) + res = self.nlm4_unpack(procedure) + un_p.done() + + return res + + def nlm4_call_async(self, procedure, data): + p = self.packer + + p.reset() + self.nlm4_pack(procedure, data) + + self.send(procedure, p.get_buffer(), None, None) + +#Synchronous Calls + def test(self, lock, netobj_cookie=None, exclusive=False): + arg_list=nlm4_testargs(netobj_cookie, exclusive, lock) + return self.nlm4_call(NLMPROC4_TEST,arg_list) + + ### Name changed to avoid conflict with thread.lock + def lockk(self, lock, netobj_cookie=None, block=False, exclusive=False, + reclaim=False, state = 1): + arg_list=nlm4_lockargs(netobj_cookie, block, exclusive, + lock, reclaim, state) + return self.nlm4_call(NLMPROC4_LOCK,arg_list) + + def unlock(self, lock, netobj_cookie=None): + arg_list=nlm_unlockargs(netobj_cookie, lock) + return self.nlm4_call(NLMPROC4_UNLOCK,arg_list) + + def cancel(self, lock, netobj_cookie=None, block=False, exclusive=False): + arg_list=nlm_cancargs(netobj_cookie, block, exclusive, lock) + return self.nlm4_call(NLMPROC4_CANCEL,arg_list) + +#Asynchronous Calls + def test_msg(self, lock, netobj_cookie=None, exclusive=False, + cb_funct=None, cb_event=None): + arg_list=nlm4_testargs(netobj_cookie, exclusive, lock) + self.cb_server.set_cb(netobj_cookie, cb_funct, cb_event) + return self.nlm4_call_async(NLMPROC4_TEST_MSG, arg_list) + + def lock_msg(self, lock, netobj_cookie=None, block=False, exclusive=False, + reclaim=False, state = 1, cb_funct=None, cb_event=None): + arg_list=nlm4_lockargs(netobj_cookie, block, exclusive, + lock, reclaim, state) + self.cb_server.set_cb(netobj_cookie, cb_funct, cb_event) + return self.nlm4_call_async(NLMPROC4_LOCK_MSG,arg_list) + + def unlock_msg(self, lock, netobj_cookie=None, cb_funct=None, + cb_event=None): + arg_list=nlm_unlockargs(netobj_cookie, lock) + self.cb_server.set_cb(netobj_cookie, cb_funct, cb_event) + return self.nlm4_call_async(NLMPROC4_UNLOCK_MSG,arg_list) + + def cancel_msg(self, lock, netobj_cookie=None, block=False, exclusive=False, + cb_funct=None, cb_event=None): + arg_list=nlm_cancargs(netobj_cookie, block, exclusive, lock) + self.cb_server.set_cb(netobj_cookie, cb_funct, cb_event) + return self.nlm4_call_async(NLMPROC4_CANCEL_MSG,arg_list) +# DOS-style + def share(self, netobj_cookie=None, caller_name='', netobj_fh=None, + netobj_oh=None, mode=0, access=0, reclaim=False): + arg_list=nlm_shareargs(netobj_cookie, nlm_share(caller_name, + netobj_fh, netobj_oh, mode, access), reclaim) + return self.nlm4_call(NLMPROC4_SHARE,arg_list) + + def unshare(self, netobj_cookie=None, caller_name='', netobj_fh=None, + netobj_oh=None, mode=0, access=0): + arg_list=nlm_shareargs(netobj_cookie, nlm_share(caller_name, + netobj_fh, netobj_oh, mode, access)) + return self.nlm4_call(NLMPROC4_UNSHARE,arg_list) + + def nm_lock(self, lock, netobj_cookie=None, block=False, exclusive=False, + reclaim=False, state=1): + arg_list=nlm_lockargs(netobj_cookie, block, exclusive, lock, reclaim, + state) + return self.nlm4_call(NLMPROC4_NM_LOCK, arg_list) + + def free_all(self, name): + return self.nlm4_call(NLMPROC4_FREE_ALL, nlm_notify(name, 0)) +############################### + +def nlm4check(res, stat=NLM4_GRANTED, msg=None, warnlist=[]): + if res.stat == stat: + return + if type(stat) is str: + raise RuntimeError("No 'msg=' in front of check's string arg") + desired = nlm4_stats[stat] + received = nlm4_stats[res.stat] + if msg: + msg = "%s should return %s, instead got %s" % (msg, desired, received) + + if res.stat in warnlist: + raise WarningException(msg) + else: + raise FailureException(msg) + diff --git a/nfs3/lib/nlm/nlm_prot.x b/nfs3/lib/nlm/nlm_prot.x new file mode 100644 index 0000000..ac8d6bb --- /dev/null +++ b/nfs3/lib/nlm/nlm_prot.x @@ -0,0 +1,445 @@ +/* + * Network lock manager protocol definition + * Copyright (C) 1986, 1992, 1993, 1997, 1999 by Sun Microsystems, Inc. + * All rights reserved. + * + * Protocol used between local lock manager and remote lock manager. + * + * There are currently 3 versions of the protocol in use. Versions 1 + * and 3 are used with NFS version 2. Version 4 is used with NFS + * version 3. + * + * (Note: there is also a version 2, but it defines an orthogonal set of + * procedures that the status monitor uses to notify the lock manager of + * changes in monitored systems.) + * Edited by Tai Horgan, for consumption by pynfs + */ + +%#pragma ident "@(#)nlm_prot.x 1.8 99/08/20 SMI" + +%#if RPC_HDR +% +%#include +% +%#endif + +%#ifdef RPC_HDR +%#define LM_MAXSTRLEN 1024 +%#define LM_MAXNAMELEN (LM_MAXSTRLEN + 1) +%#endi + +const LM_MAXSTRLEN = 1024; +const LM_MAXNAMELEN = 1025; + + +/* Typedefs for pynfs + * Added by Tai + */ + +const MAXNETOBJ_SZ = 1024; +typedef int int32; +typedef unsigned hyper uint64; +typedef opaque netobj; + +/* + * Types for versions 1 and 3. + */ + +/* + * Status of a call to the lock manager. The lower case enums violate the + * current style guide, but we're stuck with 'em. + */ + +enum nlm_stats { + nlm_granted = 0, + nlm_denied = 1, + nlm_denied_nolocks = 2, + nlm_blocked = 3, + nlm_denied_grace_period = 4, + nlm_deadlck = 5 +}; + +/* + * The holder of a conflicting lock. + */ + +typedef struct { + bool exclusive; + int svid; + netobj oh; + unsigned l_offset; + unsigned l_len; +} nlm_holder; + +union nlm_testrply switch (nlm_stats stat) { + case nlm_denied: + nlm_holder holder; + default: + void; +}; + +struct nlm_stat { + nlm_stats stat; +}; + +struct nlm_res { + netobj cookie; + nlm_stat stat; +}; + +struct nlm_testres { + netobj cookie; + nlm_testrply stat; +}; + +typedef struct{ + string caller_name; + netobj fh; /* identify a file */ + netobj oh; /* identify owner of a lock */ + int svid; /* generated from pid for svid */ + unsigned l_offset; + unsigned l_len; +}nlm_lock; + +struct nlm_lockargs { + netobj cookie; + bool block; + bool exclusive; + nlm_lock alock; + bool reclaim; /* used for recovering locks */ + int state; /* specify local status monitor state */ +}; + +struct nlm_cancargs { + netobj cookie; + bool block; + bool exclusive; + nlm_lock alock; +}; + +struct nlm_testargs { + netobj cookie; + bool exclusive; + nlm_lock alock; +}; + +struct nlm_unlockargs { + netobj cookie; + nlm_lock alock; +}; + +%#ifdef RPC_HDR +%/* +% * The following enums are actually bit encoded for efficient +% * boolean algebra.... DON'T change them..... +% * The mixed-case enums violate the present style guide, but we're +% * stuck with 'em. +% */ +%#endif + +enum fsh_mode { + fsm_DN = 0, /* deny none */ + fsm_DR = 1, /* deny read */ + fsm_DW = 2, /* deny write */ + fsm_DRW = 3 /* deny read/write */ +}; + +enum fsh_access { + fsa_NONE = 0, /* for completeness */ + fsa_R = 1, /* read only */ + fsa_W = 2, /* write only */ + fsa_RW = 3 /* read/write */ +}; + +struct nlm_share { + string caller_name; + netobj fh; + netobj oh; + fsh_mode mode; + fsh_access access; +}; + +struct nlm_shareargs { + netobj cookie; + nlm_share share; + bool reclaim; +}; + +struct nlm_shareres { + netobj cookie; + nlm_stats stat; + int sequence; +}; + +struct nlm_notify { + string name; + int state; +}; + +/* + * Types for version 4. + * + * This revision is designed to work with NFS V3. The main changes from + * NFS V2 to V3 that affect the NLM protocol are that all file offsets + * and sizes are now unsigned 64-bit ints, and file handles are now + * variable length. In NLM V1 and V3, the fixed-length V2 file handle + * was encoded as a 'netobj', which is a count followed by the data + * bytes. For NLM 4, the file handle is already a count followed by + * data bytes, so the handle is copied directly into the netobj, rather + * than being encoded with an additional byte count. + */ + +/* + * Status of a call to the lock manager. + */ + +enum nlm4_stats { + NLM4_GRANTED = 0, /* lock was granted */ + NLM4_DENIED = 1, /* lock was not granted, usually */ + /* due to conflicting lock */ + NLM4_DENIED_NOLOCKS = 2, /* not granted: out of resources */ + NLM4_BLOCKED = 3, /* not granted: expect callback */ + /* when granted */ + NLM4_DENIED_GRACE_PERIOD = 4, /* not granted: server is */ + /* reestablishing old locks */ + NLM4_DEADLCK = 5, /* not granted: deadlock detected */ + NLM4_ROFS = 6, /* not granted: read-only filesystem */ + NLM4_STALE_FH = 7, /* not granted: stale file handle */ + NLM4_FBIG = 8, /* not granted: offset or length */ + /* too big */ + NLM4_FAILED = 9 /* not granted: some other error */ +}; + +/* + * The holder of a conflicting lock. + */ +/* MODIFIED BY TAI */ +typedef struct { + bool exclusive; + int32 svid; + netobj oh; + uint64 l_offset; + uint64 l_len; +} nlm4_holder; + +union nlm4_testrply switch (nlm4_stats stat) { + case NLM4_DENIED: + nlm4_holder holder; + default: + void; +}; + +struct nlm4_stat { + nlm4_stats stat; +}; + +struct nlm4_res { + netobj cookie; + nlm4_stat stat; +}; + +struct nlm4_testres { + netobj cookie; + nlm4_testrply stat; +}; +/*MODIFIED BY TAI*/ +typedef struct { + string caller_name; + netobj fh; /* identify a file */ + netobj oh; /* identify owner of a lock */ + int32 svid; /* generated from pid for svid */ + uint64 l_offset; + uint64 l_len; +} nlm4_lock; + +struct nlm4_lockargs { + netobj cookie; + bool block; + bool exclusive; + nlm4_lock alock; + bool reclaim; /* used for recovering locks */ + int32 state; /* specify local status monitor state */ +}; + +struct nlm4_cancargs { + netobj cookie; + bool block; + bool exclusive; + nlm4_lock alock; +}; + +struct nlm4_testargs { + netobj cookie; + bool exclusive; + nlm4_lock alock; +}; + +struct nlm4_unlockargs { + netobj cookie; + nlm4_lock alock; +}; + +%#ifdef RPC_HDR +%/* +% * The following enums are actually bit encoded for efficient +% * boolean algebra.... DON'T change them..... +% */ +%#endif + +enum fsh4_mode { + FSM_DN = 0, /* deny none */ + FSM_DR = 1, /* deny read */ + FSM_DW = 2, /* deny write */ + FSM_DRW = 3 /* deny read/write */ +}; + +enum fsh4_access { + FSA_NONE = 0, /* for completeness */ + FSA_R = 1, /* read only */ + FSA_W = 2, /* write only */ + FSA_RW = 3 /* read/write */ +}; + +struct nlm4_share { + string caller_name; + netobj fh; + netobj oh; + fsh4_mode mode; + fsh4_access access; +}; + +struct nlm4_shareargs { + netobj cookie; + nlm4_share share; + bool reclaim; +}; + +struct nlm4_shareres { + netobj cookie; + nlm4_stats stat; + int32 sequence; +}; + +struct nlm4_notify { + string name; + int32 state; +}; + +/* + * Over-the-wire protocol used between the network lock managers + */ + +program NLM_PROG { + version NLM_VERS { + + nlm_testres + NLM_TEST(nlm_testargs) = 1; + + nlm_res + NLM_LOCK(nlm_lockargs) = 2; + + nlm_res + NLM_CANCEL(nlm_cancargs) = 3; + + nlm_res + NLM_UNLOCK(nlm_unlockargs) = 4; + /* + * remote lock manager call-back to grant lock + */ + nlm_res + NLM_GRANTED(nlm_testargs) = 5; + + /* + * message passing style of requesting lock + */ + + void + NLM_TEST_MSG(nlm_testargs) = 6; + void + NLM_LOCK_MSG(nlm_lockargs) = 7; + void + NLM_CANCEL_MSG(nlm_cancargs) = 8; + void + NLM_UNLOCK_MSG(nlm_unlockargs) = 9; + void + NLM_GRANTED_MSG(nlm_testargs) = 10; + void + NLM_TEST_RES(nlm_testres) = 11; + void + NLM_LOCK_RES(nlm_res) = 12; + void + NLM_CANCEL_RES(nlm_res) = 13; + void + NLM_UNLOCK_RES(nlm_res) = 14; + void + NLM_GRANTED_RES(nlm_res) = 15; + } = 1; + + version NLM_VERSX { + nlm_shareres + NLM_SHARE(nlm_shareargs) = 20; + nlm_shareres + NLM_UNSHARE(nlm_shareargs) = 21; + nlm_res + NLM_NM_LOCK(nlm_lockargs) = 22; + void + NLM_FREE_ALL(nlm_notify) = 23; + } = 3; + + version NLM4_VERS { + void + NLMPROC4_NULL(void) = 0; + nlm4_testres + NLMPROC4_TEST(nlm4_testargs) = 1; + nlm4_res + NLMPROC4_LOCK(nlm4_lockargs) = 2; + nlm4_res + NLMPROC4_CANCEL(nlm4_cancargs) = 3; + nlm4_res + NLMPROC4_UNLOCK(nlm4_unlockargs) = 4; + /* + * remote lock manager call-back to grant lock + */ + nlm4_res + NLMPROC4_GRANTED(nlm4_testargs) = 5; + + /* + * message passing style of requesting lock + */ + + void + NLMPROC4_TEST_MSG(nlm4_testargs) = 6; + void + NLMPROC4_LOCK_MSG(nlm4_lockargs) = 7; + void + NLMPROC4_CANCEL_MSG(nlm4_cancargs) = 8; + void + NLMPROC4_UNLOCK_MSG(nlm4_unlockargs) = 9; + void + NLMPROC4_GRANTED_MSG(nlm4_testargs) = 10; + void + NLMPROC4_TEST_RES(nlm4_testres) = 11; + void + NLMPROC4_LOCK_RES(nlm4_res) = 12; + void + NLMPROC4_CANCEL_RES(nlm4_res) = 13; + void + NLMPROC4_UNLOCK_RES(nlm4_res) = 14; + void + NLMPROC4_GRANTED_RES(nlm4_res) = 15; + + /* + * DOS-style file sharing + */ + + nlm4_shareres + NLMPROC4_SHARE(nlm4_shareargs) = 20; + nlm4_shareres + NLMPROC4_UNSHARE(nlm4_shareargs) = 21; + nlm4_res + NLMPROC4_NM_LOCK(nlm4_lockargs) = 22; + void + NLMPROC4_FREE_ALL(nlm4_notify) = 23; + } = 4; + +} = 100021; diff --git a/nfs3/lib/nlm/nlm_prot_const.py b/nfs3/lib/nlm/nlm_prot_const.py new file mode 100644 index 0000000..a731537 --- /dev/null +++ b/nfs3/lib/nlm/nlm_prot_const.py @@ -0,0 +1,123 @@ +# Generated by rpcgen.py from nlm_prot.x on Wed Jun 24 11:38:48 2026 +NLM_TEST = 1 +NLM_LOCK = 2 +NLM_CANCEL = 3 +NLM_UNLOCK = 4 +NLM_GRANTED = 5 +NLM_TEST_MSG = 6 +NLM_LOCK_MSG = 7 +NLM_CANCEL_MSG = 8 +NLM_UNLOCK_MSG = 9 +NLM_GRANTED_MSG = 10 +NLM_TEST_RES = 11 +NLM_LOCK_RES = 12 +NLM_CANCEL_RES = 13 +NLM_UNLOCK_RES = 14 +NLM_GRANTED_RES = 15 +NLM_SHARE = 20 +NLM_UNSHARE = 21 +NLM_NM_LOCK = 22 +NLM_FREE_ALL = 23 +NLMPROC4_NULL = 0 +NLMPROC4_TEST = 1 +NLMPROC4_LOCK = 2 +NLMPROC4_CANCEL = 3 +NLMPROC4_UNLOCK = 4 +NLMPROC4_GRANTED = 5 +NLMPROC4_TEST_MSG = 6 +NLMPROC4_LOCK_MSG = 7 +NLMPROC4_CANCEL_MSG = 8 +NLMPROC4_UNLOCK_MSG = 9 +NLMPROC4_GRANTED_MSG = 10 +NLMPROC4_TEST_RES = 11 +NLMPROC4_LOCK_RES = 12 +NLMPROC4_CANCEL_RES = 13 +NLMPROC4_UNLOCK_RES = 14 +NLMPROC4_GRANTED_RES = 15 +NLMPROC4_SHARE = 20 +NLMPROC4_UNSHARE = 21 +NLMPROC4_NM_LOCK = 22 +NLMPROC4_FREE_ALL = 23 +LM_MAXSTRLEN = 1024 +LM_MAXNAMELEN = 1025 +MAXNETOBJ_SZ = 1024 +nlm_granted = 0 +nlm_denied = 1 +nlm_denied_nolocks = 2 +nlm_blocked = 3 +nlm_denied_grace_period = 4 +nlm_deadlck = 5 +nlm_stats = { + 0 : 'nlm_granted', + 1 : 'nlm_denied', + 2 : 'nlm_denied_nolocks', + 3 : 'nlm_blocked', + 4 : 'nlm_denied_grace_period', + 5 : 'nlm_deadlck', +} +fsm_DN = 0 +fsm_DR = 1 +fsm_DW = 2 +fsm_DRW = 3 +fsh_mode = { + 0 : 'fsm_DN', + 1 : 'fsm_DR', + 2 : 'fsm_DW', + 3 : 'fsm_DRW', +} +fsa_NONE = 0 +fsa_R = 1 +fsa_W = 2 +fsa_RW = 3 +fsh_access = { + 0 : 'fsa_NONE', + 1 : 'fsa_R', + 2 : 'fsa_W', + 3 : 'fsa_RW', +} +NLM4_GRANTED = 0 +NLM4_DENIED = 1 +NLM4_DENIED_NOLOCKS = 2 +NLM4_BLOCKED = 3 +NLM4_DENIED_GRACE_PERIOD = 4 +NLM4_DEADLCK = 5 +NLM4_ROFS = 6 +NLM4_STALE_FH = 7 +NLM4_FBIG = 8 +NLM4_FAILED = 9 +nlm4_stats = { + 0 : 'NLM4_GRANTED', + 1 : 'NLM4_DENIED', + 2 : 'NLM4_DENIED_NOLOCKS', + 3 : 'NLM4_BLOCKED', + 4 : 'NLM4_DENIED_GRACE_PERIOD', + 5 : 'NLM4_DEADLCK', + 6 : 'NLM4_ROFS', + 7 : 'NLM4_STALE_FH', + 8 : 'NLM4_FBIG', + 9 : 'NLM4_FAILED', +} +FSM_DN = 0 +FSM_DR = 1 +FSM_DW = 2 +FSM_DRW = 3 +fsh4_mode = { + 0 : 'FSM_DN', + 1 : 'FSM_DR', + 2 : 'FSM_DW', + 3 : 'FSM_DRW', +} +FSA_NONE = 0 +FSA_R = 1 +FSA_W = 2 +FSA_RW = 3 +fsh4_access = { + 0 : 'FSA_NONE', + 1 : 'FSA_R', + 2 : 'FSA_W', + 3 : 'FSA_RW', +} +NLM_PROG = 100021 +NLM_VERS = 1 +NLM_VERSX = 3 +NLM4_VERS = 4 diff --git a/nfs3/lib/nlm/nlm_prot_pack.py b/nfs3/lib/nlm/nlm_prot_pack.py new file mode 100644 index 0000000..d8d95c3 --- /dev/null +++ b/nfs3/lib/nlm/nlm_prot_pack.py @@ -0,0 +1,856 @@ +# Generated by rpcgen.py from nlm_prot.x on Wed Jun 24 11:38:48 2026 +import nlm_prot_const as const +import nlm_prot_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class NLM_PROTPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + pack_int32 = pack_int + + pack_uint64 = pack_uhyper + + def pack_netobj(self, data): + if hasattr(self, 'filter_netobj'): + data = getattr(self, 'filter_netobj')(data) + if len(data) > const.MAXNETOBJ_SZ and self.check_array: + raise XDRError('array length too long for data') + self.pack_opaque(data) + + def pack_nlm_stats(self, data): + if hasattr(self, 'filter_nlm_stats'): + data = getattr(self, 'filter_nlm_stats')(data) + if self.check_enum and data not in [const.nlm_granted, const.nlm_denied, const.nlm_denied_nolocks, const.nlm_blocked, const.nlm_denied_grace_period, const.nlm_deadlck]: + raise XDRError('value=%s not in enum nlm_stats' % data) + self.pack_int(data) + + def pack_nlm_holder(self, data): + if hasattr(self, 'filter_nlm_holder'): + data = getattr(self, 'filter_nlm_holder')(data) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.svid is None: + raise TypeError('data.svid == None') + self.pack_int(data.svid) + if data.oh is None: + raise TypeError('data.oh == None') + self.pack_netobj(data.oh) + if data.l_offset is None: + raise TypeError('data.l_offset == None') + self.pack_unsigned(data.l_offset) + if data.l_len is None: + raise TypeError('data.l_len == None') + self.pack_unsigned(data.l_len) + + def pack_nlm_testrply(self, data): + if hasattr(self, 'filter_nlm_testrply'): + data = getattr(self, 'filter_nlm_testrply')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm_stats(data.stat) + if data.stat == const.nlm_denied: + if data.holder is None: + raise TypeError('data.holder == None') + self.pack_nlm_holder(data.holder) + else: + pass + + def pack_nlm_stat(self, data): + if hasattr(self, 'filter_nlm_stat'): + data = getattr(self, 'filter_nlm_stat')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm_stats(data.stat) + + def pack_nlm_res(self, data): + if hasattr(self, 'filter_nlm_res'): + data = getattr(self, 'filter_nlm_res')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm_stat(data.stat) + + def pack_nlm_testres(self, data): + if hasattr(self, 'filter_nlm_testres'): + data = getattr(self, 'filter_nlm_testres')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm_testrply(data.stat) + + def pack_nlm_lock(self, data): + if hasattr(self, 'filter_nlm_lock'): + data = getattr(self, 'filter_nlm_lock')(data) + if data.caller_name is None: + raise TypeError('data.caller_name == None') + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + self.pack_string(data.caller_name) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_netobj(data.fh) + if data.oh is None: + raise TypeError('data.oh == None') + self.pack_netobj(data.oh) + if data.svid is None: + raise TypeError('data.svid == None') + self.pack_int(data.svid) + if data.l_offset is None: + raise TypeError('data.l_offset == None') + self.pack_unsigned(data.l_offset) + if data.l_len is None: + raise TypeError('data.l_len == None') + self.pack_unsigned(data.l_len) + + def pack_nlm_lockargs(self, data): + if hasattr(self, 'filter_nlm_lockargs'): + data = getattr(self, 'filter_nlm_lockargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.block is None: + raise TypeError('data.block == None') + self.pack_bool(data.block) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm_lock(data.alock) + if data.reclaim is None: + raise TypeError('data.reclaim == None') + self.pack_bool(data.reclaim) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int(data.state) + + def pack_nlm_cancargs(self, data): + if hasattr(self, 'filter_nlm_cancargs'): + data = getattr(self, 'filter_nlm_cancargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.block is None: + raise TypeError('data.block == None') + self.pack_bool(data.block) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm_lock(data.alock) + + def pack_nlm_testargs(self, data): + if hasattr(self, 'filter_nlm_testargs'): + data = getattr(self, 'filter_nlm_testargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm_lock(data.alock) + + def pack_nlm_unlockargs(self, data): + if hasattr(self, 'filter_nlm_unlockargs'): + data = getattr(self, 'filter_nlm_unlockargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm_lock(data.alock) + + def pack_fsh_mode(self, data): + if hasattr(self, 'filter_fsh_mode'): + data = getattr(self, 'filter_fsh_mode')(data) + if self.check_enum and data not in [const.fsm_DN, const.fsm_DR, const.fsm_DW, const.fsm_DRW]: + raise XDRError('value=%s not in enum fsh_mode' % data) + self.pack_int(data) + + def pack_fsh_access(self, data): + if hasattr(self, 'filter_fsh_access'): + data = getattr(self, 'filter_fsh_access')(data) + if self.check_enum and data not in [const.fsa_NONE, const.fsa_R, const.fsa_W, const.fsa_RW]: + raise XDRError('value=%s not in enum fsh_access' % data) + self.pack_int(data) + + def pack_nlm_share(self, data): + if hasattr(self, 'filter_nlm_share'): + data = getattr(self, 'filter_nlm_share')(data) + if data.caller_name is None: + raise TypeError('data.caller_name == None') + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + self.pack_string(data.caller_name) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_netobj(data.fh) + if data.oh is None: + raise TypeError('data.oh == None') + self.pack_netobj(data.oh) + if data.mode is None: + raise TypeError('data.mode == None') + self.pack_fsh_mode(data.mode) + if data.access is None: + raise TypeError('data.access == None') + self.pack_fsh_access(data.access) + + def pack_nlm_shareargs(self, data): + if hasattr(self, 'filter_nlm_shareargs'): + data = getattr(self, 'filter_nlm_shareargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.share is None: + raise TypeError('data.share == None') + self.pack_nlm_share(data.share) + if data.reclaim is None: + raise TypeError('data.reclaim == None') + self.pack_bool(data.reclaim) + + def pack_nlm_shareres(self, data): + if hasattr(self, 'filter_nlm_shareres'): + data = getattr(self, 'filter_nlm_shareres')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm_stats(data.stat) + if data.sequence is None: + raise TypeError('data.sequence == None') + self.pack_int(data.sequence) + + def pack_nlm_notify(self, data): + if hasattr(self, 'filter_nlm_notify'): + data = getattr(self, 'filter_nlm_notify')(data) + if data.name is None: + raise TypeError('data.name == None') + if len(data.name) > const.LM_MAXNAMELEN and self.check_array: + raise XDRError('array length too long for data.name') + self.pack_string(data.name) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int(data.state) + + def pack_nlm4_stats(self, data): + if hasattr(self, 'filter_nlm4_stats'): + data = getattr(self, 'filter_nlm4_stats')(data) + if self.check_enum and data not in [const.NLM4_GRANTED, const.NLM4_DENIED, const.NLM4_DENIED_NOLOCKS, const.NLM4_BLOCKED, const.NLM4_DENIED_GRACE_PERIOD, const.NLM4_DEADLCK, const.NLM4_ROFS, const.NLM4_STALE_FH, const.NLM4_FBIG, const.NLM4_FAILED]: + raise XDRError('value=%s not in enum nlm4_stats' % data) + self.pack_int(data) + + def pack_nlm4_holder(self, data): + if hasattr(self, 'filter_nlm4_holder'): + data = getattr(self, 'filter_nlm4_holder')(data) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.svid is None: + raise TypeError('data.svid == None') + self.pack_int32(data.svid) + if data.oh is None: + raise TypeError('data.oh == None') + self.pack_netobj(data.oh) + if data.l_offset is None: + raise TypeError('data.l_offset == None') + self.pack_uint64(data.l_offset) + if data.l_len is None: + raise TypeError('data.l_len == None') + self.pack_uint64(data.l_len) + + def pack_nlm4_testrply(self, data): + if hasattr(self, 'filter_nlm4_testrply'): + data = getattr(self, 'filter_nlm4_testrply')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm4_stats(data.stat) + if data.stat == const.NLM4_DENIED: + if data.holder is None: + raise TypeError('data.holder == None') + self.pack_nlm4_holder(data.holder) + else: + pass + + def pack_nlm4_stat(self, data): + if hasattr(self, 'filter_nlm4_stat'): + data = getattr(self, 'filter_nlm4_stat')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm4_stats(data.stat) + + def pack_nlm4_res(self, data): + if hasattr(self, 'filter_nlm4_res'): + data = getattr(self, 'filter_nlm4_res')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm4_stat(data.stat) + + def pack_nlm4_testres(self, data): + if hasattr(self, 'filter_nlm4_testres'): + data = getattr(self, 'filter_nlm4_testres')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm4_testrply(data.stat) + + def pack_nlm4_lock(self, data): + if hasattr(self, 'filter_nlm4_lock'): + data = getattr(self, 'filter_nlm4_lock')(data) + if data.caller_name is None: + raise TypeError('data.caller_name == None') + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + self.pack_string(data.caller_name) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_netobj(data.fh) + if data.oh is None: + raise TypeError('data.oh == None') + self.pack_netobj(data.oh) + if data.svid is None: + raise TypeError('data.svid == None') + self.pack_int32(data.svid) + if data.l_offset is None: + raise TypeError('data.l_offset == None') + self.pack_uint64(data.l_offset) + if data.l_len is None: + raise TypeError('data.l_len == None') + self.pack_uint64(data.l_len) + + def pack_nlm4_lockargs(self, data): + if hasattr(self, 'filter_nlm4_lockargs'): + data = getattr(self, 'filter_nlm4_lockargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.block is None: + raise TypeError('data.block == None') + self.pack_bool(data.block) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm4_lock(data.alock) + if data.reclaim is None: + raise TypeError('data.reclaim == None') + self.pack_bool(data.reclaim) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int32(data.state) + + def pack_nlm4_cancargs(self, data): + if hasattr(self, 'filter_nlm4_cancargs'): + data = getattr(self, 'filter_nlm4_cancargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.block is None: + raise TypeError('data.block == None') + self.pack_bool(data.block) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm4_lock(data.alock) + + def pack_nlm4_testargs(self, data): + if hasattr(self, 'filter_nlm4_testargs'): + data = getattr(self, 'filter_nlm4_testargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.exclusive is None: + raise TypeError('data.exclusive == None') + self.pack_bool(data.exclusive) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm4_lock(data.alock) + + def pack_nlm4_unlockargs(self, data): + if hasattr(self, 'filter_nlm4_unlockargs'): + data = getattr(self, 'filter_nlm4_unlockargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.alock is None: + raise TypeError('data.alock == None') + self.pack_nlm4_lock(data.alock) + + def pack_fsh4_mode(self, data): + if hasattr(self, 'filter_fsh4_mode'): + data = getattr(self, 'filter_fsh4_mode')(data) + if self.check_enum and data not in [const.FSM_DN, const.FSM_DR, const.FSM_DW, const.FSM_DRW]: + raise XDRError('value=%s not in enum fsh4_mode' % data) + self.pack_int(data) + + def pack_fsh4_access(self, data): + if hasattr(self, 'filter_fsh4_access'): + data = getattr(self, 'filter_fsh4_access')(data) + if self.check_enum and data not in [const.FSA_NONE, const.FSA_R, const.FSA_W, const.FSA_RW]: + raise XDRError('value=%s not in enum fsh4_access' % data) + self.pack_int(data) + + def pack_nlm4_share(self, data): + if hasattr(self, 'filter_nlm4_share'): + data = getattr(self, 'filter_nlm4_share')(data) + if data.caller_name is None: + raise TypeError('data.caller_name == None') + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + self.pack_string(data.caller_name) + if data.fh is None: + raise TypeError('data.fh == None') + self.pack_netobj(data.fh) + if data.oh is None: + raise TypeError('data.oh == None') + self.pack_netobj(data.oh) + if data.mode is None: + raise TypeError('data.mode == None') + self.pack_fsh4_mode(data.mode) + if data.access is None: + raise TypeError('data.access == None') + self.pack_fsh4_access(data.access) + + def pack_nlm4_shareargs(self, data): + if hasattr(self, 'filter_nlm4_shareargs'): + data = getattr(self, 'filter_nlm4_shareargs')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.share is None: + raise TypeError('data.share == None') + self.pack_nlm4_share(data.share) + if data.reclaim is None: + raise TypeError('data.reclaim == None') + self.pack_bool(data.reclaim) + + def pack_nlm4_shareres(self, data): + if hasattr(self, 'filter_nlm4_shareres'): + data = getattr(self, 'filter_nlm4_shareres')(data) + if data.cookie is None: + raise TypeError('data.cookie == None') + self.pack_netobj(data.cookie) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_nlm4_stats(data.stat) + if data.sequence is None: + raise TypeError('data.sequence == None') + self.pack_int32(data.sequence) + + def pack_nlm4_notify(self, data): + if hasattr(self, 'filter_nlm4_notify'): + data = getattr(self, 'filter_nlm4_notify')(data) + if data.name is None: + raise TypeError('data.name == None') + if len(data.name) > const.LM_MAXNAMELEN and self.check_array: + raise XDRError('array length too long for data.name') + self.pack_string(data.name) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int32(data.state) + +class NLM_PROTUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + unpack_int32 = unpack_int + + unpack_uint64 = unpack_uhyper + + def unpack_netobj(self): + data = self.unpack_opaque() + if len(data) > const.MAXNETOBJ_SZ and self.check_array: + raise XDRError('array length too long for data') + if hasattr(self, 'filter_netobj'): + data = getattr(self, 'filter_netobj')(data) + return data + + def unpack_nlm_stats(self): + data = self.unpack_int() + if self.check_enum and data not in [const.nlm_granted, const.nlm_denied, const.nlm_denied_nolocks, const.nlm_blocked, const.nlm_denied_grace_period, const.nlm_deadlck]: + raise XDRError('value=%s not in enum nlm_stats' % data) + if hasattr(self, 'filter_nlm_stats'): + data = getattr(self, 'filter_nlm_stats')(data) + return data + + def unpack_nlm_holder(self): + data = types.nlm_holder() + data.exclusive = self.unpack_bool() + data.svid = self.unpack_int() + data.oh = self.unpack_netobj() + data.l_offset = self.unpack_unsigned() + data.l_len = self.unpack_unsigned() + if hasattr(self, 'filter_nlm_holder'): + data = getattr(self, 'filter_nlm_holder')(data) + return data + + def unpack_nlm_testrply(self): + data = types.nlm_testrply() + data.stat = self.unpack_nlm_stats() + if data.stat == const.nlm_denied: + data.holder = self.unpack_nlm_holder() + else: + pass + if hasattr(self, 'filter_nlm_testrply'): + data = getattr(self, 'filter_nlm_testrply')(data) + return data + + def unpack_nlm_stat(self): + data = types.nlm_stat() + data.stat = self.unpack_nlm_stats() + if hasattr(self, 'filter_nlm_stat'): + data = getattr(self, 'filter_nlm_stat')(data) + return data + + def unpack_nlm_res(self): + data = types.nlm_res() + data.cookie = self.unpack_netobj() + data.stat = self.unpack_nlm_stat() + if hasattr(self, 'filter_nlm_res'): + data = getattr(self, 'filter_nlm_res')(data) + return data + + def unpack_nlm_testres(self): + data = types.nlm_testres() + data.cookie = self.unpack_netobj() + data.stat = self.unpack_nlm_testrply() + if hasattr(self, 'filter_nlm_testres'): + data = getattr(self, 'filter_nlm_testres')(data) + return data + + def unpack_nlm_lock(self): + data = types.nlm_lock() + data.caller_name = self.unpack_string() + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + data.fh = self.unpack_netobj() + data.oh = self.unpack_netobj() + data.svid = self.unpack_int() + data.l_offset = self.unpack_unsigned() + data.l_len = self.unpack_unsigned() + if hasattr(self, 'filter_nlm_lock'): + data = getattr(self, 'filter_nlm_lock')(data) + return data + + def unpack_nlm_lockargs(self): + data = types.nlm_lockargs() + data.cookie = self.unpack_netobj() + data.block = self.unpack_bool() + data.exclusive = self.unpack_bool() + data.alock = self.unpack_nlm_lock() + data.reclaim = self.unpack_bool() + data.state = self.unpack_int() + if hasattr(self, 'filter_nlm_lockargs'): + data = getattr(self, 'filter_nlm_lockargs')(data) + return data + + def unpack_nlm_cancargs(self): + data = types.nlm_cancargs() + data.cookie = self.unpack_netobj() + data.block = self.unpack_bool() + data.exclusive = self.unpack_bool() + data.alock = self.unpack_nlm_lock() + if hasattr(self, 'filter_nlm_cancargs'): + data = getattr(self, 'filter_nlm_cancargs')(data) + return data + + def unpack_nlm_testargs(self): + data = types.nlm_testargs() + data.cookie = self.unpack_netobj() + data.exclusive = self.unpack_bool() + data.alock = self.unpack_nlm_lock() + if hasattr(self, 'filter_nlm_testargs'): + data = getattr(self, 'filter_nlm_testargs')(data) + return data + + def unpack_nlm_unlockargs(self): + data = types.nlm_unlockargs() + data.cookie = self.unpack_netobj() + data.alock = self.unpack_nlm_lock() + if hasattr(self, 'filter_nlm_unlockargs'): + data = getattr(self, 'filter_nlm_unlockargs')(data) + return data + + def unpack_fsh_mode(self): + data = self.unpack_int() + if self.check_enum and data not in [const.fsm_DN, const.fsm_DR, const.fsm_DW, const.fsm_DRW]: + raise XDRError('value=%s not in enum fsh_mode' % data) + if hasattr(self, 'filter_fsh_mode'): + data = getattr(self, 'filter_fsh_mode')(data) + return data + + def unpack_fsh_access(self): + data = self.unpack_int() + if self.check_enum and data not in [const.fsa_NONE, const.fsa_R, const.fsa_W, const.fsa_RW]: + raise XDRError('value=%s not in enum fsh_access' % data) + if hasattr(self, 'filter_fsh_access'): + data = getattr(self, 'filter_fsh_access')(data) + return data + + def unpack_nlm_share(self): + data = types.nlm_share() + data.caller_name = self.unpack_string() + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + data.fh = self.unpack_netobj() + data.oh = self.unpack_netobj() + data.mode = self.unpack_fsh_mode() + data.access = self.unpack_fsh_access() + if hasattr(self, 'filter_nlm_share'): + data = getattr(self, 'filter_nlm_share')(data) + return data + + def unpack_nlm_shareargs(self): + data = types.nlm_shareargs() + data.cookie = self.unpack_netobj() + data.share = self.unpack_nlm_share() + data.reclaim = self.unpack_bool() + if hasattr(self, 'filter_nlm_shareargs'): + data = getattr(self, 'filter_nlm_shareargs')(data) + return data + + def unpack_nlm_shareres(self): + data = types.nlm_shareres() + data.cookie = self.unpack_netobj() + data.stat = self.unpack_nlm_stats() + data.sequence = self.unpack_int() + if hasattr(self, 'filter_nlm_shareres'): + data = getattr(self, 'filter_nlm_shareres')(data) + return data + + def unpack_nlm_notify(self): + data = types.nlm_notify() + data.name = self.unpack_string() + if len(data.name) > const.LM_MAXNAMELEN and self.check_array: + raise XDRError('array length too long for data.name') + data.state = self.unpack_int() + if hasattr(self, 'filter_nlm_notify'): + data = getattr(self, 'filter_nlm_notify')(data) + return data + + def unpack_nlm4_stats(self): + data = self.unpack_int() + if self.check_enum and data not in [const.NLM4_GRANTED, const.NLM4_DENIED, const.NLM4_DENIED_NOLOCKS, const.NLM4_BLOCKED, const.NLM4_DENIED_GRACE_PERIOD, const.NLM4_DEADLCK, const.NLM4_ROFS, const.NLM4_STALE_FH, const.NLM4_FBIG, const.NLM4_FAILED]: + raise XDRError('value=%s not in enum nlm4_stats' % data) + if hasattr(self, 'filter_nlm4_stats'): + data = getattr(self, 'filter_nlm4_stats')(data) + return data + + def unpack_nlm4_holder(self): + data = types.nlm4_holder() + data.exclusive = self.unpack_bool() + data.svid = self.unpack_int32() + data.oh = self.unpack_netobj() + data.l_offset = self.unpack_uint64() + data.l_len = self.unpack_uint64() + if hasattr(self, 'filter_nlm4_holder'): + data = getattr(self, 'filter_nlm4_holder')(data) + return data + + def unpack_nlm4_testrply(self): + data = types.nlm4_testrply() + data.stat = self.unpack_nlm4_stats() + if data.stat == const.NLM4_DENIED: + data.holder = self.unpack_nlm4_holder() + else: + pass + if hasattr(self, 'filter_nlm4_testrply'): + data = getattr(self, 'filter_nlm4_testrply')(data) + return data + + def unpack_nlm4_stat(self): + data = types.nlm4_stat() + data.stat = self.unpack_nlm4_stats() + if hasattr(self, 'filter_nlm4_stat'): + data = getattr(self, 'filter_nlm4_stat')(data) + return data + + def unpack_nlm4_res(self): + data = types.nlm4_res() + data.cookie = self.unpack_netobj() + data.stat = self.unpack_nlm4_stat() + if hasattr(self, 'filter_nlm4_res'): + data = getattr(self, 'filter_nlm4_res')(data) + return data + + def unpack_nlm4_testres(self): + data = types.nlm4_testres() + data.cookie = self.unpack_netobj() + data.stat = self.unpack_nlm4_testrply() + if hasattr(self, 'filter_nlm4_testres'): + data = getattr(self, 'filter_nlm4_testres')(data) + return data + + def unpack_nlm4_lock(self): + data = types.nlm4_lock() + data.caller_name = self.unpack_string() + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + data.fh = self.unpack_netobj() + data.oh = self.unpack_netobj() + data.svid = self.unpack_int32() + data.l_offset = self.unpack_uint64() + data.l_len = self.unpack_uint64() + if hasattr(self, 'filter_nlm4_lock'): + data = getattr(self, 'filter_nlm4_lock')(data) + return data + + def unpack_nlm4_lockargs(self): + data = types.nlm4_lockargs() + data.cookie = self.unpack_netobj() + data.block = self.unpack_bool() + data.exclusive = self.unpack_bool() + data.alock = self.unpack_nlm4_lock() + data.reclaim = self.unpack_bool() + data.state = self.unpack_int32() + if hasattr(self, 'filter_nlm4_lockargs'): + data = getattr(self, 'filter_nlm4_lockargs')(data) + return data + + def unpack_nlm4_cancargs(self): + data = types.nlm4_cancargs() + data.cookie = self.unpack_netobj() + data.block = self.unpack_bool() + data.exclusive = self.unpack_bool() + data.alock = self.unpack_nlm4_lock() + if hasattr(self, 'filter_nlm4_cancargs'): + data = getattr(self, 'filter_nlm4_cancargs')(data) + return data + + def unpack_nlm4_testargs(self): + data = types.nlm4_testargs() + data.cookie = self.unpack_netobj() + data.exclusive = self.unpack_bool() + data.alock = self.unpack_nlm4_lock() + if hasattr(self, 'filter_nlm4_testargs'): + data = getattr(self, 'filter_nlm4_testargs')(data) + return data + + def unpack_nlm4_unlockargs(self): + data = types.nlm4_unlockargs() + data.cookie = self.unpack_netobj() + data.alock = self.unpack_nlm4_lock() + if hasattr(self, 'filter_nlm4_unlockargs'): + data = getattr(self, 'filter_nlm4_unlockargs')(data) + return data + + def unpack_fsh4_mode(self): + data = self.unpack_int() + if self.check_enum and data not in [const.FSM_DN, const.FSM_DR, const.FSM_DW, const.FSM_DRW]: + raise XDRError('value=%s not in enum fsh4_mode' % data) + if hasattr(self, 'filter_fsh4_mode'): + data = getattr(self, 'filter_fsh4_mode')(data) + return data + + def unpack_fsh4_access(self): + data = self.unpack_int() + if self.check_enum and data not in [const.FSA_NONE, const.FSA_R, const.FSA_W, const.FSA_RW]: + raise XDRError('value=%s not in enum fsh4_access' % data) + if hasattr(self, 'filter_fsh4_access'): + data = getattr(self, 'filter_fsh4_access')(data) + return data + + def unpack_nlm4_share(self): + data = types.nlm4_share() + data.caller_name = self.unpack_string() + if len(data.caller_name) > const.LM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.caller_name') + data.fh = self.unpack_netobj() + data.oh = self.unpack_netobj() + data.mode = self.unpack_fsh4_mode() + data.access = self.unpack_fsh4_access() + if hasattr(self, 'filter_nlm4_share'): + data = getattr(self, 'filter_nlm4_share')(data) + return data + + def unpack_nlm4_shareargs(self): + data = types.nlm4_shareargs() + data.cookie = self.unpack_netobj() + data.share = self.unpack_nlm4_share() + data.reclaim = self.unpack_bool() + if hasattr(self, 'filter_nlm4_shareargs'): + data = getattr(self, 'filter_nlm4_shareargs')(data) + return data + + def unpack_nlm4_shareres(self): + data = types.nlm4_shareres() + data.cookie = self.unpack_netobj() + data.stat = self.unpack_nlm4_stats() + data.sequence = self.unpack_int32() + if hasattr(self, 'filter_nlm4_shareres'): + data = getattr(self, 'filter_nlm4_shareres')(data) + return data + + def unpack_nlm4_notify(self): + data = types.nlm4_notify() + data.name = self.unpack_string() + if len(data.name) > const.LM_MAXNAMELEN and self.check_array: + raise XDRError('array length too long for data.name') + data.state = self.unpack_int32() + if hasattr(self, 'filter_nlm4_notify'): + data = getattr(self, 'filter_nlm4_notify')(data) + return data + diff --git a/nfs3/lib/nlm/nlm_prot_type.py b/nfs3/lib/nlm/nlm_prot_type.py new file mode 100644 index 0000000..0b9645f --- /dev/null +++ b/nfs3/lib/nlm/nlm_prot_type.py @@ -0,0 +1,734 @@ +# Generated by rpcgen.py from nlm_prot.x on Wed Jun 24 11:38:48 2026 +import nlm_prot_const as const +class nlm_holder: + # XDR definition: + # struct nlm_holder { + # bool exclusive; + # int svid; + # netobj oh; + # unsigned l_offset; + # unsigned l_len; + # }; + def __init__(self, exclusive=None, svid=None, oh=None, l_offset=None, l_len=None): + self.exclusive = exclusive + self.svid = svid + self.oh = oh + self.l_offset = l_offset + self.l_len = l_len + + def __repr__(self): + out = [] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.svid is not None: + out += ['svid=%s' % repr(self.svid)] + if self.oh is not None: + out += ['oh=%s' % repr(self.oh)] + if self.l_offset is not None: + out += ['l_offset=%s' % repr(self.l_offset)] + if self.l_len is not None: + out += ['l_len=%s' % repr(self.l_len)] + return 'nlm_holder(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_testrply: + # XDR definition: + # union nlm_testrply switch(nlm_stats stat) { + # case nlm_denied: + # nlm_holder holder; + # default: + # void; + # }; + def __init__(self, stat=None, holder=None): + self.stat = stat + self.holder = holder + + switch = property(lambda s: {const.nlm_denied:s.holder,}.get(s.stat, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.nlm_stats.get(self.stat, self.stat)] + if self.holder is not None: + out += ['holder=%s' % repr(self.holder)] + return 'nlm_testrply(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_stat: + # XDR definition: + # struct nlm_stat { + # nlm_stats stat; + # }; + def __init__(self, stat=None): + self.stat = stat + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.nlm_stats.get(self.stat, self.stat)] + return 'nlm_stat(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_res: + # XDR definition: + # struct nlm_res { + # netobj cookie; + # nlm_stat stat; + # }; + def __init__(self, cookie=None, stat=None): + self.cookie = cookie + self.stat = stat + + def __getattr__(self, attr): + return getattr(self.stat, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.stat is not None: + out += ['stat=%s' % repr(self.stat)] + return 'nlm_res(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_testres: + # XDR definition: + # struct nlm_testres { + # netobj cookie; + # nlm_testrply stat; + # }; + def __init__(self, cookie=None, stat=None): + self.cookie = cookie + self.stat = stat + + def __getattr__(self, attr): + return getattr(self.stat, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.stat is not None: + out += ['stat=%s' % repr(self.stat)] + return 'nlm_testres(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_lock: + # XDR definition: + # struct nlm_lock { + # string caller_name; + # netobj fh; + # netobj oh; + # int svid; + # unsigned l_offset; + # unsigned l_len; + # }; + def __init__(self, caller_name=None, fh=None, oh=None, svid=None, l_offset=None, l_len=None): + self.caller_name = caller_name + self.fh = fh + self.oh = oh + self.svid = svid + self.l_offset = l_offset + self.l_len = l_len + + def __repr__(self): + out = [] + if self.caller_name is not None: + out += ['caller_name=%s' % repr(self.caller_name)] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.oh is not None: + out += ['oh=%s' % repr(self.oh)] + if self.svid is not None: + out += ['svid=%s' % repr(self.svid)] + if self.l_offset is not None: + out += ['l_offset=%s' % repr(self.l_offset)] + if self.l_len is not None: + out += ['l_len=%s' % repr(self.l_len)] + return 'nlm_lock(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_lockargs: + # XDR definition: + # struct nlm_lockargs { + # netobj cookie; + # bool block; + # bool exclusive; + # nlm_lock alock; + # bool reclaim; + # int state; + # }; + def __init__(self, cookie=None, block=None, exclusive=None, alock=None, reclaim=None, state=None): + self.cookie = cookie + self.block = block + self.exclusive = exclusive + self.alock = alock + self.reclaim = reclaim + self.state = state + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.block is not None: + out += ['block=%s' % repr(self.block)] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + if self.reclaim is not None: + out += ['reclaim=%s' % repr(self.reclaim)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'nlm_lockargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_cancargs: + # XDR definition: + # struct nlm_cancargs { + # netobj cookie; + # bool block; + # bool exclusive; + # nlm_lock alock; + # }; + def __init__(self, cookie=None, block=None, exclusive=None, alock=None): + self.cookie = cookie + self.block = block + self.exclusive = exclusive + self.alock = alock + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.block is not None: + out += ['block=%s' % repr(self.block)] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + return 'nlm_cancargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_testargs: + # XDR definition: + # struct nlm_testargs { + # netobj cookie; + # bool exclusive; + # nlm_lock alock; + # }; + def __init__(self, cookie=None, exclusive=None, alock=None): + self.cookie = cookie + self.exclusive = exclusive + self.alock = alock + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + return 'nlm_testargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_unlockargs: + # XDR definition: + # struct nlm_unlockargs { + # netobj cookie; + # nlm_lock alock; + # }; + def __init__(self, cookie=None, alock=None): + self.cookie = cookie + self.alock = alock + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + return 'nlm_unlockargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_share: + # XDR definition: + # struct nlm_share { + # string caller_name; + # netobj fh; + # netobj oh; + # fsh_mode mode; + # fsh_access access; + # }; + def __init__(self, caller_name=None, fh=None, oh=None, mode=None, access=None): + self.caller_name = caller_name + self.fh = fh + self.oh = oh + self.mode = mode + self.access = access + + def __repr__(self): + out = [] + if self.caller_name is not None: + out += ['caller_name=%s' % repr(self.caller_name)] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.oh is not None: + out += ['oh=%s' % repr(self.oh)] + if self.mode is not None: + out += ['mode=%s' % const.fsh_mode.get(self.mode, self.mode)] + if self.access is not None: + out += ['access=%s' % const.fsh_access.get(self.access, self.access)] + return 'nlm_share(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_shareargs: + # XDR definition: + # struct nlm_shareargs { + # netobj cookie; + # nlm_share share; + # bool reclaim; + # }; + def __init__(self, cookie=None, share=None, reclaim=None): + self.cookie = cookie + self.share = share + self.reclaim = reclaim + + def __getattr__(self, attr): + return getattr(self.share, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.share is not None: + out += ['share=%s' % repr(self.share)] + if self.reclaim is not None: + out += ['reclaim=%s' % repr(self.reclaim)] + return 'nlm_shareargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_shareres: + # XDR definition: + # struct nlm_shareres { + # netobj cookie; + # nlm_stats stat; + # int sequence; + # }; + def __init__(self, cookie=None, stat=None, sequence=None): + self.cookie = cookie + self.stat = stat + self.sequence = sequence + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.stat is not None: + out += ['stat=%s' % const.nlm_stats.get(self.stat, self.stat)] + if self.sequence is not None: + out += ['sequence=%s' % repr(self.sequence)] + return 'nlm_shareres(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm_notify: + # XDR definition: + # struct nlm_notify { + # string name; + # int state; + # }; + def __init__(self, name=None, state=None): + self.name = name + self.state = state + + def __repr__(self): + out = [] + if self.name is not None: + out += ['name=%s' % repr(self.name)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'nlm_notify(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_holder: + # XDR definition: + # struct nlm4_holder { + # bool exclusive; + # int32 svid; + # netobj oh; + # uint64 l_offset; + # uint64 l_len; + # }; + def __init__(self, exclusive=None, svid=None, oh=None, l_offset=None, l_len=None): + self.exclusive = exclusive + self.svid = svid + self.oh = oh + self.l_offset = l_offset + self.l_len = l_len + + def __repr__(self): + out = [] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.svid is not None: + out += ['svid=%s' % repr(self.svid)] + if self.oh is not None: + out += ['oh=%s' % repr(self.oh)] + if self.l_offset is not None: + out += ['l_offset=%s' % repr(self.l_offset)] + if self.l_len is not None: + out += ['l_len=%s' % repr(self.l_len)] + return 'nlm4_holder(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_testrply: + # XDR definition: + # union nlm4_testrply switch(nlm4_stats stat) { + # case NLM4_DENIED: + # nlm4_holder holder; + # default: + # void; + # }; + def __init__(self, stat=None, holder=None): + self.stat = stat + self.holder = holder + + switch = property(lambda s: {const.NLM4_DENIED:s.holder,}.get(s.stat, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.nlm4_stats.get(self.stat, self.stat)] + if self.holder is not None: + out += ['holder=%s' % repr(self.holder)] + return 'nlm4_testrply(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_stat: + # XDR definition: + # struct nlm4_stat { + # nlm4_stats stat; + # }; + def __init__(self, stat=None): + self.stat = stat + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.nlm4_stats.get(self.stat, self.stat)] + return 'nlm4_stat(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_res: + # XDR definition: + # struct nlm4_res { + # netobj cookie; + # nlm4_stat stat; + # }; + def __init__(self, cookie=None, stat=None): + self.cookie = cookie + self.stat = stat + + def __getattr__(self, attr): + return getattr(self.stat, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.stat is not None: + out += ['stat=%s' % repr(self.stat)] + return 'nlm4_res(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_testres: + # XDR definition: + # struct nlm4_testres { + # netobj cookie; + # nlm4_testrply stat; + # }; + def __init__(self, cookie=None, stat=None): + self.cookie = cookie + self.stat = stat + + def __getattr__(self, attr): + return getattr(self.stat, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.stat is not None: + out += ['stat=%s' % repr(self.stat)] + return 'nlm4_testres(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_lock: + # XDR definition: + # struct nlm4_lock { + # string caller_name; + # netobj fh; + # netobj oh; + # int32 svid; + # uint64 l_offset; + # uint64 l_len; + # }; + def __init__(self, caller_name=None, fh=None, oh=None, svid=None, l_offset=None, l_len=None): + self.caller_name = caller_name + self.fh = fh + self.oh = oh + self.svid = svid + self.l_offset = l_offset + self.l_len = l_len + + def __repr__(self): + out = [] + if self.caller_name is not None: + out += ['caller_name=%s' % repr(self.caller_name)] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.oh is not None: + out += ['oh=%s' % repr(self.oh)] + if self.svid is not None: + out += ['svid=%s' % repr(self.svid)] + if self.l_offset is not None: + out += ['l_offset=%s' % repr(self.l_offset)] + if self.l_len is not None: + out += ['l_len=%s' % repr(self.l_len)] + return 'nlm4_lock(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_lockargs: + # XDR definition: + # struct nlm4_lockargs { + # netobj cookie; + # bool block; + # bool exclusive; + # nlm4_lock alock; + # bool reclaim; + # int32 state; + # }; + def __init__(self, cookie=None, block=None, exclusive=None, alock=None, reclaim=None, state=None): + self.cookie = cookie + self.block = block + self.exclusive = exclusive + self.alock = alock + self.reclaim = reclaim + self.state = state + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.block is not None: + out += ['block=%s' % repr(self.block)] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + if self.reclaim is not None: + out += ['reclaim=%s' % repr(self.reclaim)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'nlm4_lockargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_cancargs: + # XDR definition: + # struct nlm4_cancargs { + # netobj cookie; + # bool block; + # bool exclusive; + # nlm4_lock alock; + # }; + def __init__(self, cookie=None, block=None, exclusive=None, alock=None): + self.cookie = cookie + self.block = block + self.exclusive = exclusive + self.alock = alock + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.block is not None: + out += ['block=%s' % repr(self.block)] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + return 'nlm4_cancargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_testargs: + # XDR definition: + # struct nlm4_testargs { + # netobj cookie; + # bool exclusive; + # nlm4_lock alock; + # }; + def __init__(self, cookie=None, exclusive=None, alock=None): + self.cookie = cookie + self.exclusive = exclusive + self.alock = alock + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.exclusive is not None: + out += ['exclusive=%s' % repr(self.exclusive)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + return 'nlm4_testargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_unlockargs: + # XDR definition: + # struct nlm4_unlockargs { + # netobj cookie; + # nlm4_lock alock; + # }; + def __init__(self, cookie=None, alock=None): + self.cookie = cookie + self.alock = alock + + def __getattr__(self, attr): + return getattr(self.alock, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.alock is not None: + out += ['alock=%s' % repr(self.alock)] + return 'nlm4_unlockargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_share: + # XDR definition: + # struct nlm4_share { + # string caller_name; + # netobj fh; + # netobj oh; + # fsh4_mode mode; + # fsh4_access access; + # }; + def __init__(self, caller_name=None, fh=None, oh=None, mode=None, access=None): + self.caller_name = caller_name + self.fh = fh + self.oh = oh + self.mode = mode + self.access = access + + def __repr__(self): + out = [] + if self.caller_name is not None: + out += ['caller_name=%s' % repr(self.caller_name)] + if self.fh is not None: + out += ['fh=%s' % repr(self.fh)] + if self.oh is not None: + out += ['oh=%s' % repr(self.oh)] + if self.mode is not None: + out += ['mode=%s' % const.fsh4_mode.get(self.mode, self.mode)] + if self.access is not None: + out += ['access=%s' % const.fsh4_access.get(self.access, self.access)] + return 'nlm4_share(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_shareargs: + # XDR definition: + # struct nlm4_shareargs { + # netobj cookie; + # nlm4_share share; + # bool reclaim; + # }; + def __init__(self, cookie=None, share=None, reclaim=None): + self.cookie = cookie + self.share = share + self.reclaim = reclaim + + def __getattr__(self, attr): + return getattr(self.share, attr) + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.share is not None: + out += ['share=%s' % repr(self.share)] + if self.reclaim is not None: + out += ['reclaim=%s' % repr(self.reclaim)] + return 'nlm4_shareargs(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_shareres: + # XDR definition: + # struct nlm4_shareres { + # netobj cookie; + # nlm4_stats stat; + # int32 sequence; + # }; + def __init__(self, cookie=None, stat=None, sequence=None): + self.cookie = cookie + self.stat = stat + self.sequence = sequence + + def __repr__(self): + out = [] + if self.cookie is not None: + out += ['cookie=%s' % repr(self.cookie)] + if self.stat is not None: + out += ['stat=%s' % const.nlm4_stats.get(self.stat, self.stat)] + if self.sequence is not None: + out += ['sequence=%s' % repr(self.sequence)] + return 'nlm4_shareres(%s)' % ', '.join(out) + __str__ = __repr__ + +class nlm4_notify: + # XDR definition: + # struct nlm4_notify { + # string name; + # int32 state; + # }; + def __init__(self, name=None, state=None): + self.name = name + self.state = state + + def __repr__(self): + out = [] + if self.name is not None: + out += ['name=%s' % repr(self.name)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'nlm4_notify(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/nlm/portmap.c b/nfs3/lib/nlm/portmap.c new file mode 100644 index 0000000..5b5ab37 --- /dev/null +++ b/nfs3/lib/nlm/portmap.c @@ -0,0 +1,58 @@ +#include +#include +#include + +static PyObject * portmap_set(PyObject *self, PyObject *args) +{ + unsigned long program, version; + int protocol; + unsigned short port; + + if (!PyArg_ParseTuple(args, "kkiH:set", + &program, &version, &protocol, &port)) + return NULL; + // Tai: removed the unset here so we can bind both TCP and UDP + pmap_set(program, version, protocol, port); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * portmap_unset(PyObject *self, PyObject *args) +{ + unsigned long program, version; + struct netconfig *nconf; + + if (!PyArg_ParseTuple(args, "kk:unset", + &program, &version)) + return NULL; + + pmap_unset(program, version); + nconf = getnetconfigent("udp6"); + if (nconf != NULL) { + rpcb_unset((rpcprog_t)program, (rpcvers_t)version, nconf); + freenetconfigent(nconf); + } + nconf = getnetconfigent("tcp6"); + if (nconf != NULL) { + rpcb_unset((rpcprog_t)program, (rpcvers_t)version, nconf); + freenetconfigent(nconf); + } + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef PortmapMethods[] = { + {"set", portmap_set, METH_VARARGS, + "Set an entry in the portmapper."}, + {"unset", portmap_unset, METH_VARARGS, + "Unset an entry in the portmapper."}, + {NULL, NULL, 0, NULL} +}; + +void initportmap(void) +{ + (void) Py_InitModule("portmap", PortmapMethods); +} + diff --git a/nfs3/lib/nsm/__init__.py b/nfs3/lib/nsm/__init__.py new file mode 100644 index 0000000..bf1f324 --- /dev/null +++ b/nfs3/lib/nsm/__init__.py @@ -0,0 +1,4 @@ +import os as _os, sys as _sys +# Python 3: make the package directory importable so the historic bare +# (implicit-relative) imports such as ``import nsm_const`` keep working. +_sys.path.insert(1, _os.path.dirname(_os.path.abspath(__file__))) diff --git a/nfs3/lib/nsm/nsm.py b/nfs3/lib/nsm/nsm.py new file mode 100644 index 0000000..2e2d57f --- /dev/null +++ b/nfs3/lib/nsm/nsm.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python +# nsm.py - NSM protocol library for python + +import rpc +from xdrlib import Error as XDRError +from nsm_const import * +from nsm_const import res as nsm_stats +from nsm_type import * +from nsm_pack import * +from testmod import WarningException, FailureException + +AuthSys = rpc.SecAuthSys(0,'jupiter',103558,100,[]) + +class NSMClient(rpc.RPCClient): + def __init__(self, id, host='localhost', port=300, sec_list=[AuthSys], + opts = None): + self.ipv6 = getattr(opts, "ipv6", False) + self.packer = NSMPacker() + self.unpacker = NSMUnpacker('') + self.id = id + self.opts = opts + uselowport = True + rpc.RPCClient.__init__(self, host, port, program=SM_PROG, + version=1, sec_list=sec_list, uselowport=uselowport, + ipv6=self.ipv6) + self.server_address = (host,port) + + def nsm_pack(self, procedure, data): + p = self.packer + if procedure == SM_NULL: + pass + elif procedure == SM_STAT: + p.pack_sm_name(data) + elif procedure == SM_MON: + p.pack_mon(data) + elif procedure == SM_UNMON: + p.pack_mon_id(data) + elif procedure == SM_UNMON_ALL: + p.pack_my_id(data) + elif procedure == SM_SIMU_CRASH: + pass + elif procedure == SM_NOTIFY: + p.pack_stat_chge(data) + else: + raise XDRError('bad switch=%s' % procedure) + + def nsm_unpack(self, procedure): + un_p = self.unpacker + + if procedure == SM_NULL: + return + elif procedure == SM_STAT: + return un_p.unpack_sm_stat_res() + elif procedure == SM_MON: + return un_p.unpack_sm_stat_res() + elif procedure == SM_UNMON: + return un_p.unpack_sm_stat() + elif procedure == SM_UNMON_ALL: + return un_p.unpack_sm_stat() + elif procedure == SM_SIMU_CRASH: + return + elif procedure == SM_NOTIFY: + return + + def nsm_call(self, procedure, data=''): + p = self.packer + un_p = self.unpacker + + # Pack + p.reset() + self.nsm_pack(procedure, data) + + # Call + res = self.call(procedure, p.get_buffer()) + + # Unpack + un_p.reset(res) + res = self.nsm_unpack(procedure) + un_p.done() + + return res + + def null(self): + return self.nsm_call(SM_NULL, None) + + def mon(self, mon_name=''): + arg_list=mon(mon_id(mon_name, my_id(self.id, 100024, 1, SM_MON)),'') + return self.nsm_call(SM_MON,arg_list) + + def notify(self, mon_name='', state=1): + arg_list=stat_chge(mon_name,state) + return self.nsm_call(SM_NOTIFY,arg_list) + + def simu_crash(self): + return self.nsm_call(SM_SIMU_CRASH, None) + + def stat(self, mon_name=''): + return self.nsm_call(SM_STAT,sm_name(mon_name)) + + def unmon(self, mon_name=''): + return self.nsm_call(SM_UNMON,mon_id(mon_name, my_id(self.id, 100024, + 1, SM_UNMON))) + + def unmon_all(self): + return self.nsm_call(SM_UNMON_ALL,my_id(self.id, 100024, 1, + SM_UNMON_ALL)) +############################### + +def nsmcheck(res, stat=STAT_SUCC, msg=None, warnlist=[], state=None, state_only=False): + badstate = False + if state and (state_only or res.res_stat != stat): + if state != "up" and state != "down": + raise RuntimeError("State must be \"up\" or \"down\"") + if state == "up" and res.state % 2 != 0: + badstate = True + elif state == "down" and res.state % 2 == 0: + badstate = True + if not badstate and (state_only or res.res_stat == stat): + return + if type(stat) is str: + raise RuntimeError("No 'msg=' in front of check's string arg") + + if not badstate: + desired = nsm_stats[stat] + received = nsm_stats[res.res_stat] + else: + desired = state + received = {"up":"down", "down":"up"}[state] + received += " (" + str(res.state) + ")" + if msg: + msg = "%s should return %s, instead got %s" % (msg, desired, received) + + if not state_only: + if res.res_stat in warnlist: + raise WarningException(msg) + else: + raise FailureException(msg) + raise FailureException(msg) diff --git a/nfs3/lib/nsm/nsm.x b/nfs3/lib/nsm/nsm.x new file mode 100644 index 0000000..2ae430c --- /dev/null +++ b/nfs3/lib/nsm/nsm.x @@ -0,0 +1,73 @@ +/* $Id: nsm.x,v 1.2 2006/05/11 21:58:59 dancy Exp $ + * modified by Tai Horgan for consumption by pynfs + */ + +/* + * This defines the maximum length of the string + * identifying the caller. + */ +const SM_MAXSTRLEN = 1024; + +struct sm_name { + string mon_name; +}; + +enum res { + STAT_SUCC = 0, /* NSM agrees to monitor. */ + STAT_FAIL = 1 /* NSM cannot monitor. */ +}; + +struct sm_stat_res { + res res_stat; + int state; +}; + +struct sm_stat { + int state; /* state number of NSM */ +}; + +/* modified by Tai */ +struct my_id{ + string my_name; /* hostname */ + int my_prog; /* RPC program number */ + int my_vers; /* program version number */ + int my_proc; /* procedure number */ +}; +/* modified by Tai */ +struct mon_id{ + string mon_name; /* name of the host to be monitored */ + my_id my_id; +}; + +struct mon { + mon_id mon_id; + opaque priv[16]; /* private information */ +}; + +struct stat_chge { + string mon_name; + int state; +}; + +struct nsm_callback_status { + string mon_name; + int state; + opaque priv[16]; /* for private information */ +}; + +/* + * Protocol description for the NSM program. + */ + +program SM_PROG { + version SM_VERS { + void SM_NULL(void) = 0; + sm_stat_res SM_STAT(sm_name) = 1; + sm_stat_res SM_MON(mon) = 2; + sm_stat SM_UNMON(mon_id) = 3; + sm_stat SM_UNMON_ALL(my_id) = 4; + void SM_SIMU_CRASH(void) = 5; + void SM_NOTIFY(stat_chge) = 6; + } = 1; +} = 100024; + diff --git a/nfs3/lib/nsm/nsm_const.py b/nfs3/lib/nsm/nsm_const.py new file mode 100644 index 0000000..825a9b2 --- /dev/null +++ b/nfs3/lib/nsm/nsm_const.py @@ -0,0 +1,17 @@ +# Generated by rpcgen.py from nsm.x on Wed Jun 24 11:38:48 2026 +SM_NULL = 0 +SM_STAT = 1 +SM_MON = 2 +SM_UNMON = 3 +SM_UNMON_ALL = 4 +SM_SIMU_CRASH = 5 +SM_NOTIFY = 6 +SM_MAXSTRLEN = 1024 +STAT_SUCC = 0 +STAT_FAIL = 1 +res = { + 0 : 'STAT_SUCC', + 1 : 'STAT_FAIL', +} +SM_PROG = 100024 +SM_VERS = 1 diff --git a/nfs3/lib/nsm/nsm_pack.py b/nfs3/lib/nsm/nsm_pack.py new file mode 100644 index 0000000..fbe4249 --- /dev/null +++ b/nfs3/lib/nsm/nsm_pack.py @@ -0,0 +1,242 @@ +# Generated by rpcgen.py from nsm.x on Wed Jun 24 11:38:48 2026 +import nsm_const as const +import nsm_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class NSMPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + def pack_sm_name(self, data): + if hasattr(self, 'filter_sm_name'): + data = getattr(self, 'filter_sm_name')(data) + if data.mon_name is None: + raise TypeError('data.mon_name == None') + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + self.pack_string(data.mon_name) + + def pack_res(self, data): + if hasattr(self, 'filter_res'): + data = getattr(self, 'filter_res')(data) + if self.check_enum and data not in [const.STAT_SUCC, const.STAT_FAIL]: + raise XDRError('value=%s not in enum res' % data) + self.pack_int(data) + + def pack_sm_stat_res(self, data): + if hasattr(self, 'filter_sm_stat_res'): + data = getattr(self, 'filter_sm_stat_res')(data) + if data.res_stat is None: + raise TypeError('data.res_stat == None') + self.pack_res(data.res_stat) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int(data.state) + + def pack_sm_stat(self, data): + if hasattr(self, 'filter_sm_stat'): + data = getattr(self, 'filter_sm_stat')(data) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int(data.state) + + def pack_my_id(self, data): + if hasattr(self, 'filter_my_id'): + data = getattr(self, 'filter_my_id')(data) + if data.my_name is None: + raise TypeError('data.my_name == None') + if len(data.my_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.my_name') + self.pack_string(data.my_name) + if data.my_prog is None: + raise TypeError('data.my_prog == None') + self.pack_int(data.my_prog) + if data.my_vers is None: + raise TypeError('data.my_vers == None') + self.pack_int(data.my_vers) + if data.my_proc is None: + raise TypeError('data.my_proc == None') + self.pack_int(data.my_proc) + + def pack_mon_id(self, data): + if hasattr(self, 'filter_mon_id'): + data = getattr(self, 'filter_mon_id')(data) + if data.mon_name is None: + raise TypeError('data.mon_name == None') + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + self.pack_string(data.mon_name) + if data.my_id is None: + raise TypeError('data.my_id == None') + self.pack_my_id(data.my_id) + + def pack_mon(self, data): + if hasattr(self, 'filter_mon'): + data = getattr(self, 'filter_mon')(data) + if data.mon_id is None: + raise TypeError('data.mon_id == None') + self.pack_mon_id(data.mon_id) + if data.priv is None: + raise TypeError('data.priv == None') + self.pack_fopaque(16, data.priv) + + def pack_stat_chge(self, data): + if hasattr(self, 'filter_stat_chge'): + data = getattr(self, 'filter_stat_chge')(data) + if data.mon_name is None: + raise TypeError('data.mon_name == None') + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + self.pack_string(data.mon_name) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int(data.state) + + def pack_nsm_callback_status(self, data): + if hasattr(self, 'filter_nsm_callback_status'): + data = getattr(self, 'filter_nsm_callback_status')(data) + if data.mon_name is None: + raise TypeError('data.mon_name == None') + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + self.pack_string(data.mon_name) + if data.state is None: + raise TypeError('data.state == None') + self.pack_int(data.state) + if data.priv is None: + raise TypeError('data.priv == None') + self.pack_fopaque(16, data.priv) + +class NSMUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + def unpack_sm_name(self): + data = types.sm_name() + data.mon_name = self.unpack_string() + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + if hasattr(self, 'filter_sm_name'): + data = getattr(self, 'filter_sm_name')(data) + return data + + def unpack_res(self): + data = self.unpack_int() + if self.check_enum and data not in [const.STAT_SUCC, const.STAT_FAIL]: + raise XDRError('value=%s not in enum res' % data) + if hasattr(self, 'filter_res'): + data = getattr(self, 'filter_res')(data) + return data + + def unpack_sm_stat_res(self): + data = types.sm_stat_res() + data.res_stat = self.unpack_res() + data.state = self.unpack_int() + if hasattr(self, 'filter_sm_stat_res'): + data = getattr(self, 'filter_sm_stat_res')(data) + return data + + def unpack_sm_stat(self): + data = types.sm_stat() + data.state = self.unpack_int() + if hasattr(self, 'filter_sm_stat'): + data = getattr(self, 'filter_sm_stat')(data) + return data + + def unpack_my_id(self): + data = types.my_id() + data.my_name = self.unpack_string() + if len(data.my_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.my_name') + data.my_prog = self.unpack_int() + data.my_vers = self.unpack_int() + data.my_proc = self.unpack_int() + if hasattr(self, 'filter_my_id'): + data = getattr(self, 'filter_my_id')(data) + return data + + def unpack_mon_id(self): + data = types.mon_id() + data.mon_name = self.unpack_string() + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + data.my_id = self.unpack_my_id() + if hasattr(self, 'filter_mon_id'): + data = getattr(self, 'filter_mon_id')(data) + return data + + def unpack_mon(self): + data = types.mon() + data.mon_id = self.unpack_mon_id() + data.priv = self.unpack_fopaque(16) + if hasattr(self, 'filter_mon'): + data = getattr(self, 'filter_mon')(data) + return data + + def unpack_stat_chge(self): + data = types.stat_chge() + data.mon_name = self.unpack_string() + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + data.state = self.unpack_int() + if hasattr(self, 'filter_stat_chge'): + data = getattr(self, 'filter_stat_chge')(data) + return data + + def unpack_nsm_callback_status(self): + data = types.nsm_callback_status() + data.mon_name = self.unpack_string() + if len(data.mon_name) > const.SM_MAXSTRLEN and self.check_array: + raise XDRError('array length too long for data.mon_name') + data.state = self.unpack_int() + data.priv = self.unpack_fopaque(16) + if hasattr(self, 'filter_nsm_callback_status'): + data = getattr(self, 'filter_nsm_callback_status')(data) + return data + diff --git a/nfs3/lib/nsm/nsm_type.py b/nfs3/lib/nsm/nsm_type.py new file mode 100644 index 0000000..b294ff0 --- /dev/null +++ b/nfs3/lib/nsm/nsm_type.py @@ -0,0 +1,164 @@ +# Generated by rpcgen.py from nsm.x on Wed Jun 24 11:38:48 2026 +import nsm_const as const +class sm_name: + # XDR definition: + # struct sm_name { + # string mon_name; + # }; + def __init__(self, mon_name=None): + self.mon_name = mon_name + + def __repr__(self): + out = [] + if self.mon_name is not None: + out += ['mon_name=%s' % repr(self.mon_name)] + return 'sm_name(%s)' % ', '.join(out) + __str__ = __repr__ + +class sm_stat_res: + # XDR definition: + # struct sm_stat_res { + # res res_stat; + # int state; + # }; + def __init__(self, res_stat=None, state=None): + self.res_stat = res_stat + self.state = state + + def __repr__(self): + out = [] + if self.res_stat is not None: + out += ['res_stat=%s' % const.res.get(self.res_stat, self.res_stat)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'sm_stat_res(%s)' % ', '.join(out) + __str__ = __repr__ + +class sm_stat: + # XDR definition: + # struct sm_stat { + # int state; + # }; + def __init__(self, state=None): + self.state = state + + def __repr__(self): + out = [] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'sm_stat(%s)' % ', '.join(out) + __str__ = __repr__ + +class my_id: + # XDR definition: + # struct my_id { + # string my_name; + # int my_prog; + # int my_vers; + # int my_proc; + # }; + def __init__(self, my_name=None, my_prog=None, my_vers=None, my_proc=None): + self.my_name = my_name + self.my_prog = my_prog + self.my_vers = my_vers + self.my_proc = my_proc + + def __repr__(self): + out = [] + if self.my_name is not None: + out += ['my_name=%s' % repr(self.my_name)] + if self.my_prog is not None: + out += ['my_prog=%s' % repr(self.my_prog)] + if self.my_vers is not None: + out += ['my_vers=%s' % repr(self.my_vers)] + if self.my_proc is not None: + out += ['my_proc=%s' % repr(self.my_proc)] + return 'my_id(%s)' % ', '.join(out) + __str__ = __repr__ + +class mon_id: + # XDR definition: + # struct mon_id { + # string mon_name; + # my_id my_id; + # }; + def __init__(self, mon_name=None, my_id=None): + self.mon_name = mon_name + self.my_id = my_id + + def __getattr__(self, attr): + return getattr(self.my_id, attr) + + def __repr__(self): + out = [] + if self.mon_name is not None: + out += ['mon_name=%s' % repr(self.mon_name)] + if self.my_id is not None: + out += ['my_id=%s' % repr(self.my_id)] + return 'mon_id(%s)' % ', '.join(out) + __str__ = __repr__ + +class mon: + # XDR definition: + # struct mon { + # mon_id mon_id; + # opaque priv[16]; + # }; + def __init__(self, mon_id=None, priv=None): + self.mon_id = mon_id + self.priv = priv + + def __getattr__(self, attr): + return getattr(self.mon_id, attr) + + def __repr__(self): + out = [] + if self.mon_id is not None: + out += ['mon_id=%s' % repr(self.mon_id)] + if self.priv is not None: + out += ['priv=%s' % repr(self.priv)] + return 'mon(%s)' % ', '.join(out) + __str__ = __repr__ + +class stat_chge: + # XDR definition: + # struct stat_chge { + # string mon_name; + # int state; + # }; + def __init__(self, mon_name=None, state=None): + self.mon_name = mon_name + self.state = state + + def __repr__(self): + out = [] + if self.mon_name is not None: + out += ['mon_name=%s' % repr(self.mon_name)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + return 'stat_chge(%s)' % ', '.join(out) + __str__ = __repr__ + +class nsm_callback_status: + # XDR definition: + # struct nsm_callback_status { + # string mon_name; + # int state; + # opaque priv[16]; + # }; + def __init__(self, mon_name=None, state=None, priv=None): + self.mon_name = mon_name + self.state = state + self.priv = priv + + def __repr__(self): + out = [] + if self.mon_name is not None: + out += ['mon_name=%s' % repr(self.mon_name)] + if self.state is not None: + out += ['state=%s' % repr(self.state)] + if self.priv is not None: + out += ['priv=%s' % repr(self.priv)] + return 'nsm_callback_status(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/rpc/__init__.py b/nfs3/lib/rpc/__init__.py new file mode 100644 index 0000000..1b45104 --- /dev/null +++ b/nfs3/lib/rpc/__init__.py @@ -0,0 +1,8 @@ +import os as _os, sys as _sys +# Python 3: make the package directory importable so the historic bare +# (implicit-relative) imports such as ``from rpc_const import *`` keep working. +_sys.path.insert(1, _os.path.dirname(_os.path.abspath(__file__))) + +from .rpc import * + +__all__ = ['rpcsec', 'rpc_const.py', 'rpc_type.py'] diff --git a/nfs3/lib/rpc/rpc.py b/nfs3/lib/rpc/rpc.py new file mode 100644 index 0000000..70698f1 --- /dev/null +++ b/nfs3/lib/rpc/rpc.py @@ -0,0 +1,733 @@ +# rpc.py - based on RFC 1831 +# +# Requires python 2.3 +# +# Written by Fred Isaman +# Copyright (C) 2004 University of Michigan, Center for +# Information Technology Integration +# + +import struct +import xdrlib +import socket +import select +import threading +import errno +import random + +from rpc_const import * +from rpc_type import * +import rpc_pack + +# Import security flavors and store valid ones +from .rpcsec.sec_auth_none import SecAuthNone +from .rpcsec.sec_auth_sys import SecAuthSys + +supported = {'none': SecAuthNone, + 'sys': SecAuthSys} +try: + from .rpcsec.sec_auth_gss import SecAuthGss + + supported['gss'] = SecAuthGss +except ImportError: + pass + +RPCVERSION = 2 + +if hasattr(select, "poll"): + _stdmask = select.POLLERR | select.POLLHUP | select.POLLNVAL + _readmask = select.POLLIN | _stdmask + _writemask = select.POLLOUT | _stdmask + _bothmask = select.POLLOUT | select.POLLIN | _stdmask +else: + _readmask = 1 + _writemask = 2 + _bothmask = 3 + select.POLLIN = 1 + select.POLLOUT = 2 + select.POLLERR = 4 + select.POLLHUP = select.POLLNVAL = 0 + + + class my_poll(object): + """Emulate select.poll using select.select""" + + def __init__(self): + self._in = [] + self._out = [] + self._err = [] + + def register(self, fd, eventmask=_bothmask): + if type(fd) != int: + fd = fd.fileno() + self.unregister(fd) + if eventmask & _readmask: + self._in.append(fd) + if eventmask & _writemask: + self._out.append(fd) + self._err.append(fd) + + def unregister(self, fd): + if type(fd) != int: + fd = fd.fileno() + # Remove + if fd in self._in: self._in.remove(fd) + if fd in self._out: self._out.remove(fd) + if fd in self._err: self._err.remove(fd) + + def poll(self, timeout=None): + # STUB - deal with timeout + read, write, err = select.select(self._in, self._out, self._err) + list = [] + for fd in read: + mask = select.POLLIN + if fd in write: + mask |= select.POLLOUT + write.remove(fd) + if fd in err: + mask |= select.POLLERR + err.remove(fd) + list.append((fd, mask)) + for fd in write: + mask = select.POLLOUT + if fd in err: + mask |= select.POLLERR + err.remove(fd) + list.append((fd, mask)) + for fd in err: + mask = select.POLLOUT + list.append((fd, mask)) + return list + + + select.poll = my_poll + + +class RPCError(Exception): + pass + + +class RPCAcceptError(RPCError): + def __init__(self, a): + self.verf = a.verf + a = a.reply_data + self.stat = a.stat + if self.stat == PROG_MISMATCH: + self.low = a.mismatch_info.low + self.high = a.mismatch_info.high + + def __str__(self): + if self.stat == PROG_MISMATCH: + return "RPCError: MSG_ACCEPTED: %s [%i,%i]" % \ + (accept_stat.get(self.stat, self.stat), + self.low, self.high) + else: + return "RPCError: MSG_ACCEPTED: %s" % \ + accept_stat.get(self.stat, self.stat) + + +class RPCDeniedError(RPCError): + def __init__(self, r): + self.stat = r.stat + if self.stat == RPC_MISMATCH: + self.low = r.mismatch_info.low + self.high = r.mismatch_info.high + elif self.stat == AUTH_ERROR: + self.astat = r.astat + + def __str__(self): + if self.stat == RPC_MISMATCH: + return "RPCError: MSG_DENIED: RPC_MISMATCH [%i,%i]" % \ + (self.low, self.high) + else: + return "RPCError: MSG_DENIED: AUTH_ERROR: %s" % \ + auth_stat.get(self.astat, self.astat) + + +################################################### + +# Add some record marking functions to sockets +# FRED - is there a cleaner (class based) way to do this? + +def _recv_all(self, n): + """Receive n bytes, or raise an error""" + data = b"" + while n > 0: + newdata = self.recv(n) + count = len(newdata) + if not count: + raise socket.error("Connection closed") + data += newdata + n -= count + return data + + +def _recv_record(self): + """Receive data sent using record marking standard""" + last = False + data = b"" + while not last: + rec_mark = self.recv_all(4) + count = struct.unpack('>I', rec_mark)[0] + last = count & 0x80000000 + if last: + count &= 0x7fffffff + data += self.recv_all(count) + return data + + +def _send_record(self, data, chunksize=2048): + """Send data using record marking standard""" + dlen = len(data) + i = last = 0 + while not last: + chunk = data[i:i + chunksize] + i += chunksize + if i >= dlen: + last = 0x80000000 + mark = struct.pack('>I', last | len(chunk)) + self.sendall(mark + chunk) + + +socket.socket.recv_all = _recv_all +socket.socket.recv_record = _recv_record +socket.socket.send_record = _send_record + + +################################################# + +class RPCClient(object): + def __init__(self, host='localhost', port=51423, + program=None, version=None, sec_list=None, timeout=15.0, + uselowport=False, usenonrandomxid=False, ipv6=False, sym_resend=False): + self.debug = 0 + t = threading.currentThread() + self.lock = threading.Lock() + self.remotehost = host + self.remoteport = port + self.timeout = timeout + self.uselowport = uselowport + self._socket = {} + self.ipv6 = ipv6 + self.getsocket() # init socket, is this needed here? + self.ipaddress = self.socket.getsockname()[0] + self._rpcpacker = {t: rpc_pack.RPCPacker()} + self._rpcunpacker = {t: rpc_pack.RPCUnpacker('')} + self.default_prog = program + self.default_vers = version + self.sym_resend = sym_resend + + if usenonrandomxid: + self.xid = 0 + else: + # Use pseudo random XID, to avoid inadvertant replay-cache + # problems (when running pynfs multiple times in a row.) + self.xid = random.randint(0, 0xFFFFFFFF) + + self._xidlist = {} + if sec_list is None: + sec_list = [SecAuthNone()] + self.sec_list = sec_list + self._init_security(self.sec_list) # Note this can make calls + self.security = sec_list[0] + + def _init_security(self, list): + # Each element of list must have functions: + # initialize, secure_data, make_cred, make_verf + for flavor in list: + self.security = flavor + flavor.initialize(self) + + def bindsocket(self, sock, port=853): + # This is necessary because otherwise will default to an insecure + # port, which the server will reject unless it has the 'insecure' + # option set + while port < 1024: + try: + sock.bind(('', port)) + return + except socket.error as why: + if why.errno == errno.EADDRINUSE: + port += 1 + else: + print("Could not use low port") + return + + def getsocket(self): + t = threading.currentThread() + self.lock.acquire() + try: + if t in self._socket: + out = self._socket[t] + else: + if not self.ipv6: + out = self._socket[t] = socket.socket(socket.AF_INET, + socket.SOCK_STREAM) + else: + out = self._socket[t] = socket.socket(socket.AF_INET6, + socket.SOCK_STREAM) + if self.uselowport: + self.bindsocket(out) + out.connect((self.remotehost, self.remoteport)) + out.settimeout(self.timeout) + except: + raise + finally: + self.lock.release() + return out + + socket = property(getsocket) + + def getrpcpacker(self): + t = threading.currentThread() + self.lock.acquire() + if t in self._rpcpacker: + out = self._rpcpacker[t] + else: + out = self._rpcpacker[t] = rpc_pack.RPCPacker() + self._rpcunpacker[t] = rpc_pack.RPCUnpacker('') + self.lock.release() + return out + + def getrpcunpacker(self): + t = threading.currentThread() + self.lock.acquire() + if t in self._rpcunpacker: + out = self._rpcunpacker[t] + else: + self._rpcpacker[t] = gss_pack.GSSPacker() + out = self._rpcunpacker[t] = gss_pack.GSSUnpacker('') + self.lock.release() + return out + + class XidCache(object): + def __init__(self, header, data, cred=None, proc=1): + self.header = header # packed call header + self.data = data # secured call data + self.cred = cred # unpacked opaque_auth in header + self.rhead = None # unpacked reply header + self.rdata = None # unsecured reply data + self.proc = proc # unpacked proc from header + + def __repr__(self): + return "%s\n%s" % (self.header, self.data) + + def add_outstanding_xids(self, xid, header, data, cred, proc): + t = threading.currentThread() + self.lock.acquire() + if t in self._xidlist: + if xid in self._xidlist[t]: raise + self._xidlist[t][xid] = self.XidCache(header, data, cred, proc) + else: + self._xidlist[t] = {xid: self.XidCache(header, data, cred, proc)} + self.lock.release() + + def get_outstanding_xids(self): + t = threading.currentThread() + self.lock.acquire() + out = self._xidlist[t] + self.lock.release() + return out + + def reconnect(self): + t = threading.currentThread() + self.lock.acquire() + try: + self._socket[t].close() + if not self.ipv6: + out = self._socket[t] = socket.socket(socket.AF_INET, + socket.SOCK_STREAM) + else: + out = self._socket[t] = socket.socket(socket.AF_INET6, + socket.SOCK_STREAM) + # out.bind + out.connect((self.remotehost, self.remoteport)) + out.settimeout(self.timeout) + except: + raise + finally: + self.lock.release() + return out + + def send(self, procedure, data=b'', program=None, version=None): + """Send an RPC call to the server + + Takes as input packed arguments + """ + if program is None: program = self.default_prog + if version is None: version = self.default_vers + if program is None or version is None: + raise RPCError("Bad program/version: %s/%s" % (program, version)) + + if not self.sym_resend: + xid = self.get_new_xid() + else: + xid = self.xid + print(("Clinet re-sending request with xid={}".format(self.xid))) + header, cred = self.get_call_header(xid, program, version, procedure) + data = self.security.secure_data(data, cred) + try: + if self.debug: print("send %i" % xid) + self.socket.send_record(header + data) + except socket.timeout: + raise + except socket.error as e: + print("Got error:", e) + if self.debug: print("resend", xid) + try: + self.reconnect().send_record(header + data) + except socket.error: + self.reconnect() + raise + self.add_outstanding_xids(xid, header, data, cred, procedure) + return xid + + def listen(self, xid): + # Exists (per thread) list of outstanding xid/seq pairs + # If xid not on list, return error. + # Listen until get reply with given xid. Cache others received + # on list. Return error if get one not on list. + if self.debug: print("listen", xid) + list = self.get_outstanding_xids() + if xid not in list: + raise + done = False + rdata = list[xid].rdata + if rdata is not None: + rhead = list[xid].rhead + done = True + while not done: + try: + reply = self.socket.recv_record() + except socket.timeout: + raise + except socket.error as e: + print("Got error:", e) + if self.debug: print("relisten", xid) + try: + s = self.reconnect() + s.send_record(list[xid].header + list[xid].data) + reply = s.recv_record() + except socket.error: + self.reconnect() + raise + p = self.getrpcunpacker() + p.reset(reply) + rhead = p.unpack_rpc_msg() + rxid = rhead.xid + if rxid not in list: + raise RPCError("Got reply xid %i, expected %i" % \ + (rxid, xid)) + if list[rxid].rhead is not None: + raise RPCError("Duplicated reply xid %i" % rxid) + rdata = reply[p.get_position():] + try: + # BUG?, should use rhead credentials? + # This conditional is gss specific code that should be hidden + if rhead.rbody.stat == MSG_ACCEPTED and \ + rhead.areply.reply_data.stat == SUCCESS: + rdata = self.security.unsecure_data(rdata, list[rxid].cred) + except: + if 0: + # need for servers that don't add gss checksum to errors + pass + else: + raise + list[rxid].rhead = rhead + list[rxid].rdata = rdata + if rxid == xid: + done = True + out = list[xid] + del list[xid] + self.check_reply(out) + return rdata + + def call(self, procedure, data=b'', program=None, version=None): + """Make an RPC call to the server + + Takes as input packed arguments + Returns packed results + """ + xid = self.send(procedure, data, program, version) + return self.listen(xid) + + def get_new_xid(self): # Thread safe + self.lock.acquire() + self.xid += 1 + if self.xid >= 0x100000000: + self.xid = 0 + out = self.xid + self.lock.release() + return out + + # Because some security flavors use partial packing info to determine + # verf, can't call packer.pack_rpc_msg. + def get_call_header(self, xid, prog, vers, proc): # THREAD SAFE + p = self.getrpcpacker() + p.reset() + cred = self.security.make_cred() + p.pack_uint(xid) + p.pack_enum(CALL) + p.pack_uint(RPCVERSION) + p.pack_uint(prog) + p.pack_uint(vers) + p.pack_uint(proc) + p.pack_opaque_auth(cred) + verf = self.security.make_verf(p.get_buffer()) + p.pack_opaque_auth(verf) + return p.get_buffer(), cred + + def check_reply(self, cache_data): # THREAD SAFE + """Looks at rpc_msg reply and raises error if necessary + + xid has already been checked + """ + msg = cache_data.rhead.body + if msg.mtype != REPLY: + raise RPCError("Msg was not a REPLY") + msg = msg.rbody + if msg.stat == MSG_DENIED: + # Do more here + raise RPCDeniedError(msg.rreply) + elif msg.areply.reply_data.stat != SUCCESS: + raise RPCAcceptError(msg.areply) + # STUB + self.security.check_verf(msg.areply.verf, cache_data.cred) + + +################################################### + +class Server(object): + def __init__(self, host='', port=51423, name="SERVER", ipv6=False): + if ipv6: + self.s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + else: + self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.s.bind((host, port)) + self.port = self.s.getsockname()[1] + self.s.setblocking(0) + # Set up poll object + self.p = select.poll() + self.p.register(self.s, _readmask) + self.name = name + + def run(self, debug=0): + while 1: + if debug: print("%s: Calling poll" % self.name) + res = self.p.poll() + if debug: print("%s: %s" % (self.name, res)) + for fd, event in res: + if debug: + print("%s: Handling fd=%i, event=%x" % \ + (self.name, fd, event)) + if event & select.POLLHUP: + self.event_hup(fd, debug) + elif event & select.POLLNVAL: + if debug: print("%s: POLLNVAL for fd=%i" % (self.name, fd)) + self.p.unregister(fd) + elif event & ~(select.POLLIN | select.POLLOUT): + print("%s: ERROR: event %i for fd %i" % \ + (self.name, event, fd)) + self.event_error(fd) + else: + if event & select.POLLOUT: + self.event_write(fd) + # This must be last since may call close + if event & select.POLLIN: + if fd == self.s.fileno(): + self.event_connect(fd, debug) + else: + data = self.sockets[fd].recv(4096) + if data: + self.event_read(fd, data, debug) + else: + self.event_close(fd) + + +class RPCServer(Server): + def __init__(self, prog=10, vers=4, host='', port=51423, ipv6=False): + Server.__init__(self, host, port, ipv6) + self.rpcpacker = rpc_pack.RPCPacker() + self.rpcunpacker = rpc_pack.RPCUnpacker('') + self.prog = prog + self.vers = vers # FRED - this could be more general + self.security = {AUTH_NONE: SecAuthNone(), + AUTH_SYS: SecAuthSys(), + } + if 'gss' in supported: + self.security[RPCSEC_GSS] = SecAuthGss() + self.readbufs = {} + self.writebufs = {} + self.packetbufs = {} # store packets read until have a whole record + self.recordbufs = {} # write buffer for outgoing records + self.sockets = {} + self.s.listen(5) + + def handle_0(self, data, cred): + if data != b'': + return GARBAGE_ARGS, b'' + else: + return SUCCESS, b'' + + def event_connect(self, fd, debug=0): + csock, caddr = self.s.accept() + csock.setblocking(0) + if debug: + print("SERVER: got connection from %s, " \ + "assigned to fd=%i" % \ + (csock.getpeername(), csock.fileno())) + self.p.register(csock, _readmask) + cfd = csock.fileno() + self.readbufs[cfd] = b'' + self.writebufs[cfd] = b'' + self.packetbufs[cfd] = [] + self.recordbufs[cfd] = [] + self.sockets[cfd] = csock + + def event_read(self, fd, data, debug=0): + """Reads incoming record marked packets + + Also responds to command codes sent as encoded integers + """ + if debug: print("SERVER: In read event for %i" % fd) + self.readbufs[fd] += data + loop = True + while loop: + loop = False + str = self.readbufs[fd] + if len(str) >= 4: + packetlen = struct.unpack('>I', str[0:4])[0] + last = 0x80000000 & packetlen + packetlen &= 0x7fffffff + if len(str) >= 4 + packetlen: + self.packetbufs[fd].append(str[4:4 + packetlen]) + self.readbufs[fd] = str[4 + packetlen:] + if self.readbufs[fd]: + loop = True # We've received data past last + if last: + if debug: print("SERVER: Received record from %i" % fd) + recv_data = b''.join(self.packetbufs[fd]) + self.packetbufs[fd] = [] + if len(recv_data) == 4: + reply = self.event_command(fd, struct.unpack('>I', recv_data)[0]) + else: + # All handle_* functions are called in compute_reply + reply = self.compute_reply(recv_data) + if reply is not None: + self.recordbufs[fd].append(reply) + self.p.register(fd, _bothmask) + + def event_write(self, fd, chunksize=2048, debug=0): + if debug: print("SERVER: In write event for %i" % fd) + if self.writebufs[fd]: + if debug: print(" writing from writebuf") + count = self.sockets[fd].send(self.writebufs[fd]) + self.writebufs[fd] = self.writebufs[fd][count:] + # check if done? + elif self.recordbufs[fd]: + if debug: print(" writing from recordbuf") + data = self.recordbufs[fd][0] + chunk = data[:chunksize] + if len(data) > chunksize: + last = 0 + self.recordbufs[fd][0] = data[chunksize:] + else: + last = 0x80000000 + del self.recordbufs[fd][0] + mark = struct.pack('>I', last | len(chunk)) + self.writebufs[fd] = (mark + chunk) + # Duplicated code + count = self.sockets[fd].send(self.writebufs[fd]) + self.writebufs[fd] = self.writebufs[fd][count:] + else: + if debug: print(" done writing") + self.p.register(fd, _readmask) + + def event_command(self, cfd, comm, debug=0): + if debug: + print("SERVER: command = %i, cfd = %i" % (comm, cfd)) + if comm == 0: # Turn off server + self.compute_reply = lambda x: None + return b'\0' * 4 + elif comm == 1: # Turn server on + self.compute_reply = self.__compute_reply_orig + return b'\0' * 4 + + def event_close(self, fd, debug=0): + if debug: + print("SERVER: closing %i" % fd) + self.event_error(fd) + + def event_error(self, fd): + self.p.unregister(fd) + self.sockets[fd].close() + del self.readbufs[fd] + del self.writebufs[fd] + del self.packetbufs[fd] + del self.recordbufs[fd] + del self.sockets[fd] + + event_hup = event_error + + def compute_reply(self, recv_data): + # Decode RPC specific info + self.rpcunpacker.reset(recv_data) + try: + recv_msg = self.rpcunpacker.unpack_rpc_msg() + except xdrlib.Error as e: + print("XDRError", e) + return + if recv_msg.body.mtype != CALL: + print("Received a REPLY, expected a CALL") + return + # Check for reasons to deny the call + call = recv_msg.body.cbody + cred = call.cred + flavor = cred.flavor + # print call + reply_stat = MSG_ACCEPTED + areply = rreply = None + proc_response = b'' + if call.rpcvers != RPCVERSION: + rreply = rejected_reply(RPC_MISMATCH, + rpc_mismatch_info(RPCVERSION, RPCVERSION)) + reply_stat = MSG_DENIED + elif flavor not in self.security: # STUB + # Auth checking + rreply = rejected_reply(AUTH_ERROR, astat=AUTH_FAILED) + reply_stat = MSG_DENIED + # At this point recv_msg has been accepted + # Check for reasons to fail before calling handle_* + meth_data = recv_data[self.rpcunpacker.get_position():] + meth_data = self.security[flavor].unsecure_data(meth_data, cred) + if rreply: + pass + elif self.prog != call.prog: + verf = self.security[flavor].make_reply_verf(cred, PROG_UNAVAIL) + areply = accepted_reply(verf, rpc_reply_data(PROG_UNAVAIL)) + elif self.vers != call.vers: + verf = self.security[flavor].make_reply_verf(cred, PROG_MISMATCH) + mismatch = rpc_mismatch_info(self.vers, self.vers) + areply = accepted_reply(verf, + rpc_reply_data(PROG_MISMATCH, + mismatch_info=mismatch)) + elif not hasattr(self, "handle_%i" % call.proc): + verf = self.security[flavor].make_reply_verf(cred, PROG_UNAVAIL) + areply = accepted_reply(verf, rpc_reply_data(PROC_UNAVAIL)) + # Call appropriate handle_* + else: + method = getattr(self, "handle_%i" % call.proc) + a_stat, proc_response = method(meth_data, cred) + verf = self.security[flavor].make_reply_verf(cred, a_stat) + if a_stat == SUCCESS: + proc_response = self.security[flavor].secure_data(proc_response, cred) + areply = accepted_reply(verf, rpc_reply_data(a_stat, b'')) + # Build reply + body = reply_body(reply_stat, areply, rreply) + msg = rpc_msg(recv_msg.xid, rpc_msg_body(REPLY, rbody=body)) + self.rpcpacker.reset() + self.rpcpacker.pack_rpc_msg(msg) + return self.rpcpacker.get_buffer() + proc_response + + __compute_reply_orig = compute_reply diff --git a/nfs3/lib/rpc/rpc.x b/nfs3/lib/rpc/rpc.x new file mode 100644 index 0000000..db1ff4e --- /dev/null +++ b/nfs3/lib/rpc/rpc.x @@ -0,0 +1,135 @@ +/* FRED - This is taken from RFC1831, except that all the unnamed + * unions and structures have been named (which makes the resulting code + * MUCH easier to work with). + */ + +enum auth_flavor { + AUTH_NONE = 0, + AUTH_SYS = 1, + AUTH_SHORT = 2, + AUTH_DH = 3, + RPCSEC_GSS = 6 + /* and more to be defined */ +}; + +struct opaque_auth { + auth_flavor flavor; + opaque body<400>; +}; + +enum msg_type { + CALL = 0, + REPLY = 1 +}; + +enum reply_stat { + MSG_ACCEPTED = 0, + MSG_DENIED = 1 +}; + +enum accept_stat { + SUCCESS = 0, /* RPC executed successfully */ + PROG_UNAVAIL = 1, /* remote hasn't exported program */ + PROG_MISMATCH = 2, /* remote can't support version # */ + PROC_UNAVAIL = 3, /* program can't support procedure */ + GARBAGE_ARGS = 4, /* procedure can't decode params */ + SYSTEM_ERR = 5 /* errors like memory allocation failure */ +}; + +enum reject_stat { + RPC_MISMATCH = 0, /* RPC version number != 2 */ + AUTH_ERROR = 1 /* remote can't authenticate caller */ +}; + +enum auth_stat { + AUTH_OK = 0, /* success */ + /* Failed at remote end */ + AUTH_BADCRED = 1, /* bad credential (seal broken) */ + AUTH_REJECTEDCRED = 2, /* client must begin new session */ + AUTH_BADVERF = 3, /* bad verifier (seal broken) */ + AUTH_REJECTEDVERF = 4, /* verifier expired or replayed */ + AUTH_TOOWEAK = 5, /* rejected for security reasons */ + /* Failed locally */ + AUTH_INVALIDRESP = 6, /* bogus respnse verifier */ + AUTH_FAILED = 7, /* reason unknown */ + /* Kerberos errors */ + AUTH_KERB_GENERIC = 8, /* kerberos generic error */ + AUTH_TIMEEXPIRE = 9, /* time of credential expired */ + AUTH_TKT_FILE = 10, /* problem with ticket file */ + AUTH_DECODE = 11, /* can't decode authenticator */ + AUTH_NET_ADDR = 12, /* wrong net address in ticket */ + /* GSS related errors */ + /* RPCSEC_GSS_NOCRED = 13,*/ /* no credentials for user */ + /* RPCSEC_GSS_FAILED = 14 */ /* GSS failure, creds deleted */ + + RPCSEC_GSS_CREDPROBLEM = 13, + RPCSEC_GSS_CTXPROBLEM = 14 + +}; + +struct rpc_msg { + unsigned int xid; + rpc_msg_body body; +}; + +union rpc_msg_body switch (msg_type mtype) { + case CALL: + call_body cbody; + case REPLY: + reply_body rbody; +}; + +struct call_body { + unsigned int rpcvers; /* must be equal to two (2) */ + unsigned int prog; + unsigned int vers; + unsigned int proc; + opaque_auth cred; + opaque_auth verf; + /* procedure specific parameters start here */ +}; + +union reply_body switch (reply_stat stat) { + case MSG_ACCEPTED: + accepted_reply areply; + case MSG_DENIED: + rejected_reply rreply; +}; /* Note RFC has 'reply' here, which seems against XDR spec */ + +struct rpc_mismatch_info { + unsigned int low; + unsigned int high; +}; + +union rpc_reply_data switch (accept_stat stat) { + case SUCCESS: + opaque results[0]; + /* + * procedure specific results start here + */ + case PROG_MISMATCH: + rpc_mismatch_info mismatch_info; + default: + void; +}; + +struct accepted_reply { + opaque_auth verf; + rpc_reply_data reply_data; +}; + +/* FRED - this had two conflicting 'stat' variables. One has been renamed. */ +union rejected_reply switch (reject_stat stat) { + case RPC_MISMATCH: + rpc_mismatch_info mismatch_info; + case AUTH_ERROR: + auth_stat astat; +}; + +struct authsys_parms { + unsigned int stamp; + string machinename<255>; + unsigned int uid; + unsigned int gid; + unsigned int gids<16>; +}; \ No newline at end of file diff --git a/nfs3/lib/rpc/rpc_const.py b/nfs3/lib/rpc/rpc_const.py new file mode 100644 index 0000000..08a01ca --- /dev/null +++ b/nfs3/lib/rpc/rpc_const.py @@ -0,0 +1,77 @@ +# Generated by rpcgen.py from rpc.x on Wed Jun 24 11:38:48 2026 +AUTH_NONE = 0 +AUTH_SYS = 1 +AUTH_SHORT = 2 +AUTH_DH = 3 +RPCSEC_GSS = 6 +auth_flavor = { + 0 : 'AUTH_NONE', + 1 : 'AUTH_SYS', + 2 : 'AUTH_SHORT', + 3 : 'AUTH_DH', + 6 : 'RPCSEC_GSS', +} +CALL = 0 +REPLY = 1 +msg_type = { + 0 : 'CALL', + 1 : 'REPLY', +} +MSG_ACCEPTED = 0 +MSG_DENIED = 1 +reply_stat = { + 0 : 'MSG_ACCEPTED', + 1 : 'MSG_DENIED', +} +SUCCESS = 0 +PROG_UNAVAIL = 1 +PROG_MISMATCH = 2 +PROC_UNAVAIL = 3 +GARBAGE_ARGS = 4 +SYSTEM_ERR = 5 +accept_stat = { + 0 : 'SUCCESS', + 1 : 'PROG_UNAVAIL', + 2 : 'PROG_MISMATCH', + 3 : 'PROC_UNAVAIL', + 4 : 'GARBAGE_ARGS', + 5 : 'SYSTEM_ERR', +} +RPC_MISMATCH = 0 +AUTH_ERROR = 1 +reject_stat = { + 0 : 'RPC_MISMATCH', + 1 : 'AUTH_ERROR', +} +AUTH_OK = 0 +AUTH_BADCRED = 1 +AUTH_REJECTEDCRED = 2 +AUTH_BADVERF = 3 +AUTH_REJECTEDVERF = 4 +AUTH_TOOWEAK = 5 +AUTH_INVALIDRESP = 6 +AUTH_FAILED = 7 +AUTH_KERB_GENERIC = 8 +AUTH_TIMEEXPIRE = 9 +AUTH_TKT_FILE = 10 +AUTH_DECODE = 11 +AUTH_NET_ADDR = 12 +RPCSEC_GSS_CREDPROBLEM = 13 +RPCSEC_GSS_CTXPROBLEM = 14 +auth_stat = { + 0 : 'AUTH_OK', + 1 : 'AUTH_BADCRED', + 2 : 'AUTH_REJECTEDCRED', + 3 : 'AUTH_BADVERF', + 4 : 'AUTH_REJECTEDVERF', + 5 : 'AUTH_TOOWEAK', + 6 : 'AUTH_INVALIDRESP', + 7 : 'AUTH_FAILED', + 8 : 'AUTH_KERB_GENERIC', + 9 : 'AUTH_TIMEEXPIRE', + 10 : 'AUTH_TKT_FILE', + 11 : 'AUTH_DECODE', + 12 : 'AUTH_NET_ADDR', + 13 : 'RPCSEC_GSS_CREDPROBLEM', + 14 : 'RPCSEC_GSS_CTXPROBLEM', +} diff --git a/nfs3/lib/rpc/rpc_pack.py b/nfs3/lib/rpc/rpc_pack.py new file mode 100644 index 0000000..c3241e1 --- /dev/null +++ b/nfs3/lib/rpc/rpc_pack.py @@ -0,0 +1,417 @@ +# Generated by rpcgen.py from rpc.x on Wed Jun 24 11:38:48 2026 +import rpc_const as const +import rpc_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class RPCPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + def pack_auth_flavor(self, data): + if hasattr(self, 'filter_auth_flavor'): + data = getattr(self, 'filter_auth_flavor')(data) + if self.check_enum and data not in [const.AUTH_NONE, const.AUTH_SYS, const.AUTH_SHORT, const.AUTH_DH, const.RPCSEC_GSS]: + raise XDRError('value=%s not in enum auth_flavor' % data) + self.pack_int(data) + + def pack_opaque_auth(self, data): + if hasattr(self, 'filter_opaque_auth'): + data = getattr(self, 'filter_opaque_auth')(data) + if data.flavor is None: + raise TypeError('data.flavor == None') + self.pack_auth_flavor(data.flavor) + if data.body is None: + raise TypeError('data.body == None') + if len(data.body) > 400 and self.check_array: + raise XDRError('array length too long for data.body') + self.pack_opaque(data.body) + + def pack_msg_type(self, data): + if hasattr(self, 'filter_msg_type'): + data = getattr(self, 'filter_msg_type')(data) + if self.check_enum and data not in [const.CALL, const.REPLY]: + raise XDRError('value=%s not in enum msg_type' % data) + self.pack_int(data) + + def pack_reply_stat(self, data): + if hasattr(self, 'filter_reply_stat'): + data = getattr(self, 'filter_reply_stat')(data) + if self.check_enum and data not in [const.MSG_ACCEPTED, const.MSG_DENIED]: + raise XDRError('value=%s not in enum reply_stat' % data) + self.pack_int(data) + + def pack_accept_stat(self, data): + if hasattr(self, 'filter_accept_stat'): + data = getattr(self, 'filter_accept_stat')(data) + if self.check_enum and data not in [const.SUCCESS, const.PROG_UNAVAIL, const.PROG_MISMATCH, const.PROC_UNAVAIL, const.GARBAGE_ARGS, const.SYSTEM_ERR]: + raise XDRError('value=%s not in enum accept_stat' % data) + self.pack_int(data) + + def pack_reject_stat(self, data): + if hasattr(self, 'filter_reject_stat'): + data = getattr(self, 'filter_reject_stat')(data) + if self.check_enum and data not in [const.RPC_MISMATCH, const.AUTH_ERROR]: + raise XDRError('value=%s not in enum reject_stat' % data) + self.pack_int(data) + + def pack_auth_stat(self, data): + if hasattr(self, 'filter_auth_stat'): + data = getattr(self, 'filter_auth_stat')(data) + if self.check_enum and data not in [const.AUTH_OK, const.AUTH_BADCRED, const.AUTH_REJECTEDCRED, const.AUTH_BADVERF, const.AUTH_REJECTEDVERF, const.AUTH_TOOWEAK, const.AUTH_INVALIDRESP, const.AUTH_FAILED, const.AUTH_KERB_GENERIC, const.AUTH_TIMEEXPIRE, const.AUTH_TKT_FILE, const.AUTH_DECODE, const.AUTH_NET_ADDR, const.RPCSEC_GSS_CREDPROBLEM, const.RPCSEC_GSS_CTXPROBLEM]: + raise XDRError('value=%s not in enum auth_stat' % data) + self.pack_int(data) + + def pack_rpc_msg(self, data): + if hasattr(self, 'filter_rpc_msg'): + data = getattr(self, 'filter_rpc_msg')(data) + if data.xid is None: + raise TypeError('data.xid == None') + self.pack_uint(data.xid) + if data.body is None: + raise TypeError('data.body == None') + self.pack_rpc_msg_body(data.body) + + def pack_rpc_msg_body(self, data): + if hasattr(self, 'filter_rpc_msg_body'): + data = getattr(self, 'filter_rpc_msg_body')(data) + if data.mtype is None: + raise TypeError('data.mtype == None') + self.pack_msg_type(data.mtype) + if data.mtype == const.CALL: + if data.cbody is None: + raise TypeError('data.cbody == None') + self.pack_call_body(data.cbody) + elif data.mtype == const.REPLY: + if data.rbody is None: + raise TypeError('data.rbody == None') + self.pack_reply_body(data.rbody) + else: + raise XDRError('bad switch=%s' % data.mtype) + + def pack_call_body(self, data): + if hasattr(self, 'filter_call_body'): + data = getattr(self, 'filter_call_body')(data) + if data.rpcvers is None: + raise TypeError('data.rpcvers == None') + self.pack_uint(data.rpcvers) + if data.prog is None: + raise TypeError('data.prog == None') + self.pack_uint(data.prog) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.proc is None: + raise TypeError('data.proc == None') + self.pack_uint(data.proc) + if data.cred is None: + raise TypeError('data.cred == None') + self.pack_opaque_auth(data.cred) + if data.verf is None: + raise TypeError('data.verf == None') + self.pack_opaque_auth(data.verf) + + def pack_reply_body(self, data): + if hasattr(self, 'filter_reply_body'): + data = getattr(self, 'filter_reply_body')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_reply_stat(data.stat) + if data.stat == const.MSG_ACCEPTED: + if data.areply is None: + raise TypeError('data.areply == None') + self.pack_accepted_reply(data.areply) + elif data.stat == const.MSG_DENIED: + if data.rreply is None: + raise TypeError('data.rreply == None') + self.pack_rejected_reply(data.rreply) + else: + raise XDRError('bad switch=%s' % data.stat) + + def pack_rpc_mismatch_info(self, data): + if hasattr(self, 'filter_rpc_mismatch_info'): + data = getattr(self, 'filter_rpc_mismatch_info')(data) + if data.low is None: + raise TypeError('data.low == None') + self.pack_uint(data.low) + if data.high is None: + raise TypeError('data.high == None') + self.pack_uint(data.high) + + def pack_rpc_reply_data(self, data): + if hasattr(self, 'filter_rpc_reply_data'): + data = getattr(self, 'filter_rpc_reply_data')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_accept_stat(data.stat) + if data.stat == const.SUCCESS: + if data.results is None: + raise TypeError('data.results == None') + self.pack_fopaque(0, data.results) + elif data.stat == const.PROG_MISMATCH: + if data.mismatch_info is None: + raise TypeError('data.mismatch_info == None') + self.pack_rpc_mismatch_info(data.mismatch_info) + else: + pass + + def pack_accepted_reply(self, data): + if hasattr(self, 'filter_accepted_reply'): + data = getattr(self, 'filter_accepted_reply')(data) + if data.verf is None: + raise TypeError('data.verf == None') + self.pack_opaque_auth(data.verf) + if data.reply_data is None: + raise TypeError('data.reply_data == None') + self.pack_rpc_reply_data(data.reply_data) + + def pack_rejected_reply(self, data): + if hasattr(self, 'filter_rejected_reply'): + data = getattr(self, 'filter_rejected_reply')(data) + if data.stat is None: + raise TypeError('data.stat == None') + self.pack_reject_stat(data.stat) + if data.stat == const.RPC_MISMATCH: + if data.mismatch_info is None: + raise TypeError('data.mismatch_info == None') + self.pack_rpc_mismatch_info(data.mismatch_info) + elif data.stat == const.AUTH_ERROR: + if data.astat is None: + raise TypeError('data.astat == None') + self.pack_auth_stat(data.astat) + else: + raise XDRError('bad switch=%s' % data.stat) + + def pack_authsys_parms(self, data): + if hasattr(self, 'filter_authsys_parms'): + data = getattr(self, 'filter_authsys_parms')(data) + if data.stamp is None: + raise TypeError('data.stamp == None') + self.pack_uint(data.stamp) + if data.machinename is None: + raise TypeError('data.machinename == None') + if len(data.machinename) > 255 and self.check_array: + raise XDRError('array length too long for data.machinename') + self.pack_string(data.machinename) + if data.uid is None: + raise TypeError('data.uid == None') + self.pack_uint(data.uid) + if data.gid is None: + raise TypeError('data.gid == None') + self.pack_uint(data.gid) + if data.gids is None: + raise TypeError('data.gids == None') + if len(data.gids) > 16 and self.check_array: + raise XDRError('array length too long for data.gids') + self.pack_array(data.gids, self.pack_uint) + +class RPCUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + def unpack_auth_flavor(self): + data = self.unpack_int() + if self.check_enum and data not in [const.AUTH_NONE, const.AUTH_SYS, const.AUTH_SHORT, const.AUTH_DH, const.RPCSEC_GSS]: + raise XDRError('value=%s not in enum auth_flavor' % data) + if hasattr(self, 'filter_auth_flavor'): + data = getattr(self, 'filter_auth_flavor')(data) + return data + + def unpack_opaque_auth(self): + data = types.opaque_auth() + data.flavor = self.unpack_auth_flavor() + data.body = self.unpack_opaque() + if len(data.body) > 400 and self.check_array: + raise XDRError('array length too long for data.body') + if hasattr(self, 'filter_opaque_auth'): + data = getattr(self, 'filter_opaque_auth')(data) + return data + + def unpack_msg_type(self): + data = self.unpack_int() + if self.check_enum and data not in [const.CALL, const.REPLY]: + raise XDRError('value=%s not in enum msg_type' % data) + if hasattr(self, 'filter_msg_type'): + data = getattr(self, 'filter_msg_type')(data) + return data + + def unpack_reply_stat(self): + data = self.unpack_int() + if self.check_enum and data not in [const.MSG_ACCEPTED, const.MSG_DENIED]: + raise XDRError('value=%s not in enum reply_stat' % data) + if hasattr(self, 'filter_reply_stat'): + data = getattr(self, 'filter_reply_stat')(data) + return data + + def unpack_accept_stat(self): + data = self.unpack_int() + if self.check_enum and data not in [const.SUCCESS, const.PROG_UNAVAIL, const.PROG_MISMATCH, const.PROC_UNAVAIL, const.GARBAGE_ARGS, const.SYSTEM_ERR]: + raise XDRError('value=%s not in enum accept_stat' % data) + if hasattr(self, 'filter_accept_stat'): + data = getattr(self, 'filter_accept_stat')(data) + return data + + def unpack_reject_stat(self): + data = self.unpack_int() + if self.check_enum and data not in [const.RPC_MISMATCH, const.AUTH_ERROR]: + raise XDRError('value=%s not in enum reject_stat' % data) + if hasattr(self, 'filter_reject_stat'): + data = getattr(self, 'filter_reject_stat')(data) + return data + + def unpack_auth_stat(self): + data = self.unpack_int() + if self.check_enum and data not in [const.AUTH_OK, const.AUTH_BADCRED, const.AUTH_REJECTEDCRED, const.AUTH_BADVERF, const.AUTH_REJECTEDVERF, const.AUTH_TOOWEAK, const.AUTH_INVALIDRESP, const.AUTH_FAILED, const.AUTH_KERB_GENERIC, const.AUTH_TIMEEXPIRE, const.AUTH_TKT_FILE, const.AUTH_DECODE, const.AUTH_NET_ADDR, const.RPCSEC_GSS_CREDPROBLEM, const.RPCSEC_GSS_CTXPROBLEM]: + raise XDRError('value=%s not in enum auth_stat' % data) + if hasattr(self, 'filter_auth_stat'): + data = getattr(self, 'filter_auth_stat')(data) + return data + + def unpack_rpc_msg(self): + data = types.rpc_msg() + data.xid = self.unpack_uint() + data.body = self.unpack_rpc_msg_body() + if hasattr(self, 'filter_rpc_msg'): + data = getattr(self, 'filter_rpc_msg')(data) + return data + + def unpack_rpc_msg_body(self): + data = types.rpc_msg_body() + data.mtype = self.unpack_msg_type() + if data.mtype == const.CALL: + data.cbody = self.unpack_call_body() + elif data.mtype == const.REPLY: + data.rbody = self.unpack_reply_body() + else: + raise XDRError('bad switch=%s' % data.mtype) + if hasattr(self, 'filter_rpc_msg_body'): + data = getattr(self, 'filter_rpc_msg_body')(data) + return data + + def unpack_call_body(self): + data = types.call_body() + data.rpcvers = self.unpack_uint() + data.prog = self.unpack_uint() + data.vers = self.unpack_uint() + data.proc = self.unpack_uint() + data.cred = self.unpack_opaque_auth() + data.verf = self.unpack_opaque_auth() + if hasattr(self, 'filter_call_body'): + data = getattr(self, 'filter_call_body')(data) + return data + + def unpack_reply_body(self): + data = types.reply_body() + data.stat = self.unpack_reply_stat() + if data.stat == const.MSG_ACCEPTED: + data.areply = self.unpack_accepted_reply() + elif data.stat == const.MSG_DENIED: + data.rreply = self.unpack_rejected_reply() + else: + raise XDRError('bad switch=%s' % data.stat) + if hasattr(self, 'filter_reply_body'): + data = getattr(self, 'filter_reply_body')(data) + return data + + def unpack_rpc_mismatch_info(self): + data = types.rpc_mismatch_info() + data.low = self.unpack_uint() + data.high = self.unpack_uint() + if hasattr(self, 'filter_rpc_mismatch_info'): + data = getattr(self, 'filter_rpc_mismatch_info')(data) + return data + + def unpack_rpc_reply_data(self): + data = types.rpc_reply_data() + data.stat = self.unpack_accept_stat() + if data.stat == const.SUCCESS: + data.results = self.unpack_fopaque(0) + elif data.stat == const.PROG_MISMATCH: + data.mismatch_info = self.unpack_rpc_mismatch_info() + else: + pass + if hasattr(self, 'filter_rpc_reply_data'): + data = getattr(self, 'filter_rpc_reply_data')(data) + return data + + def unpack_accepted_reply(self): + data = types.accepted_reply() + data.verf = self.unpack_opaque_auth() + data.reply_data = self.unpack_rpc_reply_data() + if hasattr(self, 'filter_accepted_reply'): + data = getattr(self, 'filter_accepted_reply')(data) + return data + + def unpack_rejected_reply(self): + data = types.rejected_reply() + data.stat = self.unpack_reject_stat() + if data.stat == const.RPC_MISMATCH: + data.mismatch_info = self.unpack_rpc_mismatch_info() + elif data.stat == const.AUTH_ERROR: + data.astat = self.unpack_auth_stat() + else: + raise XDRError('bad switch=%s' % data.stat) + if hasattr(self, 'filter_rejected_reply'): + data = getattr(self, 'filter_rejected_reply')(data) + return data + + def unpack_authsys_parms(self): + data = types.authsys_parms() + data.stamp = self.unpack_uint() + data.machinename = self.unpack_string() + if len(data.machinename) > 255 and self.check_array: + raise XDRError('array length too long for data.machinename') + data.uid = self.unpack_uint() + data.gid = self.unpack_uint() + data.gids = self.unpack_array(self.unpack_uint) + if len(data.gids) > 16 and self.check_array: + raise XDRError('array length too long for data.gids') + if hasattr(self, 'filter_authsys_parms'): + data = getattr(self, 'filter_authsys_parms')(data) + return data + diff --git a/nfs3/lib/rpc/rpc_type.py b/nfs3/lib/rpc/rpc_type.py new file mode 100644 index 0000000..7312816 --- /dev/null +++ b/nfs3/lib/rpc/rpc_type.py @@ -0,0 +1,265 @@ +# Generated by rpcgen.py from rpc.x on Wed Jun 24 11:38:48 2026 +import rpc_const as const +class opaque_auth: + # XDR definition: + # struct opaque_auth { + # auth_flavor flavor; + # opaque body<400>; + # }; + def __init__(self, flavor=None, body=None): + self.flavor = flavor + self.body = body + + def __repr__(self): + out = [] + if self.flavor is not None: + out += ['flavor=%s' % const.auth_flavor.get(self.flavor, self.flavor)] + if self.body is not None: + out += ['body=%s' % repr(self.body)] + return 'opaque_auth(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_msg: + # XDR definition: + # struct rpc_msg { + # uint xid; + # rpc_msg_body body; + # }; + def __init__(self, xid=None, body=None): + self.xid = xid + self.body = body + + def __getattr__(self, attr): + return getattr(self.body, attr) + + def __repr__(self): + out = [] + if self.xid is not None: + out += ['xid=%s' % repr(self.xid)] + if self.body is not None: + out += ['body=%s' % repr(self.body)] + return 'rpc_msg(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_msg_body: + # XDR definition: + # union rpc_msg_body switch(msg_type mtype) { + # case CALL: + # call_body cbody; + # case REPLY: + # reply_body rbody; + # }; + def __init__(self, mtype=None, cbody=None, rbody=None): + self.mtype = mtype + self.cbody = cbody + self.rbody = rbody + + switch = property(lambda s: {const.CALL:s.cbody,const.REPLY:s.rbody,}[s.mtype]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.mtype is not None: + out += ['mtype=%s' % const.msg_type.get(self.mtype, self.mtype)] + if self.cbody is not None: + out += ['cbody=%s' % repr(self.cbody)] + if self.rbody is not None: + out += ['rbody=%s' % repr(self.rbody)] + return 'rpc_msg_body(%s)' % ', '.join(out) + __str__ = __repr__ + +class call_body: + # XDR definition: + # struct call_body { + # uint rpcvers; + # uint prog; + # uint vers; + # uint proc; + # opaque_auth cred; + # opaque_auth verf; + # }; + def __init__(self, rpcvers=None, prog=None, vers=None, proc=None, cred=None, verf=None): + self.rpcvers = rpcvers + self.prog = prog + self.vers = vers + self.proc = proc + self.cred = cred + self.verf = verf + + def __repr__(self): + out = [] + if self.rpcvers is not None: + out += ['rpcvers=%s' % repr(self.rpcvers)] + if self.prog is not None: + out += ['prog=%s' % repr(self.prog)] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.proc is not None: + out += ['proc=%s' % repr(self.proc)] + if self.cred is not None: + out += ['cred=%s' % repr(self.cred)] + if self.verf is not None: + out += ['verf=%s' % repr(self.verf)] + return 'call_body(%s)' % ', '.join(out) + __str__ = __repr__ + +class reply_body: + # XDR definition: + # union reply_body switch(reply_stat stat) { + # case MSG_ACCEPTED: + # accepted_reply areply; + # case MSG_DENIED: + # rejected_reply rreply; + # }; + def __init__(self, stat=None, areply=None, rreply=None): + self.stat = stat + self.areply = areply + self.rreply = rreply + + switch = property(lambda s: {const.MSG_ACCEPTED:s.areply,const.MSG_DENIED:s.rreply,}[s.stat]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.reply_stat.get(self.stat, self.stat)] + if self.areply is not None: + out += ['areply=%s' % repr(self.areply)] + if self.rreply is not None: + out += ['rreply=%s' % repr(self.rreply)] + return 'reply_body(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_mismatch_info: + # XDR definition: + # struct rpc_mismatch_info { + # uint low; + # uint high; + # }; + def __init__(self, low=None, high=None): + self.low = low + self.high = high + + def __repr__(self): + out = [] + if self.low is not None: + out += ['low=%s' % repr(self.low)] + if self.high is not None: + out += ['high=%s' % repr(self.high)] + return 'rpc_mismatch_info(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_reply_data: + # XDR definition: + # union rpc_reply_data switch(accept_stat stat) { + # case SUCCESS: + # opaque results[0]; + # case PROG_MISMATCH: + # rpc_mismatch_info mismatch_info; + # default: + # void; + # }; + def __init__(self, stat=None, results=None, mismatch_info=None): + self.stat = stat + self.results = results + self.mismatch_info = mismatch_info + + switch = property(lambda s: {const.SUCCESS:s.results,const.PROG_MISMATCH:s.mismatch_info,}.get(s.stat, None)) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.accept_stat.get(self.stat, self.stat)] + if self.results is not None: + out += ['results=%s' % repr(self.results)] + if self.mismatch_info is not None: + out += ['mismatch_info=%s' % repr(self.mismatch_info)] + return 'rpc_reply_data(%s)' % ', '.join(out) + __str__ = __repr__ + +class accepted_reply: + # XDR definition: + # struct accepted_reply { + # opaque_auth verf; + # rpc_reply_data reply_data; + # }; + def __init__(self, verf=None, reply_data=None): + self.verf = verf + self.reply_data = reply_data + + def __repr__(self): + out = [] + if self.verf is not None: + out += ['verf=%s' % repr(self.verf)] + if self.reply_data is not None: + out += ['reply_data=%s' % repr(self.reply_data)] + return 'accepted_reply(%s)' % ', '.join(out) + __str__ = __repr__ + +class rejected_reply: + # XDR definition: + # union rejected_reply switch(reject_stat stat) { + # case RPC_MISMATCH: + # rpc_mismatch_info mismatch_info; + # case AUTH_ERROR: + # auth_stat astat; + # }; + def __init__(self, stat=None, mismatch_info=None, astat=None): + self.stat = stat + self.mismatch_info = mismatch_info + self.astat = astat + + switch = property(lambda s: {const.RPC_MISMATCH:s.mismatch_info,const.AUTH_ERROR:s.astat,}[s.stat]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.stat is not None: + out += ['stat=%s' % const.reject_stat.get(self.stat, self.stat)] + if self.mismatch_info is not None: + out += ['mismatch_info=%s' % repr(self.mismatch_info)] + if self.astat is not None: + out += ['astat=%s' % const.auth_stat.get(self.astat, self.astat)] + return 'rejected_reply(%s)' % ', '.join(out) + __str__ = __repr__ + +class authsys_parms: + # XDR definition: + # struct authsys_parms { + # uint stamp; + # string machinename<255>; + # uint uid; + # uint gid; + # uint gids<16>; + # }; + def __init__(self, stamp=None, machinename=None, uid=None, gid=None, gids=None): + self.stamp = stamp + self.machinename = machinename + self.uid = uid + self.gid = gid + self.gids = gids + + def __repr__(self): + out = [] + if self.stamp is not None: + out += ['stamp=%s' % repr(self.stamp)] + if self.machinename is not None: + out += ['machinename=%s' % repr(self.machinename)] + if self.uid is not None: + out += ['uid=%s' % repr(self.uid)] + if self.gid is not None: + out += ['gid=%s' % repr(self.gid)] + if self.gids is not None: + out += ['gids=%s' % repr(self.gids)] + return 'authsys_parms(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/rpc/rpcsec/__init__.py b/nfs3/lib/rpc/rpcsec/__init__.py new file mode 100644 index 0000000..15be2d2 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/__init__.py @@ -0,0 +1,4 @@ +import os as _os, sys as _sys +# Python 3: make the package directory importable so the historic bare +# (implicit-relative) imports such as ``import gss_pack`` keep working. +_sys.path.insert(1, _os.path.dirname(_os.path.abspath(__file__))) diff --git a/nfs3/lib/rpc/rpcsec/base.py b/nfs3/lib/rpc/rpcsec/base.py new file mode 100644 index 0000000..37360c3 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/base.py @@ -0,0 +1,52 @@ +from rpc.rpc_const import AUTH_NONE +from rpc.rpc_type import opaque_auth + +class SecError(Exception): + pass + +class SecFlavor(object): + _none = opaque_auth(AUTH_NONE, b'') + + def initialize(self, client): + pass + + def secure_data(self, data, cred): + """Add any security info/encryption to procedure arg/res + 'data' is the data stream that would be sent if there were no security + 'cred' is the opaque_auth structure that will be sent in header + """ + return data + + def unsecure_data(self, data, cred): + """Remove any security cruft from procedure arg/res + 'data' is the received security wrapped data stream + 'cred' is the opaque_auth structure received in header + """ + return data + + def make_cred(self): + """Credential sent with each RPC call""" + return self._none + + def make_verf(self, data): + """Verifier sent with each RPC call + + 'data' is packed header upto and including cred + """ + return self._none + + def make_reply_verf(self, cred, stat): + """Verifier sent by server with each RPC reply""" + return self._none + + def get_owner(self): + """Return uid""" + return 0 + + def get_group(self): + """Return gid""" + return 0 + + def check_verf(self, rverf, cred): + """Raise error if there is a problem with reply verifier""" + pass diff --git a/nfs3/lib/rpc/rpcsec/gss.x b/nfs3/lib/rpc/rpcsec/gss.x new file mode 100644 index 0000000..b657529 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gss.x @@ -0,0 +1,107 @@ +/* Taken from RFC 2203 */ + +/* RPCSEC_GSS control procedures */ +enum rpc_gss_proc_t { + RPCSEC_GSS_DATA = 0, + RPCSEC_GSS_INIT = 1, + RPCSEC_GSS_CONTINUE_INIT = 2, + RPCSEC_GSS_DESTROY = 3 +}; + +/* RPCSEC_GSS services */ + +enum rpc_gss_service_t { + /* Note: the enumerated value for 0 is reserved. */ + rpc_gss_svc_none = 1, + rpc_gss_svc_integrity = 2, + rpc_gss_svc_privacy = 3 +}; + +/* Credential */ + +/* + * Note: version 0 is reserved for possible future + * definition of a version negotiation protocol + * + */ +const RPCSEC_GSS_VERS_1 = 1; + +/* (Fred) Unamed union inside struct did not meet XDR spec, so I removed + * outer struct and typedef the struct in the case. Also changed + * 'version' to 'vers' to avoid conflict with RPC reserved word. + */ + +struct rpc_gss_cred_vers_1_t { + rpc_gss_proc_t gss_proc; /* control procedure */ + unsigned int seq_num; /* sequence number */ + rpc_gss_service_t service; /* service used */ + opaque handle<>; /* context handle */ +}; + +union rpc_gss_cred_t switch (unsigned int vers) { /* version of RPCSEC_GSS */ + case RPCSEC_GSS_VERS_1: + rpc_gss_cred_vers_1_t rpc_gss_cred_vers_1_t; +}; + +/* Maximum sequence number value */ +const MAXSEQ = 0x80000000; + +struct rpc_gss_init_arg { + opaque gss_token<>; +}; + +struct rpc_gss_init_res { + opaque handle<>; + unsigned int gss_major; + unsigned int gss_minor; + unsigned int seq_window; + opaque gss_token<>; +}; + + +struct rpc_gss_integ_data { + opaque databody_integ<>; + opaque checksum<>; +}; + +struct rpc_gss_data_t { + unsigned int seq_num; + proc_req_arg_t arg; +}; + + +struct rpc_gss_priv_data { + opaque databody_priv<>; +}; + +/* (Fred) I added this */ +enum gss_major_codes { + GSS_S_COMPLETE = 0x00000000, + GSS_S_CONTINUE_NEEDED = 0x00000001, + GSS_S_DUPLICATE_TOKEN = 0x00000002, + GSS_S_OLD_TOKEN = 0x00000004, + GSS_S_UNSEQ_TOKEN = 0x00000008, + GSS_S_GAP_TOKEN = 0x00000010, + GSS_S_BAD_MECH = 0x00010000, + GSS_S_BAD_NAME = 0x00020000, + GSS_S_BAD_NAMETYPE = 0x00030000, + GSS_S_BAD_BINDINGS = 0x00040000, + GSS_S_BAD_STATUS = 0x00050000, + GSS_S_BAD_MIC = 0x00060000, + GSS_S_BAD_SIG = 0x00060000, + GSS_S_NO_CRED = 0x00070000, + GSS_S_NO_CONTEXT = 0x00080000, + GSS_S_DEFECTIVE_TOKEN = 0x00090000, + GSS_S_DEFECTIVE_CREDENTIAL = 0x000a0000, + GSS_S_CREDENTIALS_EXPIRED = 0x000b0000, + GSS_S_CONTEXT_EXPIRED = 0x000c0000, + GSS_S_FAILURE = 0x000d0000, + GSS_S_BAD_QOP = 0x000e0000, + GSS_S_UNAUTHORIZED = 0x000f0000, + GSS_S_UNAVAILABLE = 0x00100000, + GSS_S_DUPLICATE_ELEMENT = 0x00110000, + GSS_S_NAME_NOT_MN = 0x00120000, + GSS_S_CALL_INACCESSIBLE_READ = 0x01000000, + GSS_S_CALL_INACCESSIBLE_WRITE = 0x02000000, + GSS_S_CALL_BAD_STRUCTURE = 0x03000000 +}; diff --git a/nfs3/lib/rpc/rpcsec/gss_const.py b/nfs3/lib/rpc/rpcsec/gss_const.py new file mode 100644 index 0000000..eee6c88 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gss_const.py @@ -0,0 +1,79 @@ +# Generated by rpcgen.py from gss.x on Wed Jun 24 11:38:48 2026 +RPCSEC_GSS_DATA = 0 +RPCSEC_GSS_INIT = 1 +RPCSEC_GSS_CONTINUE_INIT = 2 +RPCSEC_GSS_DESTROY = 3 +rpc_gss_proc_t = { + 0 : 'RPCSEC_GSS_DATA', + 1 : 'RPCSEC_GSS_INIT', + 2 : 'RPCSEC_GSS_CONTINUE_INIT', + 3 : 'RPCSEC_GSS_DESTROY', +} +rpc_gss_svc_none = 1 +rpc_gss_svc_integrity = 2 +rpc_gss_svc_privacy = 3 +rpc_gss_service_t = { + 1 : 'rpc_gss_svc_none', + 2 : 'rpc_gss_svc_integrity', + 3 : 'rpc_gss_svc_privacy', +} +RPCSEC_GSS_VERS_1 = 1 +MAXSEQ = 0x80000000 +GSS_S_COMPLETE = 0x00000000 +GSS_S_CONTINUE_NEEDED = 0x00000001 +GSS_S_DUPLICATE_TOKEN = 0x00000002 +GSS_S_OLD_TOKEN = 0x00000004 +GSS_S_UNSEQ_TOKEN = 0x00000008 +GSS_S_GAP_TOKEN = 0x00000010 +GSS_S_BAD_MECH = 0x00010000 +GSS_S_BAD_NAME = 0x00020000 +GSS_S_BAD_NAMETYPE = 0x00030000 +GSS_S_BAD_BINDINGS = 0x00040000 +GSS_S_BAD_STATUS = 0x00050000 +GSS_S_BAD_MIC = 0x00060000 +GSS_S_BAD_SIG = 0x00060000 +GSS_S_NO_CRED = 0x00070000 +GSS_S_NO_CONTEXT = 0x00080000 +GSS_S_DEFECTIVE_TOKEN = 0x00090000 +GSS_S_DEFECTIVE_CREDENTIAL = 0x000a0000 +GSS_S_CREDENTIALS_EXPIRED = 0x000b0000 +GSS_S_CONTEXT_EXPIRED = 0x000c0000 +GSS_S_FAILURE = 0x000d0000 +GSS_S_BAD_QOP = 0x000e0000 +GSS_S_UNAUTHORIZED = 0x000f0000 +GSS_S_UNAVAILABLE = 0x00100000 +GSS_S_DUPLICATE_ELEMENT = 0x00110000 +GSS_S_NAME_NOT_MN = 0x00120000 +GSS_S_CALL_INACCESSIBLE_READ = 0x01000000 +GSS_S_CALL_INACCESSIBLE_WRITE = 0x02000000 +GSS_S_CALL_BAD_STRUCTURE = 0x03000000 +gss_major_codes = { + 0x00000000 : 'GSS_S_COMPLETE', + 0x00000001 : 'GSS_S_CONTINUE_NEEDED', + 0x00000002 : 'GSS_S_DUPLICATE_TOKEN', + 0x00000004 : 'GSS_S_OLD_TOKEN', + 0x00000008 : 'GSS_S_UNSEQ_TOKEN', + 0x00000010 : 'GSS_S_GAP_TOKEN', + 0x00010000 : 'GSS_S_BAD_MECH', + 0x00020000 : 'GSS_S_BAD_NAME', + 0x00030000 : 'GSS_S_BAD_NAMETYPE', + 0x00040000 : 'GSS_S_BAD_BINDINGS', + 0x00050000 : 'GSS_S_BAD_STATUS', + 0x00060000 : 'GSS_S_BAD_MIC', + 0x00060000 : 'GSS_S_BAD_SIG', + 0x00070000 : 'GSS_S_NO_CRED', + 0x00080000 : 'GSS_S_NO_CONTEXT', + 0x00090000 : 'GSS_S_DEFECTIVE_TOKEN', + 0x000a0000 : 'GSS_S_DEFECTIVE_CREDENTIAL', + 0x000b0000 : 'GSS_S_CREDENTIALS_EXPIRED', + 0x000c0000 : 'GSS_S_CONTEXT_EXPIRED', + 0x000d0000 : 'GSS_S_FAILURE', + 0x000e0000 : 'GSS_S_BAD_QOP', + 0x000f0000 : 'GSS_S_UNAUTHORIZED', + 0x00100000 : 'GSS_S_UNAVAILABLE', + 0x00110000 : 'GSS_S_DUPLICATE_ELEMENT', + 0x00120000 : 'GSS_S_NAME_NOT_MN', + 0x01000000 : 'GSS_S_CALL_INACCESSIBLE_READ', + 0x02000000 : 'GSS_S_CALL_INACCESSIBLE_WRITE', + 0x03000000 : 'GSS_S_CALL_BAD_STRUCTURE', +} diff --git a/nfs3/lib/rpc/rpcsec/gss_pack.py b/nfs3/lib/rpc/rpcsec/gss_pack.py new file mode 100644 index 0000000..a3553f3 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gss_pack.py @@ -0,0 +1,248 @@ +# Generated by rpcgen.py from gss.x on Wed Jun 24 11:38:48 2026 +import gss_const as const +import gss_type as types +import xdrlib +from xdrlib import Error as XDRError + +class nullclass(object): + pass + +def _str2bytes(data): + # Python 3: xdrlib requires bytes for opaque/string fields. Python 2 str + # values were raw bytes, so latin-1 reproduces those byte values exactly + # (and is identical to ASCII/utf-8 for plain text). + if isinstance(data, str): + return data.encode('latin-1') + return data + +class GSSPacker(xdrlib.Packer): + def __init__(self, check_enum=True, check_array=True): + xdrlib.Packer.__init__(self) + self.check_enum = check_enum + self.check_array = check_array + + pack_int = xdrlib.Packer.pack_int + pack_long = xdrlib.Packer.pack_int + pack_uint = xdrlib.Packer.pack_uint + pack_unsigned = xdrlib.Packer.pack_uint + pack_hyper = xdrlib.Packer.pack_hyper + pack_uhyper = xdrlib.Packer.pack_uhyper + pack_float = xdrlib.Packer.pack_float + pack_double = xdrlib.Packer.pack_double + pack_quadruple = xdrlib.Packer.pack_double + pack_bool = xdrlib.Packer.pack_bool + def pack_opaque(self, data): + return xdrlib.Packer.pack_opaque(self, _str2bytes(data)) + def pack_string(self, data): + return xdrlib.Packer.pack_string(self, _str2bytes(data)) + def pack_fopaque(self, n, data): + return xdrlib.Packer.pack_fopaque(self, n, _str2bytes(data)) + def pack_fstring(self, n, data): + return xdrlib.Packer.pack_fstring(self, n, _str2bytes(data)) + def pack_rpc_gss_proc_t(self, data): + if hasattr(self, 'filter_rpc_gss_proc_t'): + data = getattr(self, 'filter_rpc_gss_proc_t')(data) + if self.check_enum and data not in [const.RPCSEC_GSS_DATA, const.RPCSEC_GSS_INIT, const.RPCSEC_GSS_CONTINUE_INIT, const.RPCSEC_GSS_DESTROY]: + raise XDRError('value=%s not in enum rpc_gss_proc_t' % data) + self.pack_int(data) + + def pack_rpc_gss_service_t(self, data): + if hasattr(self, 'filter_rpc_gss_service_t'): + data = getattr(self, 'filter_rpc_gss_service_t')(data) + if self.check_enum and data not in [const.rpc_gss_svc_none, const.rpc_gss_svc_integrity, const.rpc_gss_svc_privacy]: + raise XDRError('value=%s not in enum rpc_gss_service_t' % data) + self.pack_int(data) + + def pack_rpc_gss_cred_vers_1_t(self, data): + if hasattr(self, 'filter_rpc_gss_cred_vers_1_t'): + data = getattr(self, 'filter_rpc_gss_cred_vers_1_t')(data) + if data.gss_proc is None: + raise TypeError('data.gss_proc == None') + self.pack_rpc_gss_proc_t(data.gss_proc) + if data.seq_num is None: + raise TypeError('data.seq_num == None') + self.pack_uint(data.seq_num) + if data.service is None: + raise TypeError('data.service == None') + self.pack_rpc_gss_service_t(data.service) + if data.handle is None: + raise TypeError('data.handle == None') + self.pack_opaque(data.handle) + + def pack_rpc_gss_cred_t(self, data): + if hasattr(self, 'filter_rpc_gss_cred_t'): + data = getattr(self, 'filter_rpc_gss_cred_t')(data) + if data.vers is None: + raise TypeError('data.vers == None') + self.pack_uint(data.vers) + if data.vers == const.RPCSEC_GSS_VERS_1: + if data.rpc_gss_cred_vers_1_t is None: + raise TypeError('data.rpc_gss_cred_vers_1_t == None') + self.pack_rpc_gss_cred_vers_1_t(data.rpc_gss_cred_vers_1_t) + else: + raise XDRError('bad switch=%s' % data.vers) + + def pack_rpc_gss_init_arg(self, data): + if hasattr(self, 'filter_rpc_gss_init_arg'): + data = getattr(self, 'filter_rpc_gss_init_arg')(data) + if data.gss_token is None: + raise TypeError('data.gss_token == None') + self.pack_opaque(data.gss_token) + + def pack_rpc_gss_init_res(self, data): + if hasattr(self, 'filter_rpc_gss_init_res'): + data = getattr(self, 'filter_rpc_gss_init_res')(data) + if data.handle is None: + raise TypeError('data.handle == None') + self.pack_opaque(data.handle) + if data.gss_major is None: + raise TypeError('data.gss_major == None') + self.pack_uint(data.gss_major) + if data.gss_minor is None: + raise TypeError('data.gss_minor == None') + self.pack_uint(data.gss_minor) + if data.seq_window is None: + raise TypeError('data.seq_window == None') + self.pack_uint(data.seq_window) + if data.gss_token is None: + raise TypeError('data.gss_token == None') + self.pack_opaque(data.gss_token) + + def pack_rpc_gss_integ_data(self, data): + if hasattr(self, 'filter_rpc_gss_integ_data'): + data = getattr(self, 'filter_rpc_gss_integ_data')(data) + if data.databody_integ is None: + raise TypeError('data.databody_integ == None') + self.pack_opaque(data.databody_integ) + if data.checksum is None: + raise TypeError('data.checksum == None') + self.pack_opaque(data.checksum) + + def pack_rpc_gss_data_t(self, data): + if hasattr(self, 'filter_rpc_gss_data_t'): + data = getattr(self, 'filter_rpc_gss_data_t')(data) + if data.seq_num is None: + raise TypeError('data.seq_num == None') + self.pack_uint(data.seq_num) + if data.arg is None: + raise TypeError('data.arg == None') + self.pack_proc_req_arg_t(data.arg) + + def pack_rpc_gss_priv_data(self, data): + if hasattr(self, 'filter_rpc_gss_priv_data'): + data = getattr(self, 'filter_rpc_gss_priv_data')(data) + if data.databody_priv is None: + raise TypeError('data.databody_priv == None') + self.pack_opaque(data.databody_priv) + + def pack_gss_major_codes(self, data): + if hasattr(self, 'filter_gss_major_codes'): + data = getattr(self, 'filter_gss_major_codes')(data) + if self.check_enum and data not in [const.GSS_S_COMPLETE, const.GSS_S_CONTINUE_NEEDED, const.GSS_S_DUPLICATE_TOKEN, const.GSS_S_OLD_TOKEN, const.GSS_S_UNSEQ_TOKEN, const.GSS_S_GAP_TOKEN, const.GSS_S_BAD_MECH, const.GSS_S_BAD_NAME, const.GSS_S_BAD_NAMETYPE, const.GSS_S_BAD_BINDINGS, const.GSS_S_BAD_STATUS, const.GSS_S_BAD_MIC, const.GSS_S_BAD_SIG, const.GSS_S_NO_CRED, const.GSS_S_NO_CONTEXT, const.GSS_S_DEFECTIVE_TOKEN, const.GSS_S_DEFECTIVE_CREDENTIAL, const.GSS_S_CREDENTIALS_EXPIRED, const.GSS_S_CONTEXT_EXPIRED, const.GSS_S_FAILURE, const.GSS_S_BAD_QOP, const.GSS_S_UNAUTHORIZED, const.GSS_S_UNAVAILABLE, const.GSS_S_DUPLICATE_ELEMENT, const.GSS_S_NAME_NOT_MN, const.GSS_S_CALL_INACCESSIBLE_READ, const.GSS_S_CALL_INACCESSIBLE_WRITE, const.GSS_S_CALL_BAD_STRUCTURE]: + raise XDRError('value=%s not in enum gss_major_codes' % data) + self.pack_int(data) + +class GSSUnpacker(xdrlib.Unpacker): + def __init__(self, data, check_enum=True, check_array=True): + xdrlib.Unpacker.__init__(self, data) + self.check_enum = check_enum + self.check_array = check_array + + unpack_int = xdrlib.Unpacker.unpack_int + unpack_long = xdrlib.Unpacker.unpack_int + unpack_uint = xdrlib.Unpacker.unpack_uint + unpack_unsigned = xdrlib.Unpacker.unpack_uint + unpack_hyper = xdrlib.Unpacker.unpack_hyper + unpack_uhyper = xdrlib.Unpacker.unpack_uhyper + unpack_float = xdrlib.Unpacker.unpack_float + unpack_double = xdrlib.Unpacker.unpack_double + unpack_quadruple = xdrlib.Unpacker.unpack_double + unpack_bool = xdrlib.Unpacker.unpack_bool + unpack_opaque = xdrlib.Unpacker.unpack_opaque + unpack_string = xdrlib.Unpacker.unpack_string + def unpack_rpc_gss_proc_t(self): + data = self.unpack_int() + if self.check_enum and data not in [const.RPCSEC_GSS_DATA, const.RPCSEC_GSS_INIT, const.RPCSEC_GSS_CONTINUE_INIT, const.RPCSEC_GSS_DESTROY]: + raise XDRError('value=%s not in enum rpc_gss_proc_t' % data) + if hasattr(self, 'filter_rpc_gss_proc_t'): + data = getattr(self, 'filter_rpc_gss_proc_t')(data) + return data + + def unpack_rpc_gss_service_t(self): + data = self.unpack_int() + if self.check_enum and data not in [const.rpc_gss_svc_none, const.rpc_gss_svc_integrity, const.rpc_gss_svc_privacy]: + raise XDRError('value=%s not in enum rpc_gss_service_t' % data) + if hasattr(self, 'filter_rpc_gss_service_t'): + data = getattr(self, 'filter_rpc_gss_service_t')(data) + return data + + def unpack_rpc_gss_cred_vers_1_t(self): + data = types.rpc_gss_cred_vers_1_t() + data.gss_proc = self.unpack_rpc_gss_proc_t() + data.seq_num = self.unpack_uint() + data.service = self.unpack_rpc_gss_service_t() + data.handle = self.unpack_opaque() + if hasattr(self, 'filter_rpc_gss_cred_vers_1_t'): + data = getattr(self, 'filter_rpc_gss_cred_vers_1_t')(data) + return data + + def unpack_rpc_gss_cred_t(self): + data = types.rpc_gss_cred_t() + data.vers = self.unpack_uint() + if data.vers == const.RPCSEC_GSS_VERS_1: + data.rpc_gss_cred_vers_1_t = self.unpack_rpc_gss_cred_vers_1_t() + else: + raise XDRError('bad switch=%s' % data.vers) + if hasattr(self, 'filter_rpc_gss_cred_t'): + data = getattr(self, 'filter_rpc_gss_cred_t')(data) + return data + + def unpack_rpc_gss_init_arg(self): + data = types.rpc_gss_init_arg() + data.gss_token = self.unpack_opaque() + if hasattr(self, 'filter_rpc_gss_init_arg'): + data = getattr(self, 'filter_rpc_gss_init_arg')(data) + return data + + def unpack_rpc_gss_init_res(self): + data = types.rpc_gss_init_res() + data.handle = self.unpack_opaque() + data.gss_major = self.unpack_uint() + data.gss_minor = self.unpack_uint() + data.seq_window = self.unpack_uint() + data.gss_token = self.unpack_opaque() + if hasattr(self, 'filter_rpc_gss_init_res'): + data = getattr(self, 'filter_rpc_gss_init_res')(data) + return data + + def unpack_rpc_gss_integ_data(self): + data = types.rpc_gss_integ_data() + data.databody_integ = self.unpack_opaque() + data.checksum = self.unpack_opaque() + if hasattr(self, 'filter_rpc_gss_integ_data'): + data = getattr(self, 'filter_rpc_gss_integ_data')(data) + return data + + def unpack_rpc_gss_data_t(self): + data = types.rpc_gss_data_t() + data.seq_num = self.unpack_uint() + data.arg = self.unpack_proc_req_arg_t() + if hasattr(self, 'filter_rpc_gss_data_t'): + data = getattr(self, 'filter_rpc_gss_data_t')(data) + return data + + def unpack_rpc_gss_priv_data(self): + data = types.rpc_gss_priv_data() + data.databody_priv = self.unpack_opaque() + if hasattr(self, 'filter_rpc_gss_priv_data'): + data = getattr(self, 'filter_rpc_gss_priv_data')(data) + return data + + def unpack_gss_major_codes(self): + data = self.unpack_int() + if self.check_enum and data not in [const.GSS_S_COMPLETE, const.GSS_S_CONTINUE_NEEDED, const.GSS_S_DUPLICATE_TOKEN, const.GSS_S_OLD_TOKEN, const.GSS_S_UNSEQ_TOKEN, const.GSS_S_GAP_TOKEN, const.GSS_S_BAD_MECH, const.GSS_S_BAD_NAME, const.GSS_S_BAD_NAMETYPE, const.GSS_S_BAD_BINDINGS, const.GSS_S_BAD_STATUS, const.GSS_S_BAD_MIC, const.GSS_S_BAD_SIG, const.GSS_S_NO_CRED, const.GSS_S_NO_CONTEXT, const.GSS_S_DEFECTIVE_TOKEN, const.GSS_S_DEFECTIVE_CREDENTIAL, const.GSS_S_CREDENTIALS_EXPIRED, const.GSS_S_CONTEXT_EXPIRED, const.GSS_S_FAILURE, const.GSS_S_BAD_QOP, const.GSS_S_UNAUTHORIZED, const.GSS_S_UNAVAILABLE, const.GSS_S_DUPLICATE_ELEMENT, const.GSS_S_NAME_NOT_MN, const.GSS_S_CALL_INACCESSIBLE_READ, const.GSS_S_CALL_INACCESSIBLE_WRITE, const.GSS_S_CALL_BAD_STRUCTURE]: + raise XDRError('value=%s not in enum gss_major_codes' % data) + if hasattr(self, 'filter_gss_major_codes'): + data = getattr(self, 'filter_gss_major_codes')(data) + return data + diff --git a/nfs3/lib/rpc/rpcsec/gss_type.py b/nfs3/lib/rpc/rpcsec/gss_type.py new file mode 100644 index 0000000..c77086e --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gss_type.py @@ -0,0 +1,152 @@ +# Generated by rpcgen.py from gss.x on Wed Jun 24 11:38:48 2026 +import gss_const as const +class rpc_gss_cred_vers_1_t: + # XDR definition: + # struct rpc_gss_cred_vers_1_t { + # rpc_gss_proc_t gss_proc; + # uint seq_num; + # rpc_gss_service_t service; + # opaque handle<>; + # }; + def __init__(self, gss_proc=None, seq_num=None, service=None, handle=None): + self.gss_proc = gss_proc + self.seq_num = seq_num + self.service = service + self.handle = handle + + def __repr__(self): + out = [] + if self.gss_proc is not None: + out += ['gss_proc=%s' % const.rpc_gss_proc_t.get(self.gss_proc, self.gss_proc)] + if self.seq_num is not None: + out += ['seq_num=%s' % repr(self.seq_num)] + if self.service is not None: + out += ['service=%s' % const.rpc_gss_service_t.get(self.service, self.service)] + if self.handle is not None: + out += ['handle=%s' % repr(self.handle)] + return 'rpc_gss_cred_vers_1_t(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_gss_cred_t: + # XDR definition: + # union rpc_gss_cred_t switch(uint vers) { + # case RPCSEC_GSS_VERS_1: + # rpc_gss_cred_vers_1_t rpc_gss_cred_vers_1_t; + # }; + def __init__(self, vers=None, rpc_gss_cred_vers_1_t=None): + self.vers = vers + self.rpc_gss_cred_vers_1_t = rpc_gss_cred_vers_1_t + + switch = property(lambda s: {const.RPCSEC_GSS_VERS_1:s.rpc_gss_cred_vers_1_t,}[s.vers]) + + def __getattr__(self, attr): + return getattr(self.switch, attr) + + def __repr__(self): + out = [] + if self.vers is not None: + out += ['vers=%s' % repr(self.vers)] + if self.rpc_gss_cred_vers_1_t is not None: + out += ['rpc_gss_cred_vers_1_t=%s' % repr(self.rpc_gss_cred_vers_1_t)] + return 'rpc_gss_cred_t(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_gss_init_arg: + # XDR definition: + # struct rpc_gss_init_arg { + # opaque gss_token<>; + # }; + def __init__(self, gss_token=None): + self.gss_token = gss_token + + def __repr__(self): + out = [] + if self.gss_token is not None: + out += ['gss_token=%s' % repr(self.gss_token)] + return 'rpc_gss_init_arg(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_gss_init_res: + # XDR definition: + # struct rpc_gss_init_res { + # opaque handle<>; + # uint gss_major; + # uint gss_minor; + # uint seq_window; + # opaque gss_token<>; + # }; + def __init__(self, handle=None, gss_major=None, gss_minor=None, seq_window=None, gss_token=None): + self.handle = handle + self.gss_major = gss_major + self.gss_minor = gss_minor + self.seq_window = seq_window + self.gss_token = gss_token + + def __repr__(self): + out = [] + if self.handle is not None: + out += ['handle=%s' % repr(self.handle)] + if self.gss_major is not None: + out += ['gss_major=%s' % repr(self.gss_major)] + if self.gss_minor is not None: + out += ['gss_minor=%s' % repr(self.gss_minor)] + if self.seq_window is not None: + out += ['seq_window=%s' % repr(self.seq_window)] + if self.gss_token is not None: + out += ['gss_token=%s' % repr(self.gss_token)] + return 'rpc_gss_init_res(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_gss_integ_data: + # XDR definition: + # struct rpc_gss_integ_data { + # opaque databody_integ<>; + # opaque checksum<>; + # }; + def __init__(self, databody_integ=None, checksum=None): + self.databody_integ = databody_integ + self.checksum = checksum + + def __repr__(self): + out = [] + if self.databody_integ is not None: + out += ['databody_integ=%s' % repr(self.databody_integ)] + if self.checksum is not None: + out += ['checksum=%s' % repr(self.checksum)] + return 'rpc_gss_integ_data(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_gss_data_t: + # XDR definition: + # struct rpc_gss_data_t { + # uint seq_num; + # proc_req_arg_t arg; + # }; + def __init__(self, seq_num=None, arg=None): + self.seq_num = seq_num + self.arg = arg + + def __repr__(self): + out = [] + if self.seq_num is not None: + out += ['seq_num=%s' % repr(self.seq_num)] + if self.arg is not None: + out += ['arg=%s' % repr(self.arg)] + return 'rpc_gss_data_t(%s)' % ', '.join(out) + __str__ = __repr__ + +class rpc_gss_priv_data: + # XDR definition: + # struct rpc_gss_priv_data { + # opaque databody_priv<>; + # }; + def __init__(self, databody_priv=None): + self.databody_priv = databody_priv + + def __repr__(self): + out = [] + if self.databody_priv is not None: + out += ['databody_priv=%s' % repr(self.databody_priv)] + return 'rpc_gss_priv_data(%s)' % ', '.join(out) + __str__ = __repr__ + diff --git a/nfs3/lib/rpc/rpcsec/gssapi.i b/nfs3/lib/rpc/rpcsec/gssapi.i new file mode 100644 index 0000000..0570788 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gssapi.i @@ -0,0 +1,445 @@ +%module gssapi +%{ +#ifdef HEIMDAL +#include +#else +#include +#if 0 /* I don't think these are needed */ +#include +#include +#endif +#endif /* HEIMDAL */ + +gss_OID_desc krb5oid = { + .length = 9, + .elements = "\052\206\110\206\367\022\001\002\002"}; + +%} + +/* Debugging */ +#if 0 +#define printdict printf("Adding $1_name""\n") +#define printfred printf("FRED: $1_name""\n") +#else +#define printdict +#define printfred +#endif +/***********************************/ + + +/* Typemaps */ + +#ifdef SWIGPYTHON + +/* Used for routines that take input directly from user, as opposed + * to other gssapi routines. + */ + +%typemap(in) gss_buffer_t INPUT (gss_buffer_desc temp) { + printfred; + if ($input == Py_None) { + /* Allow None as equivalent to "" */ + $1 = NULL; + //temp.value = NULL; + //temp.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize($input, + (char **) &temp.value, + (Py_ssize_t *) &temp.length); + + if (stat == -1) + return NULL; + //temp.length++; /* Add null to count*/ + $1 = &temp; + } +} + +#if 0 +%typemap(in) gss_buffer_t INPUT (gss_buffer_desc temp) { + printfred; + if (SWIG_ConvertPtr($input, &temp, $*1_descriptor, SWIG_POINTER_EXCEPTION) == -1) { + /* Assume is a python string */ + temp.value = (void *) PyString_AsString($input); + if (!temp.value) + return NULL; + temp.length = strlen(temp.value) + 1; + } + $1 = ($1_ltype) &temp; +} +#endif + +%typemap(in, numinputs=0) gss_buffer_t OUTPUT (gss_buffer_desc temp) { + printfred; + $1 = &temp; +} + +%typemap(argout) gss_buffer_t OUTPUT { + PyObject *o; + printdict; + o = PyString_FromStringAndSize($1->value, $1->length); + if (!o) + return NULL; + if (PyDict_SetItemString($result, "$1_name", o) == -1) + return NULL; +} + +#if 0 +%typemap(in, numinputs=0) gss_name_t *OUTPUT (gss_name_t temp) { + printfred; + $1 = &temp; +} +%typemap(argout) gss_name_t *OUTPUT { + PyObject *o; + printdict; + o = PyString_FromStringAndSize(*($1), strlen(*($1)) + 1); + //o = PyString_FromString(*($1)); + if (!o) + return NULL; + if (PyDict_SetItemString($result, "$1_name", o) == -1) + return NULL; +} +%typemap(in) gss_name_t INPUT { + printfred; + $1 = PyString_AsString($input); + if (!$1) + return NULL; +} +#endif + +%typemap(in, numinputs=0) void **OUTPUT (void *temp) { + printfred; + $1 = ($1_ltype) &temp; +} + +%typemap(argout) void **OUTPUT { + /* returns a (void *) */ + printdict; + if (PyDict_SetItemString($result, "$1_name", + SWIG_NewPointerObj(*($1), $*1_descriptor, 0)) == -1) + return NULL; +} + +%typemap(in) void *INPUT { + printfred; + if (SWIG_ConvertPtr($input, &$1, $1_descriptor, SWIG_POINTER_EXCEPTION) == -1) { + /* Assume is a python string */ + PyErr_Clear(); + $1 = (void *) PyString_AsString($input); + if (!$1) + return NULL; + /* Convert '' to NULL */ + if (!*(char *)$1) + $1 = NULL; + } +} + +%typemap(in) void **INOUT (void *temp) { + /* $input is a (void *) */ + printfred; + if (SWIG_ConvertPtr($input, &temp, $*1_descriptor, SWIG_POINTER_EXCEPTION) == -1) { + /* Assume is a python string */ + PyErr_Clear(); + temp = (void *) PyString_AsString($input); + if (!temp) + return NULL; + /* Convert '' to NULL */ + if (!*(char *)temp) + temp = NULL; + } + $1 = ($1_ltype) &temp; +} + +%typemap(default) void **INOUT (void *temp=NULL) { + $1 = ($1_ltype) &temp; /* correctly set default to NULL */ +} + +#if 1 +%typemap(argout) void **INOUT = void **OUTPUT; +#else +%typemap(argout) void **INOUT { + PyObject *o; + printdict; + if (!*$1) { + o = PyString_FromString(""); + //o = Py_None; + } + else { + o = PyString_FromString((char *)*$1); + if (!o) + return NULL; + } + if (PyDict_SetItemString($result, "$1_name", o) == -1) + return NULL; +} + +#endif + +/* + * All functions return OM_uint32, which corresponds to major. + */ +%typemap(out) OM_uint32 { + /* Returns {"major":$1} */ + $result = PyDict_New(); + if (!$result || + (PyDict_SetItemString($result, "major", PyInt_FromLong($1)) == -1)) + return NULL; +} + +%typemap(in, numinputs=0) OM_uint32 *OUTPUT ($*1_type temp=0) { + printfred; + $1 = &temp; +} + +%typemap(argout) OM_uint32 *OUTPUT { + /* FRED - int *OUTPUT */ + printdict; + if (PyDict_SetItemString($result, "$1_name", PyLong_FromUnsignedLong((unsigned long)*$1)) == -1) + return NULL; +} + +#endif /* SWIGPYTHON */ + +%apply OM_uint32 *OUTPUT {OM_uint32 *minor}; + +/***********************************/ + +/* Some helper code */ +%inline { +char *ptr2str(void *ptr) { + return (char *) ptr; +} +} +/***********************************/ + +/* Non-function declarations */ + +%rename (krb5oid) krb5oid_ptr; +%rename (HOSTBASED_SERVICE) GSS_C_NT_HOSTBASED_SERVICE; +%immutable; +extern gss_OID GSS_C_NT_HOSTBASED_SERVICE; +// extern gss_OID_desc krb5oid; +%inline {gss_OID krb5oid_ptr = &krb5oid;} +%mutable; +#define GSS_S_COMPLETE 0x00000000 +#define GSS_S_CONTINUE_NEEDED 0x00000001 + +#define DELEG_FLAG 1 +#define MUTUAL_FLAG 2 +#define REPLAY_FLAG 4 +#define SEQUENCE_FLAG 8 +#define CONF_FLAG 16 +#define INTEG_FLAG 32 +#define ANON_FLAG 64 +#define PROT_READY_FLAG 128 +#define TRANS_FLAG 256 + +typedef unsigned int OM_uint32; +typedef OM_uint32 gss_qop_t; +typedef struct gss_name_struct * gss_name_t; +typedef struct gss_cred_id_struct * gss_cred_id_t; +typedef struct gss_ctx_id_struct * gss_ctx_id_t; + +/***********************************/ + +/* Function declarations */ + + +/*********************************************/ +%rename (importName) gss_import_name; +%apply void **OUTPUT {gss_name_t *name}; +//%apply gss_name_t *OUTPUT {gss_name_t *name}; +%apply gss_buffer_t INPUT {gss_buffer_t name}; +%feature("autodoc", "importName(string name, gss_OID name_type=HOSTBASED_SERVICE) -> name"); +OM_uint32 gss_import_name + (OM_uint32 *minor, /* minor_status OUT*/ + gss_buffer_t name, /* input_name_buffer IN */ + gss_OID name_type=GSS_C_NT_HOSTBASED_SERVICE, /* input_name_type IN */ + gss_name_t *name /* output_name OUT */ + ); +%clear gss_name_t *name; +%clear gss_buffer_t name; + +%{ +/* Reorder arguments so we can set defaults easily */ +OM_uint32 reordered_init_sec_context + (OM_uint32 *minor, /* minor_status */ + gss_name_t name, /* target_name IN*/ + gss_ctx_id_t *context, /* context_handle INOUT*/ + gss_buffer_t input_token, /* input_token IN */ + gss_cred_id_t cred, /* claimant_cred_handle IN*/ + gss_OID mech, /* mech_type IN */ + OM_uint32 req_flags, /* req_flags IN*/ + OM_uint32 time_req, /* time_req IN */ + gss_channel_bindings_t chan, /* input_chan_bindings IN*/ + gss_OID *actual_mech_type, /* actual_mech_type OUT*/ + gss_buffer_t output_token, /* output_token OUT*/ + OM_uint32 *ret_flags, /* ret_flags OUT*/ + OM_uint32 *time_rec) /* time_rec OUT*/ { + return gss_init_sec_context(minor, cred, context, name, mech, + req_flags, time_req, chan, input_token, + actual_mech_type, output_token, + ret_flags, time_rec); +} + %} + +%rename (initSecContext) reordered_init_sec_context; +//%apply gss_name_t INPUT {gss_name_t name}; +%apply void **INOUT {gss_ctx_id_t *context}; +%apply void **OUTPUT {gss_OID *mech}; +%apply gss_buffer_t OUTPUT {gss_buffer_t token}; +%apply OM_uint32 *OUTPUT {OM_uint32 *flags, OM_uint32 *time}; +%feature("autodoc", "initSecContext(gss_name_t name, gss_ctx_id_t *context=None, string token=None, gss_cred_id_t cred=None, gss_OID mech=krb5oid, int flags=0, int time=0, gss_channel_bindings_t chan=None) -> context, mech, token, flags, time"); +OM_uint32 reordered_init_sec_context + (OM_uint32 *minor, /* minor_status */ + gss_name_t name, /* target_name IN*/ + gss_ctx_id_t *context=NULL, /* context_handle INOUT*/ + gss_buffer_t INPUT=NULL, /* input_token IN */ + gss_cred_id_t cred=NULL, /* claimant_cred_handle IN*/ + gss_OID mech=&krb5oid, /* mech_type IN */ + OM_uint32 flags=MUTUAL_FLAG, /* req_flags IN*/ + OM_uint32 time=0, /* time_req IN */ + gss_channel_bindings_t chan=NULL, /* input_chan_bindings IN*/ + gss_OID *mech, /* actual_mech_type OUT*/ + gss_buffer_t token, /* output_token OUT*/ + OM_uint32 *flags, /* ret_flags OUT*/ + OM_uint32 *time /* time_rec OUT*/ + ); +//%clear gss_name_t name; +%clear gss_ctx_id_t *context; +%clear gss_OID *mech; +%clear gss_buffer_t token; +%clear OM_uint32 *flags, OM_uint32 *time; + +%{ +OM_uint32 reordered_gss_accept_sec_context +(OM_uint32 *minor, /* minor_status */ + gss_buffer_t in_token, /* input_token_buffer IN*/ + gss_ctx_id_t *context, /* context_handle INOUT */ + gss_cred_id_t in_cred, /* acceptor_cred_handle IN*/ + gss_channel_bindings_t chan, /* input_chan_bindings IN*/ + gss_name_t *name, /* src_name OUT*/ + gss_OID *mech, /* mech_type OUT*/ + gss_buffer_t token, /* output_token */ + OM_uint32 *flags, /* ret_flags OUT*/ + OM_uint32 *time, /* time_rec OUT*/ + gss_cred_id_t *cred /* delegated_cred_handle OUT*/ + ) { + return gss_accept_sec_context(minor, context, in_cred, in_token, chan, + name, mech, token, flags, time, cred); +} +%} + +%rename (acceptSecContext) reordered_gss_accept_sec_context; +%apply void **INOUT {gss_ctx_id_t *context}; +%apply gss_buffer_t INPUT {gss_buffer_t in_token}; +%apply void **OUTPUT {gss_name_t *name}; +%apply void **OUTPUT {gss_OID *mech}; +%apply gss_buffer_t OUTPUT {gss_buffer_t token}; +%apply OM_uint32 *OUTPUT {OM_uint32 *flags, OM_uint32 *time}; +%apply void **OUTPUT {gss_cred_id_t *cred}; +OM_uint32 reordered_gss_accept_sec_context +(OM_uint32 *minor, /* minor_status */ + gss_buffer_t in_token, /* input_token_buffer IN*/ + gss_ctx_id_t *context=NULL, /* context_handle INOUT */ + gss_cred_id_t in_cred=NULL, /* acceptor_cred_handle IN*/ + gss_channel_bindings_t chan=NULL, /* input_chan_bindings IN*/ + gss_name_t *name, /* src_name OUT*/ + gss_OID *mech, /* mech_type OUT*/ + gss_buffer_t token, /* output_token */ + OM_uint32 *flags, /* ret_flags OUT*/ + OM_uint32 *time, /* time_rec OUT*/ + gss_cred_id_t *cred /* delegated_cred_handle OUT*/ + ); +%clear gss_ctx_id_t *context; +%clear gss_buffer_t in_token; +%clear gss_name_t *name; +%clear gss_OID *mech; +%clear gss_buffer_t token; +%clear OM_uint32 *flags, OM_uint32 *time; +%clear gss_cred_id_t *cred; + + +%rename (getMIC) reordered_gss_get_mic; +%{ +OM_uint32 reordered_gss_get_mic +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t ctx, /* context_handle IN */ + gss_buffer_t msg, /* message_buffer IN */ + gss_qop_t qop, /* qop_req IN */ + gss_buffer_t token /* message_token OUT*/ + ) { + return gss_get_mic(minor, ctx, qop, msg, token); +} +%} +%apply gss_buffer_t INPUT {gss_buffer_t msg}; +%apply gss_buffer_t OUTPUT {gss_buffer_t token}; +%feature("autodoc", "getMIC(gss_ctx_id_t context, string msg, int qop) -> string checksum"); +OM_uint32 reordered_gss_get_mic +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t INPUT, /* context_handle IN */ + gss_buffer_t msg, /* message_buffer IN */ + gss_qop_t qop=0, /* qop_req IN */ + gss_buffer_t token /* message_token OUT*/ + ); +%clear gss_buffer_t token; +%clear gss_buffer_t msg; + +%rename (verifyMIC) gss_verify_mic; +%apply OM_uint32 *OUTPUT {gss_qop_t *qop}; +%feature("autodoc", "verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop"); +OM_uint32 gss_verify_mic +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t INPUT, /* context_handle IN */ + gss_buffer_t INPUT, /* message_buffer IN */ + gss_buffer_t INPUT, /* message_token IN */ + gss_qop_t *qop /* qop_state OUT */ + ); +%clear gss_qop_t *qop; + +%rename (wrap) reordered_gss_wrap; +%{ +OM_uint32 reordered_gss_wrap +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t ctx, /* context_handle IN */ + gss_buffer_t in_msg, /* input_message_buffer IN*/ + int conf_req, /* conf_req_flag IN */ + gss_qop_t qop, /* qop_req IN=0*/ + int *confidential, /* conf_state OUT*/ + gss_buffer_t msg /* output_message_buffer OUT*/ + ) { + return gss_wrap(minor, ctx, conf_req, qop, in_msg, confidential, msg); +} +%} +%apply gss_buffer_t INPUT {gss_buffer_t in_msg}; +%apply OM_uint32 *OUTPUT {int *confidential}; +%apply gss_buffer_t OUTPUT {gss_buffer_t msg}; +OM_uint32 reordered_gss_wrap +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t INPUT, /* context_handle IN */ + gss_buffer_t in_msg, /* input_message_buffer IN*/ + int conf_req=1, /* conf_req_flag IN */ + gss_qop_t qop=0, /* qop_req IN=0*/ + int *confidential, /* conf_state OUT*/ + gss_buffer_t msg /* output_message_buffer OUT*/ + ); +%clear gss_buffer_t in_msg; +%clear int *confidential; +%clear gss_buffer_t msg; + +%rename (unwrap) gss_unwrap; +%apply gss_buffer_t OUTPUT {gss_buffer_t msg}; +%apply OM_uint32 *OUTPUT {int *confidential}; +%apply OM_uint32 *OUTPUT {gss_qop_t *qop}; +OM_uint32 gss_unwrap +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t INPUT, /* context_handle IN*/ + gss_buffer_t INPUT, /* input_message_buffer IN*/ + gss_buffer_t msg, /* output_message_buffer OUT */ + int *confidential, /* conf_state OUT*/ + gss_qop_t *qop /* qop_state OUT */ + ); +%clear gss_buffer_t msg; +%clear int *confidential; +%clear gss_qop_t *qop; diff --git a/nfs3/lib/rpc/rpcsec/gssapi.py b/nfs3/lib/rpc/rpcsec/gssapi.py new file mode 100644 index 0000000..478a0c5 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gssapi.py @@ -0,0 +1,95 @@ +# This file was automatically generated by SWIG (http://www.swig.org). +# Version 1.3.35 +# +# Don't modify this file, modify the SWIG interface instead. +# This file is compatible with both classic and new-style classes. + +import _gssapi +import new +new_instancemethod = new.instancemethod +try: + _swig_property = property +except NameError: + pass # Python < 2.2 doesn't have 'property'. +def _swig_setattr_nondynamic(self,class_type,name,value,static=1): + if (name == "thisown"): return self.this.own(value) + if (name == "this"): + if type(value).__name__ == 'PySwigObject': + self.__dict__[name] = value + return + method = class_type.__swig_setmethods__.get(name,None) + if method: return method(self,value) + if (not static) or hasattr(self,name): + self.__dict__[name] = value + else: + raise AttributeError("You cannot add attributes to %s" % self) + +def _swig_setattr(self,class_type,name,value): + return _swig_setattr_nondynamic(self,class_type,name,value,0) + +def _swig_getattr(self,class_type,name): + if (name == "thisown"): return self.this.own() + method = class_type.__swig_getmethods__.get(name,None) + if method: return method(self) + raise AttributeError(name) + +def _swig_repr(self): + try: strthis = "proxy of " + self.this.__repr__() + except: strthis = "" + return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) + +import types +try: + _object = object + _newclass = 1 +except AttributeError: + class _object : pass + _newclass = 0 +del types + + +ptr2str = _gssapi.ptr2str +GSS_S_COMPLETE = _gssapi.GSS_S_COMPLETE +GSS_S_CONTINUE_NEEDED = _gssapi.GSS_S_CONTINUE_NEEDED +DELEG_FLAG = _gssapi.DELEG_FLAG +MUTUAL_FLAG = _gssapi.MUTUAL_FLAG +REPLAY_FLAG = _gssapi.REPLAY_FLAG +SEQUENCE_FLAG = _gssapi.SEQUENCE_FLAG +CONF_FLAG = _gssapi.CONF_FLAG +INTEG_FLAG = _gssapi.INTEG_FLAG +ANON_FLAG = _gssapi.ANON_FLAG +PROT_READY_FLAG = _gssapi.PROT_READY_FLAG +TRANS_FLAG = _gssapi.TRANS_FLAG + +def importName(*args): + """importName(string name, gss_OID name_type=HOSTBASED_SERVICE) -> name""" + return _gssapi.importName(*args) + +def initSecContext(*args): + """initSecContext(gss_name_t name, gss_ctx_id_t *context=None, string token=None, gss_cred_id_t cred=None, gss_OID mech=krb5oid, int flags=0, int time=0, gss_channel_bindings_t chan=None) -> context, mech, token, flags, time""" + return _gssapi.initSecContext(*args) + +def acceptSecContext(*args): + """initSecContext(gss_name_t name, gss_ctx_id_t *context=None, string token=None, gss_cred_id_t cred=None, gss_OID mech=krb5oid, int flags=0, int time=0, gss_channel_bindings_t chan=None) -> context, mech, token, flags, time""" + return _gssapi.acceptSecContext(*args) + +def getMIC(*args): + """getMIC(gss_ctx_id_t context, string msg, int qop) -> string checksum""" + return _gssapi.getMIC(*args) + +def verifyMIC(*args): + """verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop""" + return _gssapi.verifyMIC(*args) + +def wrap(*args): + """verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop""" + return _gssapi.wrap(*args) + +def unwrap(*args): + """verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop""" + return _gssapi.unwrap(*args) + +cvar = _gssapi.cvar +HOSTBASED_SERVICE = cvar.HOSTBASED_SERVICE +krb5oid = cvar.krb5oid + diff --git a/nfs3/lib/rpc/rpcsec/gssapi_wrap.c b/nfs3/lib/rpc/rpcsec/gssapi_wrap.c new file mode 100644 index 0000000..be97c1e --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/gssapi_wrap.c @@ -0,0 +1,4414 @@ +/* ---------------------------------------------------------------------------- + * This file was automatically generated by SWIG (http://www.swig.org). + * Version 1.3.35 + * + * This file is not intended to be easily readable and contains a number of + * coding conventions designed to improve portability and efficiency. Do not make + * changes to this file unless you know what you are doing--modify the SWIG + * interface file instead. + * ----------------------------------------------------------------------------- */ + +#define SWIGPYTHON +#define SWIG_PYTHON_DIRECTOR_NO_VTABLE +/* ----------------------------------------------------------------------------- + * This section contains generic SWIG labels for method/variable + * declarations/attributes, and other compiler dependent labels. + * ----------------------------------------------------------------------------- */ + +/* template workaround for compilers that cannot correctly implement the C++ standard */ +#ifndef SWIGTEMPLATEDISAMBIGUATOR +# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560) +# define SWIGTEMPLATEDISAMBIGUATOR template +# elif defined(__HP_aCC) +/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */ +/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */ +# define SWIGTEMPLATEDISAMBIGUATOR template +# else +# define SWIGTEMPLATEDISAMBIGUATOR +# endif +#endif + +/* inline attribute */ +#ifndef SWIGINLINE +# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) +# define SWIGINLINE inline +# else +# define SWIGINLINE +# endif +#endif + +/* attribute recognised by some compilers to avoid 'unused' warnings */ +#ifndef SWIGUNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +# elif defined(__ICC) +# define SWIGUNUSED __attribute__ ((__unused__)) +# else +# define SWIGUNUSED +# endif +#endif + +#ifndef SWIGUNUSEDPARM +# ifdef __cplusplus +# define SWIGUNUSEDPARM(p) +# else +# define SWIGUNUSEDPARM(p) p SWIGUNUSED +# endif +#endif + +/* internal SWIG method */ +#ifndef SWIGINTERN +# define SWIGINTERN static SWIGUNUSED +#endif + +/* internal inline SWIG method */ +#ifndef SWIGINTERNINLINE +# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE +#endif + +/* exporting methods */ +#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# ifndef GCC_HASCLASSVISIBILITY +# define GCC_HASCLASSVISIBILITY +# endif +#endif + +#ifndef SWIGEXPORT +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT +# else +# define SWIGEXPORT __declspec(dllexport) +# endif +# else +# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) +# define SWIGEXPORT __attribute__ ((visibility("default"))) +# else +# define SWIGEXPORT +# endif +# endif +#endif + +/* calling conventions for Windows */ +#ifndef SWIGSTDCALL +# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# define SWIGSTDCALL __stdcall +# else +# define SWIGSTDCALL +# endif +#endif + +/* Deal with Microsoft's attempt at deprecating C standard runtime functions */ +#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) +# define _CRT_SECURE_NO_DEPRECATE +#endif + +/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */ +#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE) +# define _SCL_SECURE_NO_DEPRECATE +#endif + + + +/* Python.h has to appear first */ +#include + +/* ----------------------------------------------------------------------------- + * swigrun.swg + * + * This file contains generic CAPI SWIG runtime support for pointer + * type checking. + * ----------------------------------------------------------------------------- */ + +/* This should only be incremented when either the layout of swig_type_info changes, + or for whatever reason, the runtime changes incompatibly */ +#define SWIG_RUNTIME_VERSION "4" + +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +# define SWIG_QUOTE_STRING(x) #x +# define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +# define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +# define SWIG_TYPE_TABLE_NAME +#endif + +/* + You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for + creating a static or dynamic library from the swig runtime code. + In 99.9% of the cases, swig just needs to declare them as 'static'. + + But only do this if is strictly necessary, ie, if you have problems + with your compiler or so. +*/ + +#ifndef SWIGRUNTIME +# define SWIGRUNTIME SWIGINTERN +#endif + +#ifndef SWIGRUNTIMEINLINE +# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE +#endif + +/* Generic buffer size */ +#ifndef SWIG_BUFFER_SIZE +# define SWIG_BUFFER_SIZE 1024 +#endif + +/* Flags for pointer conversions */ +#define SWIG_POINTER_DISOWN 0x1 +#define SWIG_CAST_NEW_MEMORY 0x2 + +/* Flags for new pointer objects */ +#define SWIG_POINTER_OWN 0x1 + + +/* + Flags/methods for returning states. + + The swig conversion methods, as ConvertPtr, return and integer + that tells if the conversion was successful or not. And if not, + an error code can be returned (see swigerrors.swg for the codes). + + Use the following macros/flags to set or process the returning + states. + + In old swig versions, you usually write code as: + + if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { + // success code + } else { + //fail code + } + + Now you can be more explicit as: + + int res = SWIG_ConvertPtr(obj,vptr,ty.flags); + if (SWIG_IsOK(res)) { + // success code + } else { + // fail code + } + + that seems to be the same, but now you can also do + + Type *ptr; + int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); + if (SWIG_IsOK(res)) { + // success code + if (SWIG_IsNewObj(res) { + ... + delete *ptr; + } else { + ... + } + } else { + // fail code + } + + I.e., now SWIG_ConvertPtr can return new objects and you can + identify the case and take care of the deallocation. Of course that + requires also to SWIG_ConvertPtr to return new result values, as + + int SWIG_ConvertPtr(obj, ptr,...) { + if () { + if () { + *ptr = ; + return SWIG_NEWOBJ; + } else { + *ptr = ; + return SWIG_OLDOBJ; + } + } else { + return SWIG_BADOBJ; + } + } + + Of course, returning the plain '0(success)/-1(fail)' still works, but you can be + more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the + swig errors code. + + Finally, if the SWIG_CASTRANK_MODE is enabled, the result code + allows to return the 'cast rank', for example, if you have this + + int food(double) + int fooi(int); + + and you call + + food(1) // cast rank '1' (1 -> 1.0) + fooi(1) // cast rank '0' + + just use the SWIG_AddCast()/SWIG_CheckState() + + + */ +#define SWIG_OK (0) +#define SWIG_ERROR (-1) +#define SWIG_IsOK(r) (r >= 0) +#define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) + +/* The CastRankLimit says how many bits are used for the cast rank */ +#define SWIG_CASTRANKLIMIT (1 << 8) +/* The NewMask denotes the object was created (using new/malloc) */ +#define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) +/* The TmpMask is for in/out typemaps that use temporal objects */ +#define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) +/* Simple returning values */ +#define SWIG_BADOBJ (SWIG_ERROR) +#define SWIG_OLDOBJ (SWIG_OK) +#define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) +#define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) +/* Check, add and del mask methods */ +#define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) +#define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) +#define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) +#define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) +#define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) +#define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) + + +/* Cast-Rank Mode */ +#if defined(SWIG_CASTRANK_MODE) +# ifndef SWIG_TypeRank +# define SWIG_TypeRank unsigned long +# endif +# ifndef SWIG_MAXCASTRANK /* Default cast allowed */ +# define SWIG_MAXCASTRANK (2) +# endif +# define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) +# define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) +SWIGINTERNINLINE int SWIG_AddCast(int r) { + return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; +} +SWIGINTERNINLINE int SWIG_CheckState(int r) { + return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; +} +#else /* no cast-rank mode */ +# define SWIG_AddCast +# define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) +#endif + + + + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void *(*swig_converter_func)(void *, int *); +typedef struct swig_type_info *(*swig_dycast_func)(void **); + +/* Structure to store information on one type */ +typedef struct swig_type_info { + const char *name; /* mangled name of this type */ + const char *str; /* human readable name of this type */ + swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ + struct swig_cast_info *cast; /* linked list of types that can cast into this type */ + void *clientdata; /* language specific type data */ + int owndata; /* flag if the structure owns the clientdata */ +} swig_type_info; + +/* Structure to store a type and conversion function used for casting */ +typedef struct swig_cast_info { + swig_type_info *type; /* pointer to type that is equivalent to this type */ + swig_converter_func converter; /* function to cast the void pointers */ + struct swig_cast_info *next; /* pointer to next cast in linked list */ + struct swig_cast_info *prev; /* pointer to the previous cast */ +} swig_cast_info; + +/* Structure used to store module information + * Each module generates one structure like this, and the runtime collects + * all of these structures and stores them in a circularly linked list.*/ +typedef struct swig_module_info { + swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ + size_t size; /* Number of types in this module */ + struct swig_module_info *next; /* Pointer to next element in circularly linked list */ + swig_type_info **type_initial; /* Array of initially generated type structures */ + swig_cast_info **cast_initial; /* Array of initially generated casting structures */ + void *clientdata; /* Language specific module data */ +} swig_module_info; + +/* + Compare two type names skipping the space characters, therefore + "char*" == "char *" and "Class" == "Class", etc. + + Return 0 when the two name types are equivalent, as in + strncmp, but skipping ' '. +*/ +SWIGRUNTIME int +SWIG_TypeNameComp(const char *f1, const char *l1, + const char *f2, const char *l2) { + for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { + while ((*f1 == ' ') && (f1 != l1)) ++f1; + while ((*f2 == ' ') && (f2 != l2)) ++f2; + if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; + } + return (int)((l1 - f1) - (l2 - f2)); +} + +/* + Check type equivalence in a name list like ||... + Return 0 if not equal, 1 if equal +*/ +SWIGRUNTIME int +SWIG_TypeEquiv(const char *nb, const char *tb) { + int equiv = 0; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (!equiv && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + if (*ne) ++ne; + } + return equiv; +} + +/* + Check type equivalence in a name list like ||... + Return 0 if equal, -1 if nb < tb, 1 if nb > tb +*/ +SWIGRUNTIME int +SWIG_TypeCompare(const char *nb, const char *tb) { + int equiv = 0; + const char* te = tb + strlen(tb); + const char* ne = nb; + while (!equiv && *ne) { + for (nb = ne; *ne; ++ne) { + if (*ne == '|') break; + } + equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; + if (*ne) ++ne; + } + return equiv; +} + + +/* think of this as a c++ template<> or a scheme macro */ +#define SWIG_TypeCheck_Template(comparison, ty) \ + if (ty) { \ + swig_cast_info *iter = ty->cast; \ + while (iter) { \ + if (comparison) { \ + if (iter == ty->cast) return iter; \ + /* Move iter to the top of the linked list */ \ + iter->prev->next = iter->next; \ + if (iter->next) \ + iter->next->prev = iter->prev; \ + iter->next = ty->cast; \ + iter->prev = 0; \ + if (ty->cast) ty->cast->prev = iter; \ + ty->cast = iter; \ + return iter; \ + } \ + iter = iter->next; \ + } \ + } \ + return 0 + +/* + Check the typename +*/ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheck(const char *c, swig_type_info *ty) { + SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty); +} + +/* Same as previous function, except strcmp is replaced with a pointer comparison */ +SWIGRUNTIME swig_cast_info * +SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { + SWIG_TypeCheck_Template(iter->type == from, into); +} + +/* + Cast a pointer up an inheritance hierarchy +*/ +SWIGRUNTIMEINLINE void * +SWIG_TypeCast(swig_cast_info *ty, void *ptr, int *newmemory) { + return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr, newmemory); +} + +/* + Dynamic pointer casting. Down an inheritance hierarchy +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { + swig_type_info *lastty = ty; + if (!ty || !ty->dcast) return ty; + while (ty && (ty->dcast)) { + ty = (*ty->dcast)(ptr); + if (ty) lastty = ty; + } + return lastty; +} + +/* + Return the name associated with this type +*/ +SWIGRUNTIMEINLINE const char * +SWIG_TypeName(const swig_type_info *ty) { + return ty->name; +} + +/* + Return the pretty name associated with this type, + that is an unmangled type name in a form presentable to the user. +*/ +SWIGRUNTIME const char * +SWIG_TypePrettyName(const swig_type_info *type) { + /* The "str" field contains the equivalent pretty names of the + type, separated by vertical-bar characters. We choose + to print the last name, as it is often (?) the most + specific. */ + if (!type) return NULL; + if (type->str != NULL) { + const char *last_name = type->str; + const char *s; + for (s = type->str; *s; s++) + if (*s == '|') last_name = s+1; + return last_name; + } + else + return type->name; +} + +/* + Set the clientdata field for a type +*/ +SWIGRUNTIME void +SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { + swig_cast_info *cast = ti->cast; + /* if (ti->clientdata == clientdata) return; */ + ti->clientdata = clientdata; + + while (cast) { + if (!cast->converter) { + swig_type_info *tc = cast->type; + if (!tc->clientdata) { + SWIG_TypeClientData(tc, clientdata); + } + } + cast = cast->next; + } +} +SWIGRUNTIME void +SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { + SWIG_TypeClientData(ti, clientdata); + ti->owndata = 1; +} + +/* + Search for a swig_type_info structure only by mangled name + Search is a O(log #types) + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_MangledTypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + swig_module_info *iter = start; + do { + if (iter->size) { + register size_t l = 0; + register size_t r = iter->size - 1; + do { + /* since l+r >= 0, we can (>> 1) instead (/ 2) */ + register size_t i = (l + r) >> 1; + const char *iname = iter->types[i]->name; + if (iname) { + register int compare = strcmp(name, iname); + if (compare == 0) { + return iter->types[i]; + } else if (compare < 0) { + if (i) { + r = i - 1; + } else { + break; + } + } else if (compare > 0) { + l = i + 1; + } + } else { + break; /* should never happen */ + } + } while (l <= r); + } + iter = iter->next; + } while (iter != end); + return 0; +} + +/* + Search for a swig_type_info structure for either a mangled name or a human readable name. + It first searches the mangled names of the types, which is a O(log #types) + If a type is not found it then searches the human readable names, which is O(#types). + + We start searching at module start, and finish searching when start == end. + Note: if start == end at the beginning of the function, we go all the way around + the circular list. +*/ +SWIGRUNTIME swig_type_info * +SWIG_TypeQueryModule(swig_module_info *start, + swig_module_info *end, + const char *name) { + /* STEP 1: Search the name field using binary search */ + swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); + if (ret) { + return ret; + } else { + /* STEP 2: If the type hasn't been found, do a complete search + of the str field (the human readable name) */ + swig_module_info *iter = start; + do { + register size_t i = 0; + for (; i < iter->size; ++i) { + if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) + return iter->types[i]; + } + iter = iter->next; + } while (iter != end); + } + + /* neither found a match */ + return 0; +} + +/* + Pack binary data into a string +*/ +SWIGRUNTIME char * +SWIG_PackData(char *c, void *ptr, size_t sz) { + static const char hex[17] = "0123456789abcdef"; + register const unsigned char *u = (unsigned char *) ptr; + register const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + register unsigned char uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; +} + +/* + Unpack binary data from a string +*/ +SWIGRUNTIME const char * +SWIG_UnpackData(const char *c, void *ptr, size_t sz) { + register unsigned char *u = (unsigned char *) ptr; + register const unsigned char *eu = u + sz; + for (; u != eu; ++u) { + register char d = *(c++); + register unsigned char uu; + if ((d >= '0') && (d <= '9')) + uu = ((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = ((d - ('a'-10)) << 4); + else + return (char *) 0; + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (d - ('a'-10)); + else + return (char *) 0; + *u = uu; + } + return c; +} + +/* + Pack 'void *' into a string buffer. +*/ +SWIGRUNTIME char * +SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { + char *r = buff; + if ((2*sizeof(void *) + 2) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,&ptr,sizeof(void *)); + if (strlen(name) + 1 > (bsz - (r - buff))) return 0; + strcpy(r,name); + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + *ptr = (void *) 0; + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sizeof(void *)); +} + +SWIGRUNTIME char * +SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { + char *r = buff; + size_t lname = (name ? strlen(name) : 0); + if ((2*sz + 2 + lname) > bsz) return 0; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + if (lname) { + strncpy(r,name,lname+1); + } else { + *r = 0; + } + return buff; +} + +SWIGRUNTIME const char * +SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { + if (*c != '_') { + if (strcmp(c,"NULL") == 0) { + memset(ptr,0,sz); + return name; + } else { + return 0; + } + } + return SWIG_UnpackData(++c,ptr,sz); +} + +#ifdef __cplusplus +} +#endif + +/* Errors in SWIG */ +#define SWIG_UnknownError -1 +#define SWIG_IOError -2 +#define SWIG_RuntimeError -3 +#define SWIG_IndexError -4 +#define SWIG_TypeError -5 +#define SWIG_DivisionByZero -6 +#define SWIG_OverflowError -7 +#define SWIG_SyntaxError -8 +#define SWIG_ValueError -9 +#define SWIG_SystemError -10 +#define SWIG_AttributeError -11 +#define SWIG_MemoryError -12 +#define SWIG_NullReferenceError -13 + + + + +/* Add PyOS_snprintf for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) +# define PyOS_snprintf _snprintf +# else +# define PyOS_snprintf snprintf +# endif +#endif + +/* A crude PyString_FromFormat implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 + +#ifndef SWIG_PYBUFFER_SIZE +# define SWIG_PYBUFFER_SIZE 1024 +#endif + +static PyObject * +PyString_FromFormat(const char *fmt, ...) { + va_list ap; + char buf[SWIG_PYBUFFER_SIZE * 2]; + int res; + va_start(ap, fmt); + res = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); + return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); +} +#endif + +/* Add PyObject_Del for old Pythons */ +#if PY_VERSION_HEX < 0x01060000 +# define PyObject_Del(op) PyMem_DEL((op)) +#endif +#ifndef PyObject_DEL +# define PyObject_DEL PyObject_Del +#endif + +/* A crude PyExc_StopIteration exception for old Pythons */ +#if PY_VERSION_HEX < 0x02020000 +# ifndef PyExc_StopIteration +# define PyExc_StopIteration PyExc_RuntimeError +# endif +# ifndef PyObject_GenericGetAttr +# define PyObject_GenericGetAttr 0 +# endif +#endif +/* Py_NotImplemented is defined in 2.1 and up. */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef Py_NotImplemented +# define Py_NotImplemented PyExc_RuntimeError +# endif +#endif + + +/* A crude PyString_AsStringAndSize implementation for old Pythons */ +#if PY_VERSION_HEX < 0x02010000 +# ifndef PyString_AsStringAndSize +# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} +# endif +#endif + +/* PySequence_Size for old Pythons */ +#if PY_VERSION_HEX < 0x02000000 +# ifndef PySequence_Size +# define PySequence_Size PySequence_Length +# endif +#endif + + +/* PyBool_FromLong for old Pythons */ +#if PY_VERSION_HEX < 0x02030000 +static +PyObject *PyBool_FromLong(long ok) +{ + PyObject *result = ok ? Py_True : Py_False; + Py_INCREF(result); + return result; +} +#endif + +/* Py_ssize_t for old Pythons */ +/* This code is as recommended by: */ +/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) +typedef int Py_ssize_t; +# define PY_SSIZE_T_MAX INT_MAX +# define PY_SSIZE_T_MIN INT_MIN +#endif + +/* ----------------------------------------------------------------------------- + * error manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIME PyObject* +SWIG_Python_ErrorType(int code) { + PyObject* type = 0; + switch(code) { + case SWIG_MemoryError: + type = PyExc_MemoryError; + break; + case SWIG_IOError: + type = PyExc_IOError; + break; + case SWIG_RuntimeError: + type = PyExc_RuntimeError; + break; + case SWIG_IndexError: + type = PyExc_IndexError; + break; + case SWIG_TypeError: + type = PyExc_TypeError; + break; + case SWIG_DivisionByZero: + type = PyExc_ZeroDivisionError; + break; + case SWIG_OverflowError: + type = PyExc_OverflowError; + break; + case SWIG_SyntaxError: + type = PyExc_SyntaxError; + break; + case SWIG_ValueError: + type = PyExc_ValueError; + break; + case SWIG_SystemError: + type = PyExc_SystemError; + break; + case SWIG_AttributeError: + type = PyExc_AttributeError; + break; + default: + type = PyExc_RuntimeError; + } + return type; +} + + +SWIGRUNTIME void +SWIG_Python_AddErrorMsg(const char* mesg) +{ + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + + if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + PyErr_Clear(); + Py_XINCREF(type); + PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); + Py_DECREF(old_str); + Py_DECREF(value); + } else { + PyErr_SetString(PyExc_RuntimeError, mesg); + } +} + + + +#if defined(SWIG_PYTHON_NO_THREADS) +# if defined(SWIG_PYTHON_THREADS) +# undef SWIG_PYTHON_THREADS +# endif +#endif +#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ +# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) +# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ +# define SWIG_PYTHON_USE_GIL +# endif +# endif +# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ +# ifndef SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() +# endif +# ifdef __cplusplus /* C++ code */ + class SWIG_Python_Thread_Block { + bool status; + PyGILState_STATE state; + public: + void end() { if (status) { PyGILState_Release(state); status = false;} } + SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} + ~SWIG_Python_Thread_Block() { end(); } + }; + class SWIG_Python_Thread_Allow { + bool status; + PyThreadState *save; + public: + void end() { if (status) { PyEval_RestoreThread(save); status = false; }} + SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} + ~SWIG_Python_Thread_Allow() { end(); } + }; +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block +# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow +# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() +# else /* C code */ +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() +# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() +# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) +# endif +# else /* Old thread way, not implemented, user must provide it */ +# if !defined(SWIG_PYTHON_INITIALIZE_THREADS) +# define SWIG_PYTHON_INITIALIZE_THREADS +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) +# define SWIG_PYTHON_THREAD_END_BLOCK +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# endif +# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) +# define SWIG_PYTHON_THREAD_END_ALLOW +# endif +# endif +#else /* No thread support */ +# define SWIG_PYTHON_INITIALIZE_THREADS +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK +# define SWIG_PYTHON_THREAD_END_BLOCK +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW +# define SWIG_PYTHON_THREAD_END_ALLOW +#endif + +/* ----------------------------------------------------------------------------- + * Python API portion that goes into the runtime + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* ----------------------------------------------------------------------------- + * Constant declarations + * ----------------------------------------------------------------------------- */ + +/* Constant Types */ +#define SWIG_PY_POINTER 4 +#define SWIG_PY_BINARY 5 + +/* Constant information structure */ +typedef struct swig_const_info { + int type; + char *name; + long lvalue; + double dvalue; + void *pvalue; + swig_type_info **ptype; +} swig_const_info; + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + +/* ----------------------------------------------------------------------------- + * See the LICENSE file for information on copyright, usage and redistribution + * of SWIG, and the README file for authors - http://www.swig.org/release.html. + * + * pyrun.swg + * + * This file contains the runtime support for Python modules + * and includes code for managing global variables and pointer + * type checking. + * + * ----------------------------------------------------------------------------- */ + +/* Common SWIG API */ + +/* for raw pointers */ +#define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) +#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) +#define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) +#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) +#define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) +#define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) +#define swig_owntype int + +/* for raw packed data */ +#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + +/* for class or struct pointers */ +#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) +#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) + +/* for C or C++ function pointers */ +#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) +#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) + +/* for C++ member pointers, ie, member methods */ +#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) +#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) + + +/* Runtime API */ + +#define SWIG_GetModule(clientdata) SWIG_Python_GetModule() +#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) +#define SWIG_NewClientData(obj) PySwigClientData_New(obj) + +#define SWIG_SetErrorObj SWIG_Python_SetErrorObj +#define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg +#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) +#define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) +#define SWIG_fail goto fail + + +/* Runtime API implementation */ + +/* Error manipulation */ + +SWIGINTERN void +SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetObject(errtype, obj); + Py_DECREF(obj); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +SWIGINTERN void +SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { + SWIG_PYTHON_THREAD_BEGIN_BLOCK; + PyErr_SetString(errtype, (char *) msg); + SWIG_PYTHON_THREAD_END_BLOCK; +} + +#define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) + +/* Set a constant value */ + +SWIGINTERN void +SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { + PyDict_SetItemString(d, (char*) name, obj); + Py_DECREF(obj); +} + +/* Append a value to the result obj */ + +SWIGINTERN PyObject* +SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { +#if !defined(SWIG_PYTHON_OUTPUT_TUPLE) + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyList_Check(result)) { + PyObject *o2 = result; + result = PyList_New(1); + PyList_SetItem(result, 0, o2); + } + PyList_Append(result,obj); + Py_DECREF(obj); + } + return result; +#else + PyObject* o2; + PyObject* o3; + if (!result) { + result = obj; + } else if (result == Py_None) { + Py_DECREF(result); + result = obj; + } else { + if (!PyTuple_Check(result)) { + o2 = result; + result = PyTuple_New(1); + PyTuple_SET_ITEM(result, 0, o2); + } + o3 = PyTuple_New(1); + PyTuple_SET_ITEM(o3, 0, obj); + o2 = result; + result = PySequence_Concat(o2, o3); + Py_DECREF(o2); + Py_DECREF(o3); + } + return result; +#endif +} + +/* Unpack the argument tuple */ + +SWIGINTERN int +SWIG_Python_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t max, PyObject **objs) +{ + if (!args) { + if (!min && !max) { + return 1; + } else { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", + name, (min == max ? "" : "at least "), (int)min); + return 0; + } + } + if (!PyTuple_Check(args)) { + PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); + return 0; + } else { + register Py_ssize_t l = PyTuple_GET_SIZE(args); + if (l < min) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at least "), (int)min, (int)l); + return 0; + } else if (l > max) { + PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", + name, (min == max ? "" : "at most "), (int)max, (int)l); + return 0; + } else { + register int i; + for (i = 0; i < l; ++i) { + objs[i] = PyTuple_GET_ITEM(args, i); + } + for (; l < max; ++l) { + objs[l] = 0; + } + return i + 1; + } + } +} + +/* A functor is a function object with one single object argument */ +#if PY_VERSION_HEX >= 0x02020000 +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); +#else +#define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); +#endif + +/* + Helper for static pointer initialization for both C and C++ code, for example + static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); +*/ +#ifdef __cplusplus +#define SWIG_STATIC_POINTER(var) var +#else +#define SWIG_STATIC_POINTER(var) var = 0; if (!var) var +#endif + +/* ----------------------------------------------------------------------------- + * Pointer declarations + * ----------------------------------------------------------------------------- */ + +/* Flags for new pointer objects */ +#define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) +#define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) + +#define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* cc-mode */ +#endif +#endif + +/* How to access Py_None */ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# ifndef SWIG_PYTHON_NO_BUILD_NONE +# ifndef SWIG_PYTHON_BUILD_NONE +# define SWIG_PYTHON_BUILD_NONE +# endif +# endif +#endif + +#ifdef SWIG_PYTHON_BUILD_NONE +# ifdef Py_None +# undef Py_None +# define Py_None SWIG_Py_None() +# endif +SWIGRUNTIMEINLINE PyObject * +_SWIG_Py_None(void) +{ + PyObject *none = Py_BuildValue((char*)""); + Py_DECREF(none); + return none; +} +SWIGRUNTIME PyObject * +SWIG_Py_None(void) +{ + static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); + return none; +} +#endif + +/* The python void return value */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Py_Void(void) +{ + PyObject *none = Py_None; + Py_INCREF(none); + return none; +} + +/* PySwigClientData */ + +typedef struct { + PyObject *klass; + PyObject *newraw; + PyObject *newargs; + PyObject *destroy; + int delargs; + int implicitconv; +} PySwigClientData; + +SWIGRUNTIMEINLINE int +SWIG_Python_CheckImplicit(swig_type_info *ty) +{ + PySwigClientData *data = (PySwigClientData *)ty->clientdata; + return data ? data->implicitconv : 0; +} + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_ExceptionType(swig_type_info *desc) { + PySwigClientData *data = desc ? (PySwigClientData *) desc->clientdata : 0; + PyObject *klass = data ? data->klass : 0; + return (klass ? klass : PyExc_RuntimeError); +} + + +SWIGRUNTIME PySwigClientData * +PySwigClientData_New(PyObject* obj) +{ + if (!obj) { + return 0; + } else { + PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData)); + /* the klass element */ + data->klass = obj; + Py_INCREF(data->klass); + /* the newraw method and newargs arguments used to create a new raw instance */ + if (PyClass_Check(obj)) { + data->newraw = 0; + data->newargs = obj; + Py_INCREF(obj); + } else { +#if (PY_VERSION_HEX < 0x02020000) + data->newraw = 0; +#else + data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); +#endif + if (data->newraw) { + Py_INCREF(data->newraw); + data->newargs = PyTuple_New(1); + PyTuple_SetItem(data->newargs, 0, obj); + } else { + data->newargs = obj; + } + Py_INCREF(data->newargs); + } + /* the destroy method, aka as the C++ delete method */ + data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); + if (PyErr_Occurred()) { + PyErr_Clear(); + data->destroy = 0; + } + if (data->destroy) { + int flags; + Py_INCREF(data->destroy); + flags = PyCFunction_GET_FLAGS(data->destroy); +#ifdef METH_O + data->delargs = !(flags & (METH_O)); +#else + data->delargs = 0; +#endif + } else { + data->delargs = 0; + } + data->implicitconv = 0; + return data; + } +} + +SWIGRUNTIME void +PySwigClientData_Del(PySwigClientData* data) +{ + Py_XDECREF(data->newraw); + Py_XDECREF(data->newargs); + Py_XDECREF(data->destroy); +} + +/* =============== PySwigObject =====================*/ + +typedef struct { + PyObject_HEAD + void *ptr; + swig_type_info *ty; + int own; + PyObject *next; +} PySwigObject; + +SWIGRUNTIME PyObject * +PySwigObject_long(PySwigObject *v) +{ + return PyLong_FromVoidPtr(v->ptr); +} + +SWIGRUNTIME PyObject * +PySwigObject_format(const char* fmt, PySwigObject *v) +{ + PyObject *res = NULL; + PyObject *args = PyTuple_New(1); + if (args) { + if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) { + PyObject *ofmt = PyString_FromString(fmt); + if (ofmt) { + res = PyString_Format(ofmt,args); + Py_DECREF(ofmt); + } + Py_DECREF(args); + } + } + return res; +} + +SWIGRUNTIME PyObject * +PySwigObject_oct(PySwigObject *v) +{ + return PySwigObject_format("%o",v); +} + +SWIGRUNTIME PyObject * +PySwigObject_hex(PySwigObject *v) +{ + return PySwigObject_format("%x",v); +} + +SWIGRUNTIME PyObject * +#ifdef METH_NOARGS +PySwigObject_repr(PySwigObject *v) +#else +PySwigObject_repr(PySwigObject *v, PyObject *args) +#endif +{ + const char *name = SWIG_TypePrettyName(v->ty); + PyObject *hex = PySwigObject_hex(v); + PyObject *repr = PyString_FromFormat("", name, PyString_AsString(hex)); + Py_DECREF(hex); + if (v->next) { +#ifdef METH_NOARGS + PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next); +#else + PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next, args); +#endif + PyString_ConcatAndDel(&repr,nrep); + } + return repr; +} + +SWIGRUNTIME int +PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ +#ifdef METH_NOARGS + PyObject *repr = PySwigObject_repr(v); +#else + PyObject *repr = PySwigObject_repr(v, NULL); +#endif + if (repr) { + fputs(PyString_AsString(repr), fp); + Py_DECREF(repr); + return 0; + } else { + return 1; + } +} + +SWIGRUNTIME PyObject * +PySwigObject_str(PySwigObject *v) +{ + char result[SWIG_BUFFER_SIZE]; + return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? + PyString_FromString(result) : 0; +} + +SWIGRUNTIME int +PySwigObject_compare(PySwigObject *v, PySwigObject *w) +{ + void *i = v->ptr; + void *j = w->ptr; + return (i < j) ? -1 : ((i > j) ? 1 : 0); +} + +SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); + +SWIGRUNTIME PyTypeObject* +PySwigObject_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); + return type; +} + +SWIGRUNTIMEINLINE int +PySwigObject_Check(PyObject *op) { + return ((op)->ob_type == PySwigObject_type()) + || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); +} + +SWIGRUNTIME PyObject * +PySwigObject_New(void *ptr, swig_type_info *ty, int own); + +SWIGRUNTIME void +PySwigObject_dealloc(PyObject *v) +{ + PySwigObject *sobj = (PySwigObject *) v; + PyObject *next = sobj->next; + if (sobj->own == SWIG_POINTER_OWN) { + swig_type_info *ty = sobj->ty; + PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; + PyObject *destroy = data ? data->destroy : 0; + if (destroy) { + /* destroy is always a VARARGS method */ + PyObject *res; + if (data->delargs) { + /* we need to create a temporal object to carry the destroy operation */ + PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); + res = SWIG_Python_CallFunctor(destroy, tmp); + Py_DECREF(tmp); + } else { + PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); + PyObject *mself = PyCFunction_GET_SELF(destroy); + res = ((*meth)(mself, v)); + } + Py_XDECREF(res); + } +#if !defined(SWIG_PYTHON_SILENT_MEMLEAK) + else { + const char *name = SWIG_TypePrettyName(ty); + printf("swig/python detected a memory leak of type '%s', no destructor found.\n", (name ? name : "unknown")); + } +#endif + } + Py_XDECREF(next); + PyObject_DEL(v); +} + +SWIGRUNTIME PyObject* +PySwigObject_append(PyObject* v, PyObject* next) +{ + PySwigObject *sobj = (PySwigObject *) v; +#ifndef METH_O + PyObject *tmp = 0; + if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; + next = tmp; +#endif + if (!PySwigObject_Check(next)) { + return NULL; + } + sobj->next = next; + Py_INCREF(next); + return SWIG_Py_Void(); +} + +SWIGRUNTIME PyObject* +#ifdef METH_NOARGS +PySwigObject_next(PyObject* v) +#else +PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + PySwigObject *sobj = (PySwigObject *) v; + if (sobj->next) { + Py_INCREF(sobj->next); + return sobj->next; + } else { + return SWIG_Py_Void(); + } +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +PySwigObject_disown(PyObject *v) +#else +PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + PySwigObject *sobj = (PySwigObject *)v; + sobj->own = 0; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +#ifdef METH_NOARGS +PySwigObject_acquire(PyObject *v) +#else +PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) +#endif +{ + PySwigObject *sobj = (PySwigObject *)v; + sobj->own = SWIG_POINTER_OWN; + return SWIG_Py_Void(); +} + +SWIGINTERN PyObject* +PySwigObject_own(PyObject *v, PyObject *args) +{ + PyObject *val = 0; +#if (PY_VERSION_HEX < 0x02020000) + if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) +#else + if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) +#endif + { + return NULL; + } + else + { + PySwigObject *sobj = (PySwigObject *)v; + PyObject *obj = PyBool_FromLong(sobj->own); + if (val) { +#ifdef METH_NOARGS + if (PyObject_IsTrue(val)) { + PySwigObject_acquire(v); + } else { + PySwigObject_disown(v); + } +#else + if (PyObject_IsTrue(val)) { + PySwigObject_acquire(v,args); + } else { + PySwigObject_disown(v,args); + } +#endif + } + return obj; + } +} + +#ifdef METH_O +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)PySwigObject_append, METH_O, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)PySwigObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_NOARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#else +static PyMethodDef +swigobject_methods[] = { + {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, + {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, + {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, + {(char *)"append", (PyCFunction)PySwigObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, + {(char *)"next", (PyCFunction)PySwigObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, + {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_VARARGS, (char *)"returns object representation"}, + {0, 0, 0, 0} +}; +#endif + +#if PY_VERSION_HEX < 0x02020000 +SWIGINTERN PyObject * +PySwigObject_getattr(PySwigObject *sobj,char *name) +{ + return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); +} +#endif + +SWIGRUNTIME PyTypeObject* +_PySwigObject_type(void) { + static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; + + static PyNumberMethods PySwigObject_as_number = { + (binaryfunc)0, /*nb_add*/ + (binaryfunc)0, /*nb_subtract*/ + (binaryfunc)0, /*nb_multiply*/ + (binaryfunc)0, /*nb_divide*/ + (binaryfunc)0, /*nb_remainder*/ + (binaryfunc)0, /*nb_divmod*/ + (ternaryfunc)0,/*nb_power*/ + (unaryfunc)0, /*nb_negative*/ + (unaryfunc)0, /*nb_positive*/ + (unaryfunc)0, /*nb_absolute*/ + (inquiry)0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + (coercion)0, /*nb_coerce*/ + (unaryfunc)PySwigObject_long, /*nb_int*/ + (unaryfunc)PySwigObject_long, /*nb_long*/ + (unaryfunc)0, /*nb_float*/ + (unaryfunc)PySwigObject_oct, /*nb_oct*/ + (unaryfunc)PySwigObject_hex, /*nb_hex*/ +#if PY_VERSION_HEX >= 0x02050000 /* 2.5.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_index */ +#elif PY_VERSION_HEX >= 0x02020000 /* 2.2.0 */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ +#elif PY_VERSION_HEX >= 0x02000000 /* 2.0.0 */ + 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ +#endif + }; + + static PyTypeObject pyswigobject_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + (char *)"PySwigObject", /* tp_name */ + sizeof(PySwigObject), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PySwigObject_dealloc, /* tp_dealloc */ + (printfunc)PySwigObject_print, /* tp_print */ +#if PY_VERSION_HEX < 0x02020000 + (getattrfunc)PySwigObject_getattr, /* tp_getattr */ +#else + (getattrfunc)0, /* tp_getattr */ +#endif + (setattrfunc)0, /* tp_setattr */ + (cmpfunc)PySwigObject_compare, /* tp_compare */ + (reprfunc)PySwigObject_repr, /* tp_repr */ + &PySwigObject_as_number, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)PySwigObject_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigobject_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + swigobject_methods, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + pyswigobject_type = tmp; + pyswigobject_type.ob_type = &PyType_Type; + type_init = 1; + } + return &pyswigobject_type; +} + +SWIGRUNTIME PyObject * +PySwigObject_New(void *ptr, swig_type_info *ty, int own) +{ + PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type()); + if (sobj) { + sobj->ptr = ptr; + sobj->ty = ty; + sobj->own = own; + sobj->next = 0; + } + return (PyObject *)sobj; +} + +/* ----------------------------------------------------------------------------- + * Implements a simple Swig Packed type, and use it instead of string + * ----------------------------------------------------------------------------- */ + +typedef struct { + PyObject_HEAD + void *pack; + swig_type_info *ty; + size_t size; +} PySwigPacked; + +SWIGRUNTIME int +PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) +{ + char result[SWIG_BUFFER_SIZE]; + fputs("pack, v->size, 0, sizeof(result))) { + fputs("at ", fp); + fputs(result, fp); + } + fputs(v->ty->name,fp); + fputs(">", fp); + return 0; +} + +SWIGRUNTIME PyObject * +PySwigPacked_repr(PySwigPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { + return PyString_FromFormat("", result, v->ty->name); + } else { + return PyString_FromFormat("", v->ty->name); + } +} + +SWIGRUNTIME PyObject * +PySwigPacked_str(PySwigPacked *v) +{ + char result[SWIG_BUFFER_SIZE]; + if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ + return PyString_FromFormat("%s%s", result, v->ty->name); + } else { + return PyString_FromString(v->ty->name); + } +} + +SWIGRUNTIME int +PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) +{ + size_t i = v->size; + size_t j = w->size; + int s = (i < j) ? -1 : ((i > j) ? 1 : 0); + return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); +} + +SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); + +SWIGRUNTIME PyTypeObject* +PySwigPacked_type(void) { + static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); + return type; +} + +SWIGRUNTIMEINLINE int +PySwigPacked_Check(PyObject *op) { + return ((op)->ob_type == _PySwigPacked_type()) + || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); +} + +SWIGRUNTIME void +PySwigPacked_dealloc(PyObject *v) +{ + if (PySwigPacked_Check(v)) { + PySwigPacked *sobj = (PySwigPacked *) v; + free(sobj->pack); + } + PyObject_DEL(v); +} + +SWIGRUNTIME PyTypeObject* +_PySwigPacked_type(void) { + static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; + static PyTypeObject pyswigpacked_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + PyObject_HEAD_INIT(NULL) + 0, /* ob_size */ + (char *)"PySwigPacked", /* tp_name */ + sizeof(PySwigPacked), /* tp_basicsize */ + 0, /* tp_itemsize */ + (destructor)PySwigPacked_dealloc, /* tp_dealloc */ + (printfunc)PySwigPacked_print, /* tp_print */ + (getattrfunc)0, /* tp_getattr */ + (setattrfunc)0, /* tp_setattr */ + (cmpfunc)PySwigPacked_compare, /* tp_compare */ + (reprfunc)PySwigPacked_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + (hashfunc)0, /* tp_hash */ + (ternaryfunc)0, /* tp_call */ + (reprfunc)PySwigPacked_str, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + Py_TPFLAGS_DEFAULT, /* tp_flags */ + swigpacked_doc, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0, /* tp_iter */ + 0, /* tp_iternext */ + 0, /* tp_methods */ + 0, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + 0, /* tp_init */ + 0, /* tp_alloc */ + 0, /* tp_new */ + 0, /* tp_free */ + 0, /* tp_is_gc */ + 0, /* tp_bases */ + 0, /* tp_mro */ + 0, /* tp_cache */ + 0, /* tp_subclasses */ + 0, /* tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + pyswigpacked_type = tmp; + pyswigpacked_type.ob_type = &PyType_Type; + type_init = 1; + } + return &pyswigpacked_type; +} + +SWIGRUNTIME PyObject * +PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) +{ + PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type()); + if (sobj) { + void *pack = malloc(size); + if (pack) { + memcpy(pack, ptr, size); + sobj->pack = pack; + sobj->ty = ty; + sobj->size = size; + } else { + PyObject_DEL((PyObject *) sobj); + sobj = 0; + } + } + return (PyObject *) sobj; +} + +SWIGRUNTIME swig_type_info * +PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) +{ + if (PySwigPacked_Check(obj)) { + PySwigPacked *sobj = (PySwigPacked *)obj; + if (sobj->size != size) return 0; + memcpy(ptr, sobj->pack, size); + return sobj->ty; + } else { + return 0; + } +} + +/* ----------------------------------------------------------------------------- + * pointers/data manipulation + * ----------------------------------------------------------------------------- */ + +SWIGRUNTIMEINLINE PyObject * +_SWIG_This(void) +{ + return PyString_FromString("this"); +} + +SWIGRUNTIME PyObject * +SWIG_This(void) +{ + static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); + return swig_this; +} + +/* #define SWIG_PYTHON_SLOW_GETSET_THIS */ + +SWIGRUNTIME PySwigObject * +SWIG_Python_GetSwigThis(PyObject *pyobj) +{ + if (PySwigObject_Check(pyobj)) { + return (PySwigObject *) pyobj; + } else { + PyObject *obj = 0; +#if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) + if (PyInstance_Check(pyobj)) { + obj = _PyInstance_Lookup(pyobj, SWIG_This()); + } else { + PyObject **dictptr = _PyObject_GetDictPtr(pyobj); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; + } else { +#ifdef PyWeakref_CheckProxy + if (PyWeakref_CheckProxy(pyobj)) { + PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); + return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; + } +#endif + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } + } + } +#else + obj = PyObject_GetAttr(pyobj,SWIG_This()); + if (obj) { + Py_DECREF(obj); + } else { + if (PyErr_Occurred()) PyErr_Clear(); + return 0; + } +#endif + if (obj && !PySwigObject_Check(obj)) { + /* a PyObject is called 'this', try to get the 'real this' + PySwigObject from it */ + return SWIG_Python_GetSwigThis(obj); + } + return (PySwigObject *)obj; + } +} + +/* Acquire a pointer value */ + +SWIGRUNTIME int +SWIG_Python_AcquirePtr(PyObject *obj, int own) { + if (own == SWIG_POINTER_OWN) { + PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (sobj) { + int oldown = sobj->own; + sobj->own = own; + return oldown; + } + } + return 0; +} + +/* Convert a pointer value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { + if (!obj) return SWIG_ERROR; + if (obj == Py_None) { + if (ptr) *ptr = 0; + return SWIG_OK; + } else { + PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); + if (own) + *own = 0; + while (sobj) { + void *vptr = sobj->ptr; + if (ty) { + swig_type_info *to = sobj->ty; + if (to == ty) { + /* no type cast needed */ + if (ptr) *ptr = vptr; + break; + } else { + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) { + sobj = (PySwigObject *)sobj->next; + } else { + if (ptr) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + if (newmemory == SWIG_CAST_NEW_MEMORY) { + assert(own); + if (own) + *own = *own | SWIG_CAST_NEW_MEMORY; + } + } + break; + } + } + } else { + if (ptr) *ptr = vptr; + break; + } + } + if (sobj) { + if (own) + *own = *own | sobj->own; + if (flags & SWIG_POINTER_DISOWN) { + sobj->own = 0; + } + return SWIG_OK; + } else { + int res = SWIG_ERROR; + if (flags & SWIG_POINTER_IMPLICIT_CONV) { + PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; + if (data && !data->implicitconv) { + PyObject *klass = data->klass; + if (klass) { + PyObject *impconv; + data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ + impconv = SWIG_Python_CallFunctor(klass, obj); + data->implicitconv = 0; + if (PyErr_Occurred()) { + PyErr_Clear(); + impconv = 0; + } + if (impconv) { + PySwigObject *iobj = SWIG_Python_GetSwigThis(impconv); + if (iobj) { + void *vptr; + res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); + if (SWIG_IsOK(res)) { + if (ptr) { + *ptr = vptr; + /* transfer the ownership to 'ptr' */ + iobj->own = 0; + res = SWIG_AddCast(res); + res = SWIG_AddNewMask(res); + } else { + res = SWIG_AddCast(res); + } + } + } + Py_DECREF(impconv); + } + } + } + } + return res; + } + } +} + +/* Convert a function ptr value */ + +SWIGRUNTIME int +SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { + if (!PyCFunction_Check(obj)) { + return SWIG_ConvertPtr(obj, ptr, ty, 0); + } else { + void *vptr = 0; + + /* here we get the method pointer for callbacks */ + const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); + const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; + if (desc) { + desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; + if (!desc) return SWIG_ERROR; + } + if (ty) { + swig_cast_info *tc = SWIG_TypeCheck(desc,ty); + if (tc) { + int newmemory = 0; + *ptr = SWIG_TypeCast(tc,vptr,&newmemory); + assert(!newmemory); /* newmemory handling not yet implemented */ + } else { + return SWIG_ERROR; + } + } else { + *ptr = vptr; + } + return SWIG_OK; + } +} + +/* Convert a packed value value */ + +SWIGRUNTIME int +SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { + swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz); + if (!to) return SWIG_ERROR; + if (ty) { + if (to != ty) { + /* check type cast? */ + swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); + if (!tc) return SWIG_ERROR; + } + } + return SWIG_OK; +} + +/* ----------------------------------------------------------------------------- + * Create a new pointer object + * ----------------------------------------------------------------------------- */ + +/* + Create a new instance object, whitout calling __init__, and set the + 'this' attribute. +*/ + +SWIGRUNTIME PyObject* +SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this) +{ +#if (PY_VERSION_HEX >= 0x02020000) + PyObject *inst = 0; + PyObject *newraw = data->newraw; + if (newraw) { + inst = PyObject_Call(newraw, data->newargs, NULL); + if (inst) { +#if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + PyObject *dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + PyDict_SetItem(dict, SWIG_This(), swig_this); + } + } +#else + PyObject *key = SWIG_This(); + PyObject_SetAttr(inst, key, swig_this); +#endif + } + } else { + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + } + return inst; +#else +#if (PY_VERSION_HEX >= 0x02010000) + PyObject *inst; + PyObject *dict = PyDict_New(); + PyDict_SetItem(dict, SWIG_This(), swig_this); + inst = PyInstance_NewRaw(data->newargs, dict); + Py_DECREF(dict); + return (PyObject *) inst; +#else + PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); + if (inst == NULL) { + return NULL; + } + inst->in_class = (PyClassObject *)data->newargs; + Py_INCREF(inst->in_class); + inst->in_dict = PyDict_New(); + if (inst->in_dict == NULL) { + Py_DECREF(inst); + return NULL; + } +#ifdef Py_TPFLAGS_HAVE_WEAKREFS + inst->in_weakreflist = NULL; +#endif +#ifdef Py_TPFLAGS_GC + PyObject_GC_Init(inst); +#endif + PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); + return (PyObject *) inst; +#endif +#endif +} + +SWIGRUNTIME void +SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) +{ + PyObject *dict; +#if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) + PyObject **dictptr = _PyObject_GetDictPtr(inst); + if (dictptr != NULL) { + dict = *dictptr; + if (dict == NULL) { + dict = PyDict_New(); + *dictptr = dict; + } + PyDict_SetItem(dict, SWIG_This(), swig_this); + return; + } +#endif + dict = PyObject_GetAttrString(inst, (char*)"__dict__"); + PyDict_SetItem(dict, SWIG_This(), swig_this); + Py_DECREF(dict); +} + + +SWIGINTERN PyObject * +SWIG_Python_InitShadowInstance(PyObject *args) { + PyObject *obj[2]; + if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { + return NULL; + } else { + PySwigObject *sthis = SWIG_Python_GetSwigThis(obj[0]); + if (sthis) { + PySwigObject_append((PyObject*) sthis, obj[1]); + } else { + SWIG_Python_SetSwigThis(obj[0], obj[1]); + } + return SWIG_Py_Void(); + } +} + +/* Create a new pointer object */ + +SWIGRUNTIME PyObject * +SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { + if (!ptr) { + return SWIG_Py_Void(); + } else { + int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; + PyObject *robj = PySwigObject_New(ptr, type, own); + PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0; + if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { + PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); + if (inst) { + Py_DECREF(robj); + robj = inst; + } + } + return robj; + } +} + +/* Create a new packed object */ + +SWIGRUNTIMEINLINE PyObject * +SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { + return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); +} + +/* -----------------------------------------------------------------------------* + * Get type list + * -----------------------------------------------------------------------------*/ + +#ifdef SWIG_LINK_RUNTIME +void *SWIG_ReturnGlobalTypeList(void *); +#endif + +SWIGRUNTIME swig_module_info * +SWIG_Python_GetModule(void) { + static void *type_pointer = (void *)0; + /* first check if module already created */ + if (!type_pointer) { +#ifdef SWIG_LINK_RUNTIME + type_pointer = SWIG_ReturnGlobalTypeList((void *)0); +#else + type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); + if (PyErr_Occurred()) { + PyErr_Clear(); + type_pointer = (void *)0; + } +#endif + } + return (swig_module_info *) type_pointer; +} + +#if PY_MAJOR_VERSION < 2 +/* PyModule_AddObject function was introduced in Python 2.0. The following function + is copied out of Python/modsupport.c in python version 2.3.4 */ +SWIGINTERN int +PyModule_AddObject(PyObject *m, char *name, PyObject *o) +{ + PyObject *dict; + if (!PyModule_Check(m)) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs module as first arg"); + return SWIG_ERROR; + } + if (!o) { + PyErr_SetString(PyExc_TypeError, + "PyModule_AddObject() needs non-NULL value"); + return SWIG_ERROR; + } + + dict = PyModule_GetDict(m); + if (dict == NULL) { + /* Internal error -- modules must have a dict! */ + PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", + PyModule_GetName(m)); + return SWIG_ERROR; + } + if (PyDict_SetItemString(dict, name, o)) + return SWIG_ERROR; + Py_DECREF(o); + return SWIG_OK; +} +#endif + +SWIGRUNTIME void +SWIG_Python_DestroyModule(void *vptr) +{ + swig_module_info *swig_module = (swig_module_info *) vptr; + swig_type_info **types = swig_module->types; + size_t i; + for (i =0; i < swig_module->size; ++i) { + swig_type_info *ty = types[i]; + if (ty->owndata) { + PySwigClientData *data = (PySwigClientData *) ty->clientdata; + if (data) PySwigClientData_Del(data); + } + } + Py_DECREF(SWIG_This()); +} + +SWIGRUNTIME void +SWIG_Python_SetModule(swig_module_info *swig_module) { + static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ + + PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, + swig_empty_runtime_method_table); + PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); + if (pointer && module) { + PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); + } else { + Py_XDECREF(pointer); + } +} + +/* The python cached type query */ +SWIGRUNTIME PyObject * +SWIG_Python_TypeCache(void) { + static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); + return cache; +} + +SWIGRUNTIME swig_type_info * +SWIG_Python_TypeQuery(const char *type) +{ + PyObject *cache = SWIG_Python_TypeCache(); + PyObject *key = PyString_FromString(type); + PyObject *obj = PyDict_GetItem(cache, key); + swig_type_info *descriptor; + if (obj) { + descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); + } else { + swig_module_info *swig_module = SWIG_Python_GetModule(); + descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); + if (descriptor) { + obj = PyCObject_FromVoidPtr(descriptor, NULL); + PyDict_SetItem(cache, key, obj); + Py_DECREF(obj); + } + } + Py_DECREF(key); + return descriptor; +} + +/* + For backward compatibility only +*/ +#define SWIG_POINTER_EXCEPTION 0 +#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) +#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) + +SWIGRUNTIME int +SWIG_Python_AddErrMesg(const char* mesg, int infront) +{ + if (PyErr_Occurred()) { + PyObject *type = 0; + PyObject *value = 0; + PyObject *traceback = 0; + PyErr_Fetch(&type, &value, &traceback); + if (value) { + PyObject *old_str = PyObject_Str(value); + Py_XINCREF(type); + PyErr_Clear(); + if (infront) { + PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); + } else { + PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); + } + Py_DECREF(old_str); + } + return 1; + } else { + return 0; + } +} + +SWIGRUNTIME int +SWIG_Python_ArgFail(int argnum) +{ + if (PyErr_Occurred()) { + /* add information about failing argument */ + char mesg[256]; + PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); + return SWIG_Python_AddErrMesg(mesg, 1); + } else { + return 0; + } +} + +SWIGRUNTIMEINLINE const char * +PySwigObject_GetDesc(PyObject *self) +{ + PySwigObject *v = (PySwigObject *)self; + swig_type_info *ty = v ? v->ty : 0; + return ty ? ty->str : (char*)""; +} + +SWIGRUNTIME void +SWIG_Python_TypeError(const char *type, PyObject *obj) +{ + if (type) { +#if defined(SWIG_COBJECT_TYPES) + if (obj && PySwigObject_Check(obj)) { + const char *otype = (const char *) PySwigObject_GetDesc(obj); + if (otype) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", + type, otype); + return; + } + } else +#endif + { + const char *otype = (obj ? obj->ob_type->tp_name : 0); + if (otype) { + PyObject *str = PyObject_Str(obj); + const char *cstr = str ? PyString_AsString(str) : 0; + if (cstr) { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", + type, otype, cstr); + } else { + PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", + type, otype); + } + Py_XDECREF(str); + return; + } + } + PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); + } else { + PyErr_Format(PyExc_TypeError, "unexpected type is received"); + } +} + + +/* Convert a pointer value, signal an exception on a type mismatch */ +SWIGRUNTIME void * +SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { + void *result; + if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { + PyErr_Clear(); + if (flags & SWIG_POINTER_EXCEPTION) { + SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); + SWIG_Python_ArgFail(argnum); + } + } + return result; +} + + +#ifdef __cplusplus +#if 0 +{ /* cc-mode */ +#endif +} +#endif + + + +#define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) + +#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else + + + +/* -------- TYPES TABLE (BEGIN) -------- */ + +#define SWIGTYPE_gss_OID swig_types[0] +#define SWIGTYPE_p_char swig_types[1] +#define SWIGTYPE_p_gss_OID swig_types[2] +#define SWIGTYPE_p_gss_buffer_t swig_types[3] +#define SWIGTYPE_p_gss_channel_bindings_t swig_types[4] +#define SWIGTYPE_p_gss_cred_id_struct swig_types[5] +#define SWIGTYPE_p_gss_ctx_id_struct swig_types[6] +#define SWIGTYPE_p_gss_name_struct swig_types[7] +#define SWIGTYPE_p_int swig_types[8] +#define SWIGTYPE_p_p_gss_cred_id_struct swig_types[9] +#define SWIGTYPE_p_p_gss_ctx_id_struct swig_types[10] +#define SWIGTYPE_p_p_gss_name_struct swig_types[11] +#define SWIGTYPE_p_unsigned_int swig_types[12] +static swig_type_info *swig_types[14]; +static swig_module_info swig_module = {swig_types, 13, 0, 0, 0, 0}; +#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) +#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) + +/* -------- TYPES TABLE (END) -------- */ + +#if (PY_VERSION_HEX <= 0x02000000) +# if !defined(SWIG_PYTHON_CLASSIC) +# error "This python version requires swig to be run with the '-classic' option" +# endif +#endif + +/*----------------------------------------------- + @(target):= _gssapi.so + ------------------------------------------------*/ +#define SWIG_init init_gssapi + +#define SWIG_name "_gssapi" + +#define SWIGVERSION 0x010335 +#define SWIG_VERSION SWIGVERSION + + +#define SWIG_as_voidptr(a) (void *)((const void *)(a)) +#define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) + + +#ifdef HEIMDAL +#include +#else +#include +#if 0 /* I don't think these are needed */ +#include +#include +#endif +#endif /* HEIMDAL */ + +gss_OID_desc krb5oid = { + .length = 9, + .elements = "\052\206\110\206\367\022\001\002\002"}; + + + +char *ptr2str(void *ptr) { + return (char *) ptr; +} + + +SWIGINTERN swig_type_info* +SWIG_pchar_descriptor(void) +{ + static int init = 0; + static swig_type_info* info = 0; + if (!init) { + info = SWIG_TypeQuery("_p_char"); + init = 1; + } + return info; +} + + +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtrAndSize(const char* carray, size_t size) +{ + if (carray) { + if (size > INT_MAX) { + swig_type_info* pchar_descriptor = SWIG_pchar_descriptor(); + return pchar_descriptor ? + SWIG_NewPointerObj((char *)(carray), pchar_descriptor, 0) : SWIG_Py_Void(); + } else { + return PyString_FromStringAndSize(carray, (int)(size)); + } + } else { + return SWIG_Py_Void(); + } +} + + +SWIGINTERNINLINE PyObject * +SWIG_FromCharPtr(const char *cptr) +{ + return SWIG_FromCharPtrAndSize(cptr, (cptr ? strlen(cptr) : 0)); +} + +gss_OID krb5oid_ptr = &krb5oid; + + #define SWIG_From_long PyInt_FromLong + + +SWIGINTERNINLINE PyObject * +SWIG_From_int (int value) +{ + return SWIG_From_long (value); +} + + +/* Reorder arguments so we can set defaults easily */ +OM_uint32 reordered_init_sec_context + (OM_uint32 *minor, /* minor_status */ + gss_name_t name, /* target_name IN*/ + gss_ctx_id_t *context, /* context_handle INOUT*/ + gss_buffer_t input_token, /* input_token IN */ + gss_cred_id_t cred, /* claimant_cred_handle IN*/ + gss_OID mech, /* mech_type IN */ + OM_uint32 req_flags, /* req_flags IN*/ + OM_uint32 time_req, /* time_req IN */ + gss_channel_bindings_t chan, /* input_chan_bindings IN*/ + gss_OID *actual_mech_type, /* actual_mech_type OUT*/ + gss_buffer_t output_token, /* output_token OUT*/ + OM_uint32 *ret_flags, /* ret_flags OUT*/ + OM_uint32 *time_rec) /* time_rec OUT*/ { + return gss_init_sec_context(minor, cred, context, name, mech, + req_flags, time_req, chan, input_token, + actual_mech_type, output_token, + ret_flags, time_rec); +} + + +#include +#if !defined(SWIG_NO_LLONG_MAX) +# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__) +# define LLONG_MAX __LONG_LONG_MAX__ +# define LLONG_MIN (-LLONG_MAX - 1LL) +# define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) +# endif +#endif + + +SWIGINTERN int +SWIG_AsVal_double (PyObject *obj, double *val) +{ + int res = SWIG_TypeError; + if (PyFloat_Check(obj)) { + if (val) *val = PyFloat_AsDouble(obj); + return SWIG_OK; + } else if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else if (PyLong_Check(obj)) { + double v = PyLong_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + double d = PyFloat_AsDouble(obj); + if (!PyErr_Occurred()) { + if (val) *val = d; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_AddCast(SWIG_OK)); + } else { + PyErr_Clear(); + } + } + } +#endif + return res; +} + + +#include + + +#include + + +SWIGINTERNINLINE int +SWIG_CanCastAsInteger(double *d, double min, double max) { + double x = *d; + if ((min <= x && x <= max)) { + double fx = floor(x); + double cx = ceil(x); + double rd = ((x - fx) < 0.5) ? fx : cx; /* simple rint */ + if ((errno == EDOM) || (errno == ERANGE)) { + errno = 0; + } else { + double summ, reps, diff; + if (rd < x) { + diff = x - rd; + } else if (rd > x) { + diff = rd - x; + } else { + return 1; + } + summ = rd + x; + reps = diff/summ; + if (reps < 8*DBL_EPSILON) { + *d = rd; + return 1; + } + } + } + return 0; +} + + +SWIGINTERN int +SWIG_AsVal_unsigned_SS_long (PyObject *obj, unsigned long *val) +{ + if (PyInt_Check(obj)) { + long v = PyInt_AsLong(obj); + if (v >= 0) { + if (val) *val = v; + return SWIG_OK; + } else { + return SWIG_OverflowError; + } + } else if (PyLong_Check(obj)) { + unsigned long v = PyLong_AsUnsignedLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + unsigned long v = PyLong_AsUnsignedLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + double d; + int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); + if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, 0, ULONG_MAX)) { + if (val) *val = (unsigned long)(d); + return res; + } + } + } +#endif + return SWIG_TypeError; +} + + +SWIGINTERN int +SWIG_AsVal_unsigned_SS_int (PyObject * obj, unsigned int *val) +{ + unsigned long v; + int res = SWIG_AsVal_unsigned_SS_long (obj, &v); + if (SWIG_IsOK(res)) { + if ((v > UINT_MAX)) { + return SWIG_OverflowError; + } else { + if (val) *val = (unsigned int)(v); + } + } + return res; +} + + +OM_uint32 reordered_gss_accept_sec_context +(OM_uint32 *minor, /* minor_status */ + gss_buffer_t in_token, /* input_token_buffer IN*/ + gss_ctx_id_t *context, /* context_handle INOUT */ + gss_cred_id_t in_cred, /* acceptor_cred_handle IN*/ + gss_channel_bindings_t chan, /* input_chan_bindings IN*/ + gss_name_t *name, /* src_name OUT*/ + gss_OID *mech, /* mech_type OUT*/ + gss_buffer_t token, /* output_token */ + OM_uint32 *flags, /* ret_flags OUT*/ + OM_uint32 *time, /* time_rec OUT*/ + gss_cred_id_t *cred /* delegated_cred_handle OUT*/ + ) { + return gss_accept_sec_context(minor, context, in_cred, in_token, chan, + name, mech, token, flags, time, cred); +} + + +OM_uint32 reordered_gss_get_mic +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t ctx, /* context_handle IN */ + gss_buffer_t msg, /* message_buffer IN */ + gss_qop_t qop, /* qop_req IN */ + gss_buffer_t token /* message_token OUT*/ + ) { + return gss_get_mic(minor, ctx, qop, msg, token); +} + + +OM_uint32 reordered_gss_wrap +(OM_uint32 *minor, /* minor_status */ + gss_ctx_id_t ctx, /* context_handle IN */ + gss_buffer_t in_msg, /* input_message_buffer IN*/ + int conf_req, /* conf_req_flag IN */ + gss_qop_t qop, /* qop_req IN=0*/ + int *confidential, /* conf_state OUT*/ + gss_buffer_t msg /* output_message_buffer OUT*/ + ) { + return gss_wrap(minor, ctx, conf_req, qop, in_msg, confidential, msg); +} + + +SWIGINTERN int +SWIG_AsVal_long (PyObject *obj, long* val) +{ + if (PyInt_Check(obj)) { + if (val) *val = PyInt_AsLong(obj); + return SWIG_OK; + } else if (PyLong_Check(obj)) { + long v = PyLong_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_OK; + } else { + PyErr_Clear(); + } + } +#ifdef SWIG_PYTHON_CAST_MODE + { + int dispatch = 0; + long v = PyInt_AsLong(obj); + if (!PyErr_Occurred()) { + if (val) *val = v; + return SWIG_AddCast(SWIG_OK); + } else { + PyErr_Clear(); + } + if (!dispatch) { + double d; + int res = SWIG_AddCast(SWIG_AsVal_double (obj,&d)); + if (SWIG_IsOK(res) && SWIG_CanCastAsInteger(&d, LONG_MIN, LONG_MAX)) { + if (val) *val = (long)(d); + return res; + } + } + } +#endif + return SWIG_TypeError; +} + + +SWIGINTERN int +SWIG_AsVal_int (PyObject * obj, int *val) +{ + long v; + int res = SWIG_AsVal_long (obj, &v); + if (SWIG_IsOK(res)) { + if ((v < INT_MIN || v > INT_MAX)) { + return SWIG_OverflowError; + } else { + if (val) *val = (int)(v); + } + } + return res; +} + +#ifdef __cplusplus +extern "C" { +#endif +SWIGINTERN PyObject *_wrap_ptr2str(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + void *arg1 = (void *) 0 ; + char *result = 0 ; + int res1 ; + PyObject * obj0 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"O:ptr2str",&obj0)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0,SWIG_as_voidptrptr(&arg1), 0, 0); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ptr2str" "', argument " "1"" of type '" "void *""'"); + } + result = (char *)ptr2str(arg1); + resultobj = SWIG_FromCharPtr((const char *)result); + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN int Swig_var_HOSTBASED_SERVICE_set(PyObject *_val SWIGUNUSED) { + SWIG_Error(SWIG_AttributeError,"Variable HOSTBASED_SERVICE is read-only."); + return 1; +} + + +SWIGINTERN PyObject *Swig_var_HOSTBASED_SERVICE_get(void) { + PyObject *pyobj = 0; + + pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(&GSS_C_NT_HOSTBASED_SERVICE), SWIGTYPE_p_gss_OID, 0 ); + return pyobj; +} + + +SWIGINTERN int Swig_var_krb5oid_set(PyObject *_val SWIGUNUSED) { + SWIG_Error(SWIG_AttributeError,"Variable krb5oid is read-only."); + return 1; +} + + +SWIGINTERN PyObject *Swig_var_krb5oid_get(void) { + PyObject *pyobj = 0; + + pyobj = SWIG_NewPointerObj(SWIG_as_voidptr(&krb5oid_ptr), SWIGTYPE_p_gss_OID, 0 ); + return pyobj; +} + + +SWIGINTERN PyObject *_wrap_importName(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_buffer_t arg2 ; + gss_OID arg3 = (gss_OID) GSS_C_NT_HOSTBASED_SERVICE ; + gss_name_t *arg4 = (gss_name_t *) 0 ; + OM_uint32 result; + OM_uint32 temp1 = 0 ; + gss_buffer_desc temp2 ; + void *argp3 ; + int res3 = 0 ; + void *temp4 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + { + ; + arg1 = &temp1; + } + { + ; + arg4 = (gss_name_t *) &temp4; + } + if (!PyArg_ParseTuple(args,(char *)"O|O:importName",&obj0,&obj1)) SWIG_fail; + { + ; + if (obj0 == Py_None) { + /* Allow None as equivalent to "" */ + arg2 = NULL; + //temp2.value = NULL; + //temp2.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj0, + (char **) &temp2.value, + (Py_ssize_t *) &temp2.length); + + if (stat == -1) + return NULL; + //temp2.length++; /* Add null to count*/ + arg2 = &temp2; + } + } + if (obj1) { + { + res3 = SWIG_ConvertPtr(obj1, &argp3, SWIGTYPE_p_gss_OID, 0 ); + if (!SWIG_IsOK(res3)) { + SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "importName" "', argument " "3"" of type '" "gss_OID""'"); + } + if (!argp3) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "importName" "', argument " "3"" of type '" "gss_OID""'"); + } else { + arg3 = *((gss_OID *)(argp3)); + } + } + } + result = (OM_uint32)gss_import_name(arg1,arg2,arg3,arg4); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "name", + SWIG_NewPointerObj(*(arg4), SWIGTYPE_p_gss_name_struct, 0)) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_initSecContext(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_name_t arg2 = (gss_name_t) 0 ; + gss_ctx_id_t *arg3 = (gss_ctx_id_t *) NULL ; + gss_buffer_t arg4 = (gss_buffer_t) NULL ; + gss_cred_id_t arg5 = (gss_cred_id_t) NULL ; + gss_OID arg6 = (gss_OID) &krb5oid ; + OM_uint32 arg7 = (OM_uint32) 2 ; + OM_uint32 arg8 = (OM_uint32) 0 ; + gss_channel_bindings_t arg9 = (gss_channel_bindings_t) NULL ; + gss_OID *arg10 = (gss_OID *) 0 ; + gss_buffer_t arg11 ; + OM_uint32 *arg12 = (OM_uint32 *) 0 ; + OM_uint32 *arg13 = (OM_uint32 *) 0 ; + OM_uint32 result; + void *temp3 = NULL ; + OM_uint32 temp1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + void *temp30 ; + gss_buffer_desc temp4 ; + void *argp5 = 0 ; + int res5 = 0 ; + void *argp6 ; + int res6 = 0 ; + unsigned int val7 ; + int ecode7 = 0 ; + unsigned int val8 ; + int ecode8 = 0 ; + void *argp9 ; + int res9 = 0 ; + void *temp10 ; + gss_buffer_desc temp11 ; + OM_uint32 temp12 = 0 ; + OM_uint32 temp13 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + PyObject * obj4 = 0 ; + PyObject * obj5 = 0 ; + PyObject * obj6 = 0 ; + PyObject * obj7 = 0 ; + + { + arg3 = (gss_ctx_id_t *) &temp3; /* correctly set default to NULL */ + } + { + ; + arg1 = &temp1; + } + { + ; + arg10 = (gss_OID *) &temp10; + } + { + ; + arg11 = &temp11; + } + { + ; + arg12 = &temp12; + } + { + ; + arg13 = &temp13; + } + if (!PyArg_ParseTuple(args,(char *)"O|OOOOOOO:initSecContext",&obj0,&obj1,&obj2,&obj3,&obj4,&obj5,&obj6,&obj7)) SWIG_fail; + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_gss_name_struct, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "initSecContext" "', argument " "2"" of type '" "gss_name_t""'"); + } + arg2 = (gss_name_t)(argp2); + if (obj1) { + { + /* obj1 is a (void *) */ + ; + if (SWIG_ConvertPtr(obj1, &temp30, SWIGTYPE_p_gss_ctx_id_struct, SWIG_POINTER_EXCEPTION) == -1) { + /* Assume is a python string */ + PyErr_Clear(); + temp30 = (void *) PyString_AsString(obj1); + if (!temp30) + return NULL; + /* Convert '' to NULL */ + if (!*(char *)temp30) + temp30 = NULL; + } + arg3 = (gss_ctx_id_t *) &temp30; + } + } + if (obj2) { + { + ; + if (obj2 == Py_None) { + /* Allow None as equivalent to "" */ + arg4 = NULL; + //temp4.value = NULL; + //temp4.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj2, + (char **) &temp4.value, + (Py_ssize_t *) &temp4.length); + + if (stat == -1) + return NULL; + //temp4.length++; /* Add null to count*/ + arg4 = &temp4; + } + } + } + if (obj3) { + res5 = SWIG_ConvertPtr(obj3, &argp5,SWIGTYPE_p_gss_cred_id_struct, 0 | 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "initSecContext" "', argument " "5"" of type '" "gss_cred_id_t""'"); + } + arg5 = (gss_cred_id_t)(argp5); + } + if (obj4) { + { + res6 = SWIG_ConvertPtr(obj4, &argp6, SWIGTYPE_p_gss_OID, 0 ); + if (!SWIG_IsOK(res6)) { + SWIG_exception_fail(SWIG_ArgError(res6), "in method '" "initSecContext" "', argument " "6"" of type '" "gss_OID""'"); + } + if (!argp6) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "initSecContext" "', argument " "6"" of type '" "gss_OID""'"); + } else { + arg6 = *((gss_OID *)(argp6)); + } + } + } + if (obj5) { + ecode7 = SWIG_AsVal_unsigned_SS_int(obj5, &val7); + if (!SWIG_IsOK(ecode7)) { + SWIG_exception_fail(SWIG_ArgError(ecode7), "in method '" "initSecContext" "', argument " "7"" of type '" "OM_uint32""'"); + } + arg7 = (OM_uint32)(val7); + } + if (obj6) { + ecode8 = SWIG_AsVal_unsigned_SS_int(obj6, &val8); + if (!SWIG_IsOK(ecode8)) { + SWIG_exception_fail(SWIG_ArgError(ecode8), "in method '" "initSecContext" "', argument " "8"" of type '" "OM_uint32""'"); + } + arg8 = (OM_uint32)(val8); + } + if (obj7) { + { + res9 = SWIG_ConvertPtr(obj7, &argp9, SWIGTYPE_p_gss_channel_bindings_t, 0 ); + if (!SWIG_IsOK(res9)) { + SWIG_exception_fail(SWIG_ArgError(res9), "in method '" "initSecContext" "', argument " "9"" of type '" "gss_channel_bindings_t""'"); + } + if (!argp9) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "initSecContext" "', argument " "9"" of type '" "gss_channel_bindings_t""'"); + } else { + arg9 = *((gss_channel_bindings_t *)(argp9)); + } + } + } + result = (OM_uint32)reordered_init_sec_context(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "context", + SWIG_NewPointerObj(*(arg3), SWIGTYPE_p_gss_ctx_id_struct, 0)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "mech", + SWIG_NewPointerObj(*(arg10), SWIGTYPE_gss_OID, 0)) == -1) + return NULL; + } + { + PyObject *o; + ; + o = PyString_FromStringAndSize(arg11->value, arg11->length); + if (!o) + return NULL; + if (PyDict_SetItemString(resultobj, "token", o) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "flags", PyLong_FromUnsignedLong((unsigned long)*arg12)) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "time", PyLong_FromUnsignedLong((unsigned long)*arg13)) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_acceptSecContext(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_buffer_t arg2 ; + gss_ctx_id_t *arg3 = (gss_ctx_id_t *) NULL ; + gss_cred_id_t arg4 = (gss_cred_id_t) NULL ; + gss_channel_bindings_t arg5 = (gss_channel_bindings_t) NULL ; + gss_name_t *arg6 = (gss_name_t *) 0 ; + gss_OID *arg7 = (gss_OID *) 0 ; + gss_buffer_t arg8 ; + OM_uint32 *arg9 = (OM_uint32 *) 0 ; + OM_uint32 *arg10 = (OM_uint32 *) 0 ; + gss_cred_id_t *arg11 = (gss_cred_id_t *) 0 ; + OM_uint32 result; + void *temp3 = NULL ; + OM_uint32 temp1 = 0 ; + gss_buffer_desc temp2 ; + void *temp30 ; + void *argp4 = 0 ; + int res4 = 0 ; + void *argp5 ; + int res5 = 0 ; + void *temp6 ; + void *temp7 ; + gss_buffer_desc temp8 ; + OM_uint32 temp9 = 0 ; + OM_uint32 temp10 = 0 ; + void *temp11 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + + { + arg3 = (gss_ctx_id_t *) &temp3; /* correctly set default to NULL */ + } + { + ; + arg1 = &temp1; + } + { + ; + arg6 = (gss_name_t *) &temp6; + } + { + ; + arg7 = (gss_OID *) &temp7; + } + { + ; + arg8 = &temp8; + } + { + ; + arg9 = &temp9; + } + { + ; + arg10 = &temp10; + } + { + ; + arg11 = (gss_cred_id_t *) &temp11; + } + if (!PyArg_ParseTuple(args,(char *)"O|OOO:acceptSecContext",&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + { + ; + if (obj0 == Py_None) { + /* Allow None as equivalent to "" */ + arg2 = NULL; + //temp2.value = NULL; + //temp2.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj0, + (char **) &temp2.value, + (Py_ssize_t *) &temp2.length); + + if (stat == -1) + return NULL; + //temp2.length++; /* Add null to count*/ + arg2 = &temp2; + } + } + if (obj1) { + { + /* obj1 is a (void *) */ + ; + if (SWIG_ConvertPtr(obj1, &temp30, SWIGTYPE_p_gss_ctx_id_struct, SWIG_POINTER_EXCEPTION) == -1) { + /* Assume is a python string */ + PyErr_Clear(); + temp30 = (void *) PyString_AsString(obj1); + if (!temp30) + return NULL; + /* Convert '' to NULL */ + if (!*(char *)temp30) + temp30 = NULL; + } + arg3 = (gss_ctx_id_t *) &temp30; + } + } + if (obj2) { + res4 = SWIG_ConvertPtr(obj2, &argp4,SWIGTYPE_p_gss_cred_id_struct, 0 | 0 ); + if (!SWIG_IsOK(res4)) { + SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "acceptSecContext" "', argument " "4"" of type '" "gss_cred_id_t""'"); + } + arg4 = (gss_cred_id_t)(argp4); + } + if (obj3) { + { + res5 = SWIG_ConvertPtr(obj3, &argp5, SWIGTYPE_p_gss_channel_bindings_t, 0 ); + if (!SWIG_IsOK(res5)) { + SWIG_exception_fail(SWIG_ArgError(res5), "in method '" "acceptSecContext" "', argument " "5"" of type '" "gss_channel_bindings_t""'"); + } + if (!argp5) { + SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "acceptSecContext" "', argument " "5"" of type '" "gss_channel_bindings_t""'"); + } else { + arg5 = *((gss_channel_bindings_t *)(argp5)); + } + } + } + result = (OM_uint32)reordered_gss_accept_sec_context(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "context", + SWIG_NewPointerObj(*(arg3), SWIGTYPE_p_gss_ctx_id_struct, 0)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "name", + SWIG_NewPointerObj(*(arg6), SWIGTYPE_p_gss_name_struct, 0)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "mech", + SWIG_NewPointerObj(*(arg7), SWIGTYPE_gss_OID, 0)) == -1) + return NULL; + } + { + PyObject *o; + ; + o = PyString_FromStringAndSize(arg8->value, arg8->length); + if (!o) + return NULL; + if (PyDict_SetItemString(resultobj, "token", o) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "flags", PyLong_FromUnsignedLong((unsigned long)*arg9)) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "time", PyLong_FromUnsignedLong((unsigned long)*arg10)) == -1) + return NULL; + } + { + /* returns a (void *) */ + ; + if (PyDict_SetItemString(resultobj, "cred", + SWIG_NewPointerObj(*(arg11), SWIGTYPE_p_gss_cred_id_struct, 0)) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_getMIC(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_ctx_id_t arg2 = (gss_ctx_id_t) 0 ; + gss_buffer_t arg3 ; + gss_qop_t arg4 = (gss_qop_t) 0 ; + gss_buffer_t arg5 ; + OM_uint32 result; + OM_uint32 temp1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + gss_buffer_desc temp3 ; + unsigned int val4 ; + int ecode4 = 0 ; + gss_buffer_desc temp5 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + + { + ; + arg1 = &temp1; + } + { + ; + arg5 = &temp5; + } + if (!PyArg_ParseTuple(args,(char *)"OO|O:getMIC",&obj0,&obj1,&obj2)) SWIG_fail; + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_gss_ctx_id_struct, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "getMIC" "', argument " "2"" of type '" "gss_ctx_id_t""'"); + } + arg2 = (gss_ctx_id_t)(argp2); + { + ; + if (obj1 == Py_None) { + /* Allow None as equivalent to "" */ + arg3 = NULL; + //temp3.value = NULL; + //temp3.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj1, + (char **) &temp3.value, + (Py_ssize_t *) &temp3.length); + + if (stat == -1) + return NULL; + //temp3.length++; /* Add null to count*/ + arg3 = &temp3; + } + } + if (obj2) { + ecode4 = SWIG_AsVal_unsigned_SS_int(obj2, &val4); + if (!SWIG_IsOK(ecode4)) { + SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "getMIC" "', argument " "4"" of type '" "gss_qop_t""'"); + } + arg4 = (gss_qop_t)(val4); + } + result = (OM_uint32)reordered_gss_get_mic(arg1,arg2,arg3,arg4,arg5); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + PyObject *o; + ; + o = PyString_FromStringAndSize(arg5->value, arg5->length); + if (!o) + return NULL; + if (PyDict_SetItemString(resultobj, "token", o) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_verifyMIC(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_ctx_id_t arg2 = (gss_ctx_id_t) 0 ; + gss_buffer_t arg3 ; + gss_buffer_t arg4 ; + gss_qop_t *arg5 = (gss_qop_t *) 0 ; + OM_uint32 result; + OM_uint32 temp1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + gss_buffer_desc temp3 ; + gss_buffer_desc temp4 ; + gss_qop_t temp5 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + + { + ; + arg1 = &temp1; + } + { + ; + arg5 = &temp5; + } + if (!PyArg_ParseTuple(args,(char *)"OOO:verifyMIC",&obj0,&obj1,&obj2)) SWIG_fail; + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_gss_ctx_id_struct, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "verifyMIC" "', argument " "2"" of type '" "gss_ctx_id_t""'"); + } + arg2 = (gss_ctx_id_t)(argp2); + { + ; + if (obj1 == Py_None) { + /* Allow None as equivalent to "" */ + arg3 = NULL; + //temp3.value = NULL; + //temp3.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj1, + (char **) &temp3.value, + (Py_ssize_t *) &temp3.length); + + if (stat == -1) + return NULL; + //temp3.length++; /* Add null to count*/ + arg3 = &temp3; + } + } + { + ; + if (obj2 == Py_None) { + /* Allow None as equivalent to "" */ + arg4 = NULL; + //temp4.value = NULL; + //temp4.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj2, + (char **) &temp4.value, + (Py_ssize_t *) &temp4.length); + + if (stat == -1) + return NULL; + //temp4.length++; /* Add null to count*/ + arg4 = &temp4; + } + } + result = (OM_uint32)gss_verify_mic(arg1,arg2,arg3,arg4,arg5); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "qop", PyLong_FromUnsignedLong((unsigned long)*arg5)) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_wrap(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_ctx_id_t arg2 = (gss_ctx_id_t) 0 ; + gss_buffer_t arg3 ; + int arg4 = (int) 1 ; + gss_qop_t arg5 = (gss_qop_t) 0 ; + int *arg6 = (int *) 0 ; + gss_buffer_t arg7 ; + OM_uint32 result; + OM_uint32 temp1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + gss_buffer_desc temp3 ; + int val4 ; + int ecode4 = 0 ; + unsigned int val5 ; + int ecode5 = 0 ; + int temp6 = 0 ; + gss_buffer_desc temp7 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + PyObject * obj3 = 0 ; + + { + ; + arg1 = &temp1; + } + { + ; + arg6 = &temp6; + } + { + ; + arg7 = &temp7; + } + if (!PyArg_ParseTuple(args,(char *)"OO|OO:wrap",&obj0,&obj1,&obj2,&obj3)) SWIG_fail; + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_gss_ctx_id_struct, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "wrap" "', argument " "2"" of type '" "gss_ctx_id_t""'"); + } + arg2 = (gss_ctx_id_t)(argp2); + { + ; + if (obj1 == Py_None) { + /* Allow None as equivalent to "" */ + arg3 = NULL; + //temp3.value = NULL; + //temp3.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj1, + (char **) &temp3.value, + (Py_ssize_t *) &temp3.length); + + if (stat == -1) + return NULL; + //temp3.length++; /* Add null to count*/ + arg3 = &temp3; + } + } + if (obj2) { + ecode4 = SWIG_AsVal_int(obj2, &val4); + if (!SWIG_IsOK(ecode4)) { + SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "wrap" "', argument " "4"" of type '" "int""'"); + } + arg4 = (int)(val4); + } + if (obj3) { + ecode5 = SWIG_AsVal_unsigned_SS_int(obj3, &val5); + if (!SWIG_IsOK(ecode5)) { + SWIG_exception_fail(SWIG_ArgError(ecode5), "in method '" "wrap" "', argument " "5"" of type '" "gss_qop_t""'"); + } + arg5 = (gss_qop_t)(val5); + } + result = (OM_uint32)reordered_gss_wrap(arg1,arg2,arg3,arg4,arg5,arg6,arg7); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "confidential", PyLong_FromUnsignedLong((unsigned long)*arg6)) == -1) + return NULL; + } + { + PyObject *o; + ; + o = PyString_FromStringAndSize(arg7->value, arg7->length); + if (!o) + return NULL; + if (PyDict_SetItemString(resultobj, "msg", o) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +SWIGINTERN PyObject *_wrap_unwrap(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + OM_uint32 *arg1 = (OM_uint32 *) 0 ; + gss_ctx_id_t arg2 = (gss_ctx_id_t) 0 ; + gss_buffer_t arg3 ; + gss_buffer_t arg4 ; + int *arg5 = (int *) 0 ; + gss_qop_t *arg6 = (gss_qop_t *) 0 ; + OM_uint32 result; + OM_uint32 temp1 = 0 ; + void *argp2 = 0 ; + int res2 = 0 ; + gss_buffer_desc temp3 ; + gss_buffer_desc temp4 ; + int temp5 = 0 ; + gss_qop_t temp6 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + + { + ; + arg1 = &temp1; + } + { + ; + arg4 = &temp4; + } + { + ; + arg5 = &temp5; + } + { + ; + arg6 = &temp6; + } + if (!PyArg_ParseTuple(args,(char *)"OO:unwrap",&obj0,&obj1)) SWIG_fail; + res2 = SWIG_ConvertPtr(obj0, &argp2,SWIGTYPE_p_gss_ctx_id_struct, 0 | 0 ); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "unwrap" "', argument " "2"" of type '" "gss_ctx_id_t""'"); + } + arg2 = (gss_ctx_id_t)(argp2); + { + ; + if (obj1 == Py_None) { + /* Allow None as equivalent to "" */ + arg3 = NULL; + //temp3.value = NULL; + //temp3.length = 0; + } + else { + int stat; + stat = PyString_AsStringAndSize(obj1, + (char **) &temp3.value, + (Py_ssize_t *) &temp3.length); + + if (stat == -1) + return NULL; + //temp3.length++; /* Add null to count*/ + arg3 = &temp3; + } + } + result = (OM_uint32)gss_unwrap(arg1,arg2,arg3,arg4,arg5,arg6); + { + /* Returns {"major":result} */ + resultobj = PyDict_New(); + if (!resultobj || + (PyDict_SetItemString(resultobj, "major", PyInt_FromLong(result)) == -1)) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "minor", PyLong_FromUnsignedLong((unsigned long)*arg1)) == -1) + return NULL; + } + { + PyObject *o; + ; + o = PyString_FromStringAndSize(arg4->value, arg4->length); + if (!o) + return NULL; + if (PyDict_SetItemString(resultobj, "msg", o) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "confidential", PyLong_FromUnsignedLong((unsigned long)*arg5)) == -1) + return NULL; + } + { + /* FRED - int *OUTPUT */ + ; + if (PyDict_SetItemString(resultobj, "qop", PyLong_FromUnsignedLong((unsigned long)*arg6)) == -1) + return NULL; + } + return resultobj; +fail: + return NULL; +} + + +static PyMethodDef SwigMethods[] = { + { (char *)"ptr2str", _wrap_ptr2str, METH_VARARGS, NULL}, + { (char *)"importName", _wrap_importName, METH_VARARGS, (char *)"importName(string name, gss_OID name_type=HOSTBASED_SERVICE) -> name"}, + { (char *)"initSecContext", _wrap_initSecContext, METH_VARARGS, (char *)"initSecContext(gss_name_t name, gss_ctx_id_t *context=None, string token=None, gss_cred_id_t cred=None, gss_OID mech=krb5oid, int flags=0, int time=0, gss_channel_bindings_t chan=None) -> context, mech, token, flags, time"}, + { (char *)"acceptSecContext", _wrap_acceptSecContext, METH_VARARGS, (char *)"initSecContext(gss_name_t name, gss_ctx_id_t *context=None, string token=None, gss_cred_id_t cred=None, gss_OID mech=krb5oid, int flags=0, int time=0, gss_channel_bindings_t chan=None) -> context, mech, token, flags, time"}, + { (char *)"getMIC", _wrap_getMIC, METH_VARARGS, (char *)"getMIC(gss_ctx_id_t context, string msg, int qop) -> string checksum"}, + { (char *)"verifyMIC", _wrap_verifyMIC, METH_VARARGS, (char *)"verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop"}, + { (char *)"wrap", _wrap_wrap, METH_VARARGS, (char *)"verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop"}, + { (char *)"unwrap", _wrap_unwrap, METH_VARARGS, (char *)"verifyMIC(gss_ctx_id_t context, string msg, string checksum) -> qop"}, + { NULL, NULL, 0, NULL } +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ + +static swig_type_info _swigt__gss_OID = {"_gss_OID", "gss_OID", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_gss_OID = {"_p_gss_OID", "gss_OID *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_gss_buffer_t = {"_p_gss_buffer_t", "gss_buffer_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_gss_channel_bindings_t = {"_p_gss_channel_bindings_t", "gss_channel_bindings_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_gss_cred_id_struct = {"_p_gss_cred_id_struct", "struct gss_cred_id_struct *|gss_cred_id_t", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_gss_ctx_id_struct = {"_p_gss_ctx_id_struct", "struct gss_ctx_id_struct *|gss_ctx_id_t", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_gss_name_struct = {"_p_gss_name_struct", "struct gss_name_struct *|gss_name_t", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_int = {"_p_int", "int *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_p_gss_cred_id_struct = {"_p_p_gss_cred_id_struct", "struct gss_cred_id_struct **|gss_cred_id_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_p_gss_ctx_id_struct = {"_p_p_gss_ctx_id_struct", "struct gss_ctx_id_struct **|gss_ctx_id_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_p_gss_name_struct = {"_p_p_gss_name_struct", "struct gss_name_struct **|gss_name_t *", 0, 0, (void*)0, 0}; +static swig_type_info _swigt__p_unsigned_int = {"_p_unsigned_int", "OM_uint32 *|unsigned int *|gss_qop_t *", 0, 0, (void*)0, 0}; + +static swig_type_info *swig_type_initial[] = { + &_swigt__gss_OID, + &_swigt__p_char, + &_swigt__p_gss_OID, + &_swigt__p_gss_buffer_t, + &_swigt__p_gss_channel_bindings_t, + &_swigt__p_gss_cred_id_struct, + &_swigt__p_gss_ctx_id_struct, + &_swigt__p_gss_name_struct, + &_swigt__p_int, + &_swigt__p_p_gss_cred_id_struct, + &_swigt__p_p_gss_ctx_id_struct, + &_swigt__p_p_gss_name_struct, + &_swigt__p_unsigned_int, +}; + +static swig_cast_info _swigc__gss_OID[] = { {&_swigt__gss_OID, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_gss_OID[] = { {&_swigt__p_gss_OID, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_gss_buffer_t[] = { {&_swigt__p_gss_buffer_t, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_gss_channel_bindings_t[] = { {&_swigt__p_gss_channel_bindings_t, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_gss_cred_id_struct[] = { {&_swigt__p_gss_cred_id_struct, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_gss_ctx_id_struct[] = { {&_swigt__p_gss_ctx_id_struct, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_gss_name_struct[] = { {&_swigt__p_gss_name_struct, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_int[] = { {&_swigt__p_int, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_p_gss_cred_id_struct[] = { {&_swigt__p_p_gss_cred_id_struct, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_p_gss_ctx_id_struct[] = { {&_swigt__p_p_gss_ctx_id_struct, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_p_gss_name_struct[] = { {&_swigt__p_p_gss_name_struct, 0, 0, 0},{0, 0, 0, 0}}; +static swig_cast_info _swigc__p_unsigned_int[] = { {&_swigt__p_unsigned_int, 0, 0, 0},{0, 0, 0, 0}}; + +static swig_cast_info *swig_cast_initial[] = { + _swigc__gss_OID, + _swigc__p_char, + _swigc__p_gss_OID, + _swigc__p_gss_buffer_t, + _swigc__p_gss_channel_bindings_t, + _swigc__p_gss_cred_id_struct, + _swigc__p_gss_ctx_id_struct, + _swigc__p_gss_name_struct, + _swigc__p_int, + _swigc__p_p_gss_cred_id_struct, + _swigc__p_p_gss_ctx_id_struct, + _swigc__p_p_gss_name_struct, + _swigc__p_unsigned_int, +}; + + +/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ + +static swig_const_info swig_const_table[] = { +{0, 0, 0, 0.0, 0, 0}}; + +#ifdef __cplusplus +} +#endif +/* ----------------------------------------------------------------------------- + * Type initialization: + * This problem is tough by the requirement that no dynamic + * memory is used. Also, since swig_type_info structures store pointers to + * swig_cast_info structures and swig_cast_info structures store pointers back + * to swig_type_info structures, we need some lookup code at initialization. + * The idea is that swig generates all the structures that are needed. + * The runtime then collects these partially filled structures. + * The SWIG_InitializeModule function takes these initial arrays out of + * swig_module, and does all the lookup, filling in the swig_module.types + * array with the correct data and linking the correct swig_cast_info + * structures together. + * + * The generated swig_type_info structures are assigned staticly to an initial + * array. We just loop through that array, and handle each type individually. + * First we lookup if this type has been already loaded, and if so, use the + * loaded structure instead of the generated one. Then we have to fill in the + * cast linked list. The cast data is initially stored in something like a + * two-dimensional array. Each row corresponds to a type (there are the same + * number of rows as there are in the swig_type_initial array). Each entry in + * a column is one of the swig_cast_info structures for that type. + * The cast_initial array is actually an array of arrays, because each row has + * a variable number of columns. So to actually build the cast linked list, + * we find the array of casts associated with the type, and loop through it + * adding the casts to the list. The one last trick we need to do is making + * sure the type pointer in the swig_cast_info struct is correct. + * + * First off, we lookup the cast->type name to see if it is already loaded. + * There are three cases to handle: + * 1) If the cast->type has already been loaded AND the type we are adding + * casting info to has not been loaded (it is in this module), THEN we + * replace the cast->type pointer with the type pointer that has already + * been loaded. + * 2) If BOTH types (the one we are adding casting info to, and the + * cast->type) are loaded, THEN the cast info has already been loaded by + * the previous module so we just ignore it. + * 3) Finally, if cast->type has not already been loaded, then we add that + * swig_cast_info to the linked list (because the cast->type) pointer will + * be correct. + * ----------------------------------------------------------------------------- */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* c-mode */ +#endif +#endif + +#if 0 +#define SWIGRUNTIME_DEBUG +#endif + + +SWIGRUNTIME void +SWIG_InitializeModule(void *clientdata) { + size_t i; + swig_module_info *module_head, *iter; + int found, init; + + clientdata = clientdata; + + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + init = 1; + } else { + init = 0; + } + + /* Try and load any already created modules */ + module_head = SWIG_GetModule(clientdata); + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + module_head = &swig_module; + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + found=0; + iter=module_head; + do { + if (iter==&swig_module) { + found=1; + break; + } + iter=iter->next; + } while (iter!= module_head); + + /* if the is found in the list, then all is done and we may leave */ + if (found) return; + /* otherwise we must add out module into the list */ + swig_module.next = module_head->next; + module_head->next = &swig_module; + } + + /* When multiple interpeters are used, a module could have already been initialized in + a different interpreter, but not yet have a pointer in this interpreter. + In this case, we do not want to continue adding types... everything should be + set up already */ + if (init == 0) return; + + /* Now work on filling in swig_module.types */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: size %d\n", swig_module.size); +#endif + for (i = 0; i < swig_module.size; ++i) { + swig_type_info *type = 0; + swig_type_info *ret; + swig_cast_info *cast; + +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); +#endif + + /* if there is another module already loaded */ + if (swig_module.next != &swig_module) { + type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); + } + if (type) { + /* Overwrite clientdata field */ +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found type %s\n", type->name); +#endif + if (swig_module.type_initial[i]->clientdata) { + type->clientdata = swig_module.type_initial[i]->clientdata; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); +#endif + } + } else { + type = swig_module.type_initial[i]; + } + + /* Insert casting types */ + cast = swig_module.cast_initial[i]; + while (cast->type) { + /* Don't need to add information already in the list */ + ret = 0; +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); +#endif + if (swig_module.next != &swig_module) { + ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); +#ifdef SWIGRUNTIME_DEBUG + if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); +#endif + } + if (ret) { + if (type == swig_module.type_initial[i]) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); +#endif + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } + } + + if (!ret) { +#ifdef SWIGRUNTIME_DEBUG + printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); +#endif + if (type->cast) { + type->cast->prev = cast; + cast->next = type->cast; + } + type->cast = cast; + } + cast++; + } + /* Set entry in modules->types array equal to the type */ + swig_module.types[i] = type; + } + swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif +} + +/* This function will propagate the clientdata field of type to +* any new swig_type_info structures that have been added into the list +* of equivalent types. It is like calling +* SWIG_TypeClientData(type, clientdata) a second time. +*/ +SWIGRUNTIME void +SWIG_PropagateClientData(void) { + size_t i; + swig_cast_info *equiv; + static int init_run = 0; + + if (init_run) return; + init_run = 1; + + for (i = 0; i < swig_module.size; i++) { + if (swig_module.types[i]->clientdata) { + equiv = swig_module.types[i]->cast; + while (equiv) { + if (!equiv->converter) { + if (equiv->type && !equiv->type->clientdata) + SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); + } + equiv = equiv->next; + } + } + } +} + +#ifdef __cplusplus +#if 0 +{ + /* c-mode */ +#endif +} +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + /* Python-specific SWIG API */ +#define SWIG_newvarlink() SWIG_Python_newvarlink() +#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) +#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) + + /* ----------------------------------------------------------------------------- + * global variable support code. + * ----------------------------------------------------------------------------- */ + + typedef struct swig_globalvar { + char *name; /* Name of global variable */ + PyObject *(*get_attr)(void); /* Return the current value */ + int (*set_attr)(PyObject *); /* Set the value */ + struct swig_globalvar *next; + } swig_globalvar; + + typedef struct swig_varlinkobject { + PyObject_HEAD + swig_globalvar *vars; + } swig_varlinkobject; + + SWIGINTERN PyObject * + swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { + return PyString_FromString(""); + } + + SWIGINTERN PyObject * + swig_varlink_str(swig_varlinkobject *v) { + PyObject *str = PyString_FromString("("); + swig_globalvar *var; + for (var = v->vars; var; var=var->next) { + PyString_ConcatAndDel(&str,PyString_FromString(var->name)); + if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); + } + PyString_ConcatAndDel(&str,PyString_FromString(")")); + return str; + } + + SWIGINTERN int + swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { + PyObject *str = swig_varlink_str(v); + fprintf(fp,"Swig global variables "); + fprintf(fp,"%s\n", PyString_AsString(str)); + Py_DECREF(str); + return 0; + } + + SWIGINTERN void + swig_varlink_dealloc(swig_varlinkobject *v) { + swig_globalvar *var = v->vars; + while (var) { + swig_globalvar *n = var->next; + free(var->name); + free(var); + var = n; + } + } + + SWIGINTERN PyObject * + swig_varlink_getattr(swig_varlinkobject *v, char *n) { + PyObject *res = NULL; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->get_attr)(); + break; + } + var = var->next; + } + if (res == NULL && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN int + swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { + int res = 1; + swig_globalvar *var = v->vars; + while (var) { + if (strcmp(var->name,n) == 0) { + res = (*var->set_attr)(p); + break; + } + var = var->next; + } + if (res == 1 && !PyErr_Occurred()) { + PyErr_SetString(PyExc_NameError,"Unknown C global variable"); + } + return res; + } + + SWIGINTERN PyTypeObject* + swig_varlink_type(void) { + static char varlink__doc__[] = "Swig var link object"; + static PyTypeObject varlink_type; + static int type_init = 0; + if (!type_init) { + const PyTypeObject tmp + = { + PyObject_HEAD_INIT(NULL) + 0, /* Number of items in variable part (ob_size) */ + (char *)"swigvarlink", /* Type name (tp_name) */ + sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ + 0, /* Itemsize (tp_itemsize) */ + (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ + (printfunc) swig_varlink_print, /* Print (tp_print) */ + (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ + (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ + 0, /* tp_compare */ + (reprfunc) swig_varlink_repr, /* tp_repr */ + 0, /* tp_as_number */ + 0, /* tp_as_sequence */ + 0, /* tp_as_mapping */ + 0, /* tp_hash */ + 0, /* tp_call */ + (reprfunc)swig_varlink_str, /* tp_str */ + 0, /* tp_getattro */ + 0, /* tp_setattro */ + 0, /* tp_as_buffer */ + 0, /* tp_flags */ + varlink__doc__, /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ +#if PY_VERSION_HEX >= 0x02020000 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ +#endif +#if PY_VERSION_HEX >= 0x02030000 + 0, /* tp_del */ +#endif +#ifdef COUNT_ALLOCS + 0,0,0,0 /* tp_alloc -> tp_next */ +#endif + }; + varlink_type = tmp; + varlink_type.ob_type = &PyType_Type; + type_init = 1; + } + return &varlink_type; + } + + /* Create a variable linking object for use later */ + SWIGINTERN PyObject * + SWIG_Python_newvarlink(void) { + swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); + if (result) { + result->vars = 0; + } + return ((PyObject*) result); + } + + SWIGINTERN void + SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { + swig_varlinkobject *v = (swig_varlinkobject *) p; + swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); + if (gv) { + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + strncpy(gv->name,name,size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } + } + v->vars = gv; + } + + SWIGINTERN PyObject * + SWIG_globals(void) { + static PyObject *_SWIG_globals = 0; + if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); + return _SWIG_globals; + } + + /* ----------------------------------------------------------------------------- + * constants/methods manipulation + * ----------------------------------------------------------------------------- */ + + /* Install Constants */ + SWIGINTERN void + SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { + PyObject *obj = 0; + size_t i; + for (i = 0; constants[i].type; ++i) { + switch(constants[i].type) { + case SWIG_PY_POINTER: + obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); + break; + case SWIG_PY_BINARY: + obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); + break; + default: + obj = 0; + break; + } + if (obj) { + PyDict_SetItemString(d, constants[i].name, obj); + Py_DECREF(obj); + } + } + } + + /* -----------------------------------------------------------------------------*/ + /* Fix SwigMethods to carry the callback ptrs when needed */ + /* -----------------------------------------------------------------------------*/ + + SWIGINTERN void + SWIG_Python_FixMethods(PyMethodDef *methods, + swig_const_info *const_table, + swig_type_info **types, + swig_type_info **types_initial) { + size_t i; + for (i = 0; methods[i].ml_name; ++i) { + const char *c = methods[i].ml_doc; + if (c && (c = strstr(c, "swig_ptr: "))) { + int j; + swig_const_info *ci = 0; + const char *name = c + 10; + for (j = 0; const_table[j].type; ++j) { + if (strncmp(const_table[j].name, name, + strlen(const_table[j].name)) == 0) { + ci = &(const_table[j]); + break; + } + } + if (ci) { + size_t shift = (ci->ptype) - types; + swig_type_info *ty = types_initial[shift]; + size_t ldoc = (c - methods[i].ml_doc); + size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; + char *ndoc = (char*)malloc(ldoc + lptr + 10); + if (ndoc) { + char *buff = ndoc; + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; + if (ptr) { + strncpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + strncpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } + } + } + } + } + } + +#ifdef __cplusplus +} +#endif + +/* -----------------------------------------------------------------------------* + * Partial Init method + * -----------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" +#endif +SWIGEXPORT void SWIG_init(void) { + PyObject *m, *d; + + /* Fix SwigMethods to carry the callback ptrs when needed */ + SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); + + m = Py_InitModule((char *) SWIG_name, SwigMethods); + d = PyModule_GetDict(m); + + SWIG_InitializeModule(0); + SWIG_InstallConstants(d,swig_const_table); + + + PyDict_SetItemString(d,(char*)"cvar", SWIG_globals()); + SWIG_addvarlink(SWIG_globals(),(char*)"HOSTBASED_SERVICE",Swig_var_HOSTBASED_SERVICE_get, Swig_var_HOSTBASED_SERVICE_set); + SWIG_addvarlink(SWIG_globals(),(char*)"krb5oid",Swig_var_krb5oid_get, Swig_var_krb5oid_set); + SWIG_Python_SetConstant(d, "GSS_S_COMPLETE",SWIG_From_int((int)(0x00000000))); + SWIG_Python_SetConstant(d, "GSS_S_CONTINUE_NEEDED",SWIG_From_int((int)(0x00000001))); + SWIG_Python_SetConstant(d, "DELEG_FLAG",SWIG_From_int((int)(1))); + SWIG_Python_SetConstant(d, "MUTUAL_FLAG",SWIG_From_int((int)(2))); + SWIG_Python_SetConstant(d, "REPLAY_FLAG",SWIG_From_int((int)(4))); + SWIG_Python_SetConstant(d, "SEQUENCE_FLAG",SWIG_From_int((int)(8))); + SWIG_Python_SetConstant(d, "CONF_FLAG",SWIG_From_int((int)(16))); + SWIG_Python_SetConstant(d, "INTEG_FLAG",SWIG_From_int((int)(32))); + SWIG_Python_SetConstant(d, "ANON_FLAG",SWIG_From_int((int)(64))); + SWIG_Python_SetConstant(d, "PROT_READY_FLAG",SWIG_From_int((int)(128))); + SWIG_Python_SetConstant(d, "TRANS_FLAG",SWIG_From_int((int)(256))); +} + diff --git a/nfs3/lib/rpc/rpcsec/sec_auth_gss.py b/nfs3/lib/rpc/rpcsec/sec_auth_gss.py new file mode 100644 index 0000000..e7da115 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/sec_auth_gss.py @@ -0,0 +1,379 @@ +from .base import SecFlavor, SecError +from rpc.rpc_const import RPCSEC_GSS +from rpc.rpc_type import opaque_auth +from gss_const import * +import gss_pack +import gss_type +from . import gssapi +import threading + +WINDOWSIZE = 10 # STUB, curently just a completely random number + +#XXX eventually, krb stuff must be separated from gss code +krb5_minor_codes = { + 0 : "KDC_ERR_NONE", + 1 : "KDC_ERR_NAME_EXP", + 2 : "KDC_ERR_SERVICE_EXP", + 3 : "KDC_ERR_BAD_PVNO", + 4 : "KDC_ERR_C_OLD_MAST_KVNO", + 5 : "KDC_ERR_S_OLD_MAST_KVNO", + 6 : "KDC_ERR_C_PRINCIPAL_UNKNOWN", + 7 : "KDC_ERR_S_PRINCIPAL_UNKNOWN", + 8 : "KDC_ERR_PRINCIPAL_NOT_UNIQUE", + 9 : "KDC_ERR_NULL_KEY", + 10 : "KDC_ERR_CANNOT_POSTDATE", + 11 : "KDC_ERR_NEVER_VALID", + 12 : "KDC_ERR_POLICY", + 13 : "KDC_ERR_BADOPTION", + 14 : "KDC_ERR_ETYPE_NOSUPP", + 15 : "KDC_ERR_SUMTYPE_NOSUPP", + 16 : "KDC_ERR_PADATA_TYPE_NOSUPP", + 17 : "KDC_ERR_TRTYPE_NOSUPP", + 18 : "KDC_ERR_CLIENT_REVOKED", + 19 : "KDC_ERR_SERVICE_REVOKED", + 20 : "KDC_ERR_TGT_REVOKED", + 21 : "KDC_ERR_CLIENT_NOTYET", + 22 : "KDC_ERR_SERVICE_NOTYET", + 23 : "KDC_ERR_KEY_EXPIRED", + 24 : "KDC_ERR_PREAUTH_FAILED", + 25 : "KDC_ERR_PREAUTH_REQUIRED", + 26 : "KDC_ERR_SERVER_NOMATCH", + 27 : "KDC_ERR_MUST_USE_USER2USER", + 31 : "KRB_AP_ERR_BAD_INTEGRITY", + 32 : "KRB_AP_ERR_TKT_EXPIRED", + 33 : "KRB_AP_ERR_TKT_NYV", + 34 : "KRB_AP_ERR_REPEAT", + 35 : "KRB_AP_ERR_NOT_US", + 36 : "KRB_AP_ERR_BADMATCH", + 37 : "KRB_AP_ERR_SKEW", + 38 : "KRB_AP_ERR_BADADDR", + 39 : "KRB_AP_ERR_BADVERSION", + 40 : "KRB_AP_ERR_MSG_TYPE", + 41 : "KRB_AP_ERR_MODIFIED", + 42 : "KRB_AP_ERR_BADORDER", + 44 : "KRB_AP_ERR_BADKEYVER", + 45 : "KRB_AP_ERR_NOKEY", + 46 : "KRB_AP_ERR_MUT_FAIL", + 47 : "KRB_AP_ERR_BADDIRECTION", + 48 : "KRB_AP_ERR_METHOD", + 49 : "KRB_AP_ERR_BADSEQ", + 50 : "KRB_AP_ERR_INAPP_CKSUM", + 60 : "KRB_ERR_GENERIC", + 61 : "KRB_ERR_FIELD_TOOLONG", +} + +def show_minor(m): + """Return string corresponding to minor code""" + # XXX krb specific currently + default = "UNKNOWN_MINOR_CODE_%i" % m + return krb5_minor_codes.get(m, default) + +def show_major(m): + """Return string corresponding to major code""" + if m == 0: + return gss_major_codes[0] + call = m & 0xff000000 + routine = m & 0xff0000 + supp = m & 0xffff + out = [] + if call: + out.append(gss_major_codes[call]) + if routine: + out.append(gss_major_codes[routine]) + if supp: + out.append(gss_major_codes[supp]) + return ' | '.join(out) + +def hint_string(d): + """Return a hint regarding how to deal with error, or None""" + hints = {(851968, 13) : "Do you have permission to read the krb5.* files?"} + return hints.get((d["major"], d["minor"]), None) + +class SecAuthGss(SecFlavor): + krb5_oid = "\x2a\x86\x48\x86\xf7\x12\x01\x02\x02" + def __init__(self, service=rpc_gss_svc_none): + t = threading.currentThread() + self.lock = threading.Lock() + self.gss_seq_num = 0 + self.init = 1 + self.service = service + self._packer = {t : gss_pack.GSSPacker()} + self._unpacker = {t : gss_pack.GSSUnpacker('')} + + def getpacker(self): + t = threading.currentThread() + self.lock.acquire() + if t in self._packer: + out = self._packer[t] + else: + out = self._packer[t] = gss_pack.GSSPacker() + self._unpacker[t] = gss_pack.GSSUnpacker('') + self.lock.release() + return out + + def getunpacker(self): + t = threading.currentThread() + self.lock.acquire() + if t in self._unpacker: + out = self._unpacker[t] + else: + self._packer[t] = gss_pack.GSSPacker() + out = self._unpacker[t] = gss_pack.GSSUnpacker('') + self.lock.release() + return out + + def initialize(self, client): # Note this is not thread safe + """Set seq_num, init, handle, and context""" + self.gss_seq_num = 0 + d = gssapi.importName("nfs@%s" % client.remotehost) + if d['major'] != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.importName returned: %s" % \ + show_major(d['major'])) + name = d['name'] + # We need to send NULLPROCs with token from initSecContext + good_major = [gssapi.GSS_S_COMPLETE, gssapi.GSS_S_CONTINUE_NEEDED] + self.init = 1 + reply_token = None + reply_major = '' + context = None + while True: + d = gssapi.initSecContext(name, context, reply_token) + major = d['major'] + context = d['context'] + if major not in good_major: + raise SecError("gssapi.initSecContext returned: %s" % \ + show_major(major)) + if (major == gssapi.GSS_S_CONTINUE_NEEDED) and \ + (reply_major == gssapi.GSS_S_COMPLETE): + raise SecError("Unexpected GSS_S_COMPLETE from server") + token = d['token'] + if reply_major != gssapi.GSS_S_COMPLETE: + # FRED - sec 5.2.2 of RFC 2203 mentions possibility that + # no token is returned. But then how get handle? + p = self.getpacker() + p.reset() + p.pack_opaque(token) + data = p.get_buffer() + reply = client.call(0, data) + up = self.getunpacker() + up.reset(reply) + res = up.unpack_rpc_gss_init_res() + up.done() + reply_major = res.gss_major + if reply_major not in good_major: + raise SecError("Server returned: %s" % \ + show_major(reply_major)) + self.init = 2 + reply_token = res.gss_token + if major == gssapi.GSS_S_COMPLETE: + if reply_major != gssapi.GSS_S_COMPLETE: + raise SecError("Unexpected COMPLETE from client") + break + self.gss_context = context + self.gss_handle = res.handle + self.init = 0 + + def make_cred(self): + """Credential sent with each RPC call""" + if self.init == 1: # first call in context creation + cred = self._make_cred_gss('', rpc_gss_svc_none, RPCSEC_GSS_INIT) + elif self.init > 1: # subsequent calls in context creation + cred = self._make_cred_gss('', rpc_gss_svc_none, + RPCSEC_GSS_CONTINUE_INIT) + else: # data transfer calls + self.lock.acquire() + self.gss_seq_num += 1 # FRED - check for overflow + self.lock.release() + cred = self._make_cred_gss(self.gss_handle, self.service, + seq=self.gss_seq_num) + return opaque_auth(RPCSEC_GSS, cred) + + def read_cred(self, data): + p = self.getunpacker() + p.reset(data) + out = p.unpack_rpc_gss_cred_t() + p.done() + return out.switch + + def handle_proc(self, body, data): + import rpc + if body.gss_proc == RPCSEC_GSS_INIT: + p = self.getunpacker() + p.reset(data) + token = p.unpack_opaque() + p.done() + d = gssapi.acceptSecContext(token, body.handle) + if d["major"] == GSS_S_COMPLETE: + print("SUCCESS!") + class C(object): + pass + out = C() + out.handle = gssapi.ptr2str(d['context']) + out.gss_major = d['major'] + out.gss_minor = d['minor'] + out.seq_window = WINDOWSIZE + out.gss_token = d['token'] + p = self.getpacker() + p.reset() + p.pack_rpc_gss_init_res(out) + out = p.get_buffer() + self.init = 0 + self.gss_context = d['context'] + return rpc.SUCCESS, out + else: + out = hint_string(d) + if out is not None: + print(out) + return rpc.GARBAGE_ARGS, '' + else: + # Stub + print("Unable to handle gss_proc==%i" % body.gss_proc) + return rpc.GARBAGE_ARGS, '' + def make_verf(self, data): + """Verifier sent with each RPC call + + 'data' is packed header upto and including cred + """ + if self.init: + return self._none + else: + d = gssapi.getMIC(self.gss_context, data) + major = d['major'] + if major != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.getMIC returned: %s" % \ + show_major(major)) + return opaque_auth(RPCSEC_GSS, d['token']) + + def _make_cred_gss(self, handle, service, gss_proc=RPCSEC_GSS_DATA, seq=0): + data = gss_type.rpc_gss_cred_vers_1_t(gss_proc, seq, service, handle) + cred = gss_type.rpc_gss_cred_t(RPCSEC_GSS_VERS_1, data) + p = self.getpacker() + p.reset() + p.pack_rpc_gss_cred_t(cred) + return p.get_buffer() + + def secure_data(self, data, cred): + """Add security info/encryption to procedure arg/res""" + gss_cred = self._gss_cred_from_opaque_auth(cred) + if gss_cred.service == rpc_gss_svc_none or \ + gss_cred.gss_proc != RPCSEC_GSS_DATA: + pass + elif gss_cred.service == rpc_gss_svc_integrity: + # data = opaque[gss_seq_num+data] + opaque[checksum] + p = self.getpacker() + p.reset() + p.pack_uint(gss_cred.seq_num) + data = p.get_buffer() + data + d = gssapi.getMIC(self.gss_context, data) + if d['major'] != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.getMIC returned: %s" % \ + show_major(d['major'])) + p.reset() + p.pack_opaque(data) + p.pack_opaque(d['token']) + data = p.get_buffer() + elif gss_cred.service == rpc_gss_svc_privacy: + # data = opaque[wrap([gss_seq_num+data])] + p = self.getpacker() + p.reset() + p.pack_uint(gss_cred.seq_num) + data = p.get_buffer() + data + d = gssapi.wrap(self.gss_context, data) + if d['major'] != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.wrap returned: %s" % \ + show_major(d['major'])) + p.reset() + p.pack_opaque(d['msg']) + data = p.get_buffer() + else: + # Not really necessary, should have already raised XDRError + raise SecError("Unknown service %i for RPCSEC_GSS" % gss_cred.service) + return data + + def unsecure_data(self, data, cred): + """Remove gss cruft from procedure arg/res""" + gss_cred = self._gss_cred_from_opaque_auth(cred) + if gss_cred.service == rpc_gss_svc_none or \ + gss_cred.gss_proc != RPCSEC_GSS_DATA: + pass + elif gss_cred.service == rpc_gss_svc_integrity: + # data = opaque[gss_seq_num+data] + opaque[checksum] + p = self.getunpacker() + p.reset(data) + data = p.unpack_opaque() + checksum = p.unpack_opaque() + p.done() + d = gssapi.verifyMIC(self.gss_context, data, checksum) + if d['major'] != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.verifyMIC returned: %s" % \ + show_major(d['major'])) + p.reset(data) + seqnum = p.unpack_uint() + if seqnum != gss_cred.seq_num: + raise SecError("Mismatched seqnum in reply: got %i, expected %i" % \ + (seqnum, gss_cred.seq_num)) + data = p.get_buffer()[p.get_position():] + elif gss_cred.service == rpc_gss_svc_privacy: + # data = opaque[wrap([gss_seq_num+data])] + p = self.getunpacker() + p.reset(data) + data = p.unpack_opaque() + p.done() + d = gssapi.unwrap(self.gss_context, data) + if d['major'] != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.unwrap returned %s" % \ + show_major(d['major'])) + p.reset(d['msg']) + seqnum = p.unpack_uint() + if seqnum != gss_cred.seq_num: + raise SecError("Mismatched seqnum in reply: got %i, expected %i" % \ + (seqnum, self.gss_cred.seq_num)) + data = p.get_buffer()[p.get_position():] + else: + # Not really necessary, should have already raised XDRError + raise SecError("Unknown service %i for RPCSEC_GSS" % gss_cred.service) + return data + + def _gss_cred_from_opaque_auth(self, auth): + p = self.getunpacker() + data = auth.body + p.reset(data) + cred = p.unpack_rpc_gss_cred_t() + p.done + return cred.switch # return version switch branch + + def make_reply_verf(self, cred, stat): + cred = self._gss_cred_from_opaque_auth(cred) + i = None + if stat: + # Return trivial verf on error + return self._none + elif cred.gss_proc != RPCSEC_GSS_DATA: + # STUB - init requires getMIC(seq_window) + i = WINDOWSIZE + else: + # Else return getMIC(cred.seq_num) + i = cred.seq_num + p = self.getpacker() + p.reset() + p.pack_uint(i) + d = gssapi.getMIC(self.gss_context, p.get_buffer()) + if d['major'] != gssapi.GSS_S_COMPLETE: + raise SecError("gssapi.getMIC returned: %s" % \ + show_major(d['major'])) + return opaque_auth(RPCSEC_GSS, d['token']) + + def check_verf(self, rverf, cred): + """Raise error if there is a problem with reply verifier""" + # STUB + if rverf.flavor == 6 and hasattr(self, 'gss_context'): + cred = self._gss_cred_from_opaque_auth(cred) + p = self.getpacker() + p.reset() + p.pack_uint(cred.seq_num) + d = gssapi.verifyMIC(self.gss_context, p.get_buffer(), rverf.body) + #print "Verify(%i):"%cred.seq_num, show_major(d['major']), show_minor(d['minor']) + + else: + pass + diff --git a/nfs3/lib/rpc/rpcsec/sec_auth_none.py b/nfs3/lib/rpc/rpcsec/sec_auth_none.py new file mode 100644 index 0000000..ec8896a --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/sec_auth_none.py @@ -0,0 +1,4 @@ +from .base import SecFlavor + +class SecAuthNone(SecFlavor): + pass diff --git a/nfs3/lib/rpc/rpcsec/sec_auth_sys.py b/nfs3/lib/rpc/rpcsec/sec_auth_sys.py new file mode 100644 index 0000000..0c8ca13 --- /dev/null +++ b/nfs3/lib/rpc/rpcsec/sec_auth_sys.py @@ -0,0 +1,35 @@ +from .base import SecFlavor, SecError +from rpc.rpc_const import AUTH_SYS +from rpc.rpc_type import opaque_auth +from xdrlib import Packer, Error + +class SecAuthSys(SecFlavor): + # XXX need better defaults + def __init__(self, stamp=0, machinename='', uid=0, gid=0, gids=[]): + if len(machinename) > 255: + raise SecError("machinename %s is too long" % machinename) + if len(gids) > 16: + raise SecError("gid array too long: %s" % str(gids)) + try: + p = Packer() + p.pack_int(stamp) + if isinstance(machinename, str): + machinename = machinename.encode('latin-1') + p.pack_string(machinename) + p.pack_uint(uid) + p.pack_uint(gid) + p.pack_array(gids, p.pack_uint) + self.cred = p.get_buffer() + except Error as e: + raise SecError("Packing error: %s", str(e)) + self.uid = uid + self.gid = gid + + def make_cred(self): + return opaque_auth(AUTH_SYS, self.cred) + + def get_owner(self): + return self.uid + + def get_group(self): + return self.gid diff --git a/nfs3/lib/testmod.py b/nfs3/lib/testmod.py new file mode 100644 index 0000000..2ffe4be --- /dev/null +++ b/nfs3/lib/testmod.py @@ -0,0 +1,638 @@ +# testmod.py - run tests from a suite +# +# Requires python 2.3 +# +# Written by Fred Isaman +# Copyright (C) 2004 University of Michigan, Center for +# Information Technology Integration +# +import nfs3.mountlib +import nfs3.nfs3lib +import re +import sys +import time +import traceback +from traceback import format_exception +from functools import reduce + +if 'sum' not in __builtins__: + def sum(seq, start=0): + return reduce(lambda x, y: x + y, seq, start) + +# Possible outcomes +TEST_NOTRUN = 0 # Not yet considered +TEST_RUNNING = 1 # Test actually running +TEST_WAIT = 2 # Waiting for dependencies to run +TEST_OMIT = 3 # Test skipped +TEST_FAIL = 4 # Test failed +TEST_NOTSUP = 5 # Counts as WARN, but considered a failed dependency +TEST_WARN = 6 # Technically a PASS, but there was a better way +TEST_PASS = 7 # Test passed +TEST_TOOLONG = 8 # Test succeeded, but took too long! +TEST_TOOLONGFAIL = 9 # Test failed AND took too long! +DEP_FUNCT = 100 # Used for depency functions + + +class Result(object): + outcome_names = {TEST_NOTRUN: "NOT RUN", + TEST_RUNNING: "RUNNING", + TEST_WAIT: "WAITING TO RUN", + TEST_OMIT: "OMIT", + TEST_FAIL: "FAILURE", + TEST_NOTSUP: "UNSUPPORTED", + TEST_WARN: "WARNING", + TEST_PASS: "PASS", + TEST_TOOLONG: "TOOLONG", + TEST_TOOLONGFAIL: "TOOLONGFAIL", + DEP_FUNCT: "DEPENDENCY FUNCTION" + } + + def __init__(self, outcome=TEST_NOTRUN, msg="", tb=None, default=False): + self.outcome = outcome + self.msg = str(msg) + self.default = default + if tb is None: + self.tb = [] + else: + # self.tb = ''.join(format_exception(*tb)) + self.tb = format_exception(*tb) + + def __str__(self): + return self.outcome_names[self.outcome] + + def __repr__(self): + return '\n'.join([self.__str__(), self.msg]) + + def __eq__(self, other): + if type(other) == type(0): + return self.outcome == other + else: + return id(self) == id(other) + + def __ne__(self, other): + if type(other) == type(0): + return self.outcome != other + else: + return id(self) != id(other) + + +class TestException(Exception): + pass + + +class UnsupportedException(TestException): + def __init__(self, *args): + self.type = TEST_NOTSUP + TestException.__init__(self, *args) + + +class FailureException(TestException): + def __init__(self, *args): + self.type = TEST_FAIL + TestException.__init__(self, *args) + + +class WarningException(TestException): + def __init__(self, *args): + self.type = TEST_WARN + TestException.__init__(self, *args) + + +class Test(object): + _keywords = ["FLAGS", "DEPEND", "CODE"] + _pass_result = Result(TEST_PASS, default=True) + _run_result = Result(TEST_RUNNING, default=True) + _wait_result = Result(TEST_WAIT, "Circular dependency", default=True) + _omit_result = Result(TEST_OMIT, "Failed runfilter", default=True) + _funct_result = Result(DEP_FUNCT, default=True) + _toolong_result = Result(TEST_TOOLONG, default=True) + _toolongfail_result = Result(TEST_TOOLONGFAIL, default=True) + __re = re.compile(r'(\D*)(\d*)(.*)') + + def __init__(self, function, module=""): + """Needs function to be run""" + self.runtest = function + self.multiconn = False + self.afterrun_list = [] + self.name = function.__name__ + if module: + self.fullname = module.split('.')[-1] + '.' + self.name + else: + self.fullname = self.name + self.doc = function.__doc__.split('\n')[0].strip() + # self.doc = function.__doc__.strip() + self.result = Result() + self._read_docstr(function.__doc__) + + def _read_docstr(self, s): + """Searches s for 'keyword: list' and stores resulting lists""" + for key in self._keywords: + p = re.compile(r'^\s*' + key + ':(.*$)', re.MULTILINE) + match = p.search(str(s)) + if match is None: + setattr(self, key.lower() + '_list', []) + else: + setattr(self, key.lower() + '_list', match.group(1).split()) + + def __getstate__(self): + """Remove function reference when pickling + + This vastly reduce size of the output file, while at the same + time making it more robust to function/class renames. However, + if we need to restore this info for some reason, will need a + __setstate__ function to try and recover it. + """ + d = self.__dict__.copy() + del d["runtest"] + del d["dependencies"] + del d["flags"] + return d + + ## def __cmp__(self, other): + ## if self.code < other.code: + ## return -1 + ## elif self.code == other.code: + ## return 0 + ## else: + ## return 1 + + def __lt__(self, other): + me = self.__re.match(self.code) + me = (me.group(1), int(me.group(2).zfill(1)), me.group(3)) + you = self.__re.match(other.code) + you = (you.group(1), int(you.group(2).zfill(1)), you.group(3)) + return me < you + + def __str__(self): + return "%-8s %s" % (self.code, self.fullname) + + def __repr__(self): + if self.result.msg: + return "%-65s : %s\n%s" % (self, self.result, self._format(self.result.msg)) + else: + return "%-65s : %s" % (self, self.result) + + def display(self, showdoc=False, showtrace=False): + out = "%-65s : %s" % (str(self), str(self.result)) + if showdoc: + out += "\n%s" % self._format(self.doc, 5, 70) + if showtrace and self.result.tb: + out += "\n%s" % ''.join(self.result.tb) + elif self.result.msg: + out += "\n%s" % self._format(self.result.msg, 11, 64) + return out + + def _format(self, s, start_col=11, end_col=64): + s = str(s) + indent = ' ' * (start_col - 1) + out = indent + lout = len(out) + words = s.split() + for w in words: + lw = len(w) + if lout + lw > end_col and lout > start_col: + out += '\n' + indent + lout = start_col - 1 + out += ' ' + w + lout += lw + 1 + return out + + def fail(self, msg): + raise FailureException(msg) + + def fail_support(self, msg): + raise UnsupportedException(msg) + + def pass_warn(self, msg): + raise WarningException(msg) + + def __info(self): + # return sys.exc_info() + exctype, excvalue, tb = sys.exc_info() + if sys.platform[:4] == 'java': ## tracebacks look different in Jython + return (exctype, excvalue, tb) + newtb = tb.tb_next + if newtb is None: + return (exctype, excvalue, tb) + return (exctype, excvalue, newtb) + + def run(self, environment, options): + """Run self.runtest, storing result""" + verbose = getattr(options, 'verbose', False) + timeout = getattr(options, 'timeout', 0) + showtime = getattr(options, 'showtime', True) + + # print "*********Running test %s (%s)" % (self.name, self.code) + self.result = self._run_result + if verbose: + print(repr(self)) + try: + time1 = time.time() + environment.startUp() + self.runtest(self, environment) + self.result = self._pass_result + except KeyboardInterrupt: + raise + except TestException as e: + self.result = Result(e.type, e, sys.exc_info()) + except Exception as e: + self.result = Result(TEST_FAIL, '', sys.exc_info()) + self.result.msg = self.result.tb[-1] + traceback.print_exc() + except Exception as e: + self.result = Result(TEST_FAIL, e, sys.exc_info()) + traceback.print_exc() + try: + environment.shutDown() + except Exception as e: + self.result = Result(TEST_FAIL, '', sys.exc_info()) + self.result.msg = self.result.tb[-1] + traceback.print_exc() + + # Print out test time if 'showtime' is enabled. + time2 = time.time() + testtime = time2 - time1 + if showtime: + print("test took %f seconds!" % (testtime)) + + # Change result to TOOLONG or TOOLONGFAIL if the test ran over the + # "timeout" time. If "timeout" == 0, don't change the result. + if timeout > 0 and testtime > timeout: + print("test took %f seconds, which exceeded the timeout of %d " \ + "seconds!" % (testtime, timeout)) + if self.result == self._pass_result: + self.result = self._toolong_result + else: + self.result = self._toolongfail_result + + if verbose: + print(repr(self) + "\n") + + def runmulticonn(self, env, options): + # print "\nRunning MULTICONN test=%s" % self + + num = 1 + testcode = self.code + + for (connstr, conn) in env.secondconns: + # print "%d: connstr = %s, id = %s" % (num, connstr, conn.id) + + # Set environment's "second connection" + env.secondconn = conn + + # Set test's code name, temporarily + self.code = testcode + str(num) + + # Run test + self.run(env, options) + num = num + 1 + + # OMIT test if no secondconns + if num == 1: + self.result = self._omit_result + + env.secondconn = None + self.code = testcode + + +class Environment(object): + """Base class for a test environment""" + + def __init__(self, opts): + self.opts = opts + + def init(self): + """Run once before any test is run""" + pass + + def finish(self): + """Run once after all tests are run""" + pass + + def startUp(self): + """Run before each test""" + pass + + def shutDown(self): + """Run after each test""" + pass + + +def _run_filter(test, options): + """Returns True if test should be run, False if it should be skipped""" + return True + + +def runtests(tests, options, environment, runfilter=_run_filter): + """tests is an array of test objects, to be run in order + + (as much as possible) + """ + for t in tests: + if t.result == TEST_NOTRUN: + _runtree(t, options, environment, runfilter) + else: + # Test has already been run in a dependency tree + pass + + +def _runtree(t, options, environment, runfilter=_run_filter): + if t.result == TEST_WAIT: + return + t.result = t._wait_result + if not runfilter(t, options): + # Check flags to see if test should be omitted + t.result = t._omit_result + return + if options.rundeps: + runfilter = lambda x, y: True + for dep in t.dependencies: + if dep.result == DEP_FUNCT: + if (not options.force) and (not dep(t, environment)): + t.result = Result(TEST_OMIT, + "Dependency function %s failed" % + dep.__name__) + return + continue + if dep.result == t._omit_result and options.rundeps: + _runtree(dep, options, environment, runfilter) + elif dep.result in [TEST_NOTRUN, TEST_WAIT]: + _runtree(dep, options, environment, runfilter) + # Note dep.result has now changed + if dep.result == TEST_WAIT: + return + elif (not options.force) and \ + (dep.result in [TEST_OMIT, TEST_FAIL, TEST_NOTSUP]): + t.result = Result(TEST_OMIT, + "Dependency %s had status %s." % \ + (dep, dep.result)) + return + + # ISILON: MULTICONN + if t.multiconn: + t.runmulticonn(environment, options) + else: + t.run(environment, options) + + # MULTICONN: Run after-run tests. + for t2 in t.afterrun_list: + _runtree(t2, options, environment) + + +def _import_by_name(name): + mod = __import__(name) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod + + +def get_multiconn_testname(name): + return name + "_MULTICONN" + + +def createtests(testdirs): + """ Tests are functions that start with "test". Their docstring must + contain a line starting with "FLAGS:" and a line starting with "CODE:". + It may optionall contain a line starting with "DEPEND:". Each test must + have a unique code string. The space seperated list of flags must + not contain any code names. The depend list is a list of code names for + tests that must be run before the given test. + """ + # Find all tests in testdir + tests = [] + for testdir in testdirs: + package = _import_by_name(testdir) + for testfile in package.__all__: + if testfile.endswith('.py'): + testfile = testfile[:-3] + testmod = ".".join([testdir, testfile]) + mod = _import_by_name(testmod) + for attr in dir(mod): + if attr.startswith("test"): + f = getattr(mod, attr) + t = Test(f, testmod) + tests.append(t) + # ISILON: Add additional MULTICONN test + if "multiconn" in t.flags_list: + t2 = Test(f, testmod) + t2.multiconn = True + t2.code_list[0] = get_multiconn_testname(t2.code_list[0]) + # Force the _MULTICONN test to run after the original test + t.afterrun_list.append(t2) + tests.append(t2) + + # Reduce doc string info into format easier to work with + used_codes = {} + flag_dict = {} + bit = 1 + for t in tests: + if not t.flags_list: + raise Exception("%s has no flags" % t.fullname) + for f in t.flags_list: + if f not in flag_dict: + flag_dict[f] = bit + bit <<= 1 + if len(t.code_list) != 1: + raise Exception("%s needs exactly one code" % t.fullname) + t.code = t.code_list[0] + if t.code in used_codes: + raise Exception("%s trying to use a code already used" % t.fullname) + used_codes[t.code] = t + del t.code_list + # Check that flags don't contain a code word + for f in flag_dict: + if f in used_codes: + raise Exception("flag %s is also used as a test code" % f) + # Now turn dependency names into pointers, and flags into a bitmask + for t in tests: + t.flags = sum([flag_dict[x] for x in t.flags_list]) + t.dependencies = [] + for d in t.depend_list: + if d in used_codes: + t.dependencies.append(used_codes[d]) + else: + mod = _import_by_name(t.runtest.__module__) + if not hasattr(mod, d): + raise Exception("Could not find reference to dependency %s" % str(d)) + funct = getattr(mod, d) + if not callable(funct): + raise Exception("Dependency %s of %s does not exist" % + (d, t.fullname)) + funct.result = t._funct_result + t.dependencies.append(funct) + return tests, flag_dict, used_codes + + +def printresults(tests, opts, file=None): + failures = 0 + NOTRUN, OMIT, SKIP, FAIL, WARN, PASS, TOOLONG, TOOLONGFAIL = list(range(8)) + count = [0] * 8 + for t in tests: + if not hasattr(t, "result"): + print(dir(t)) + print(t.__dict__) + raise + if t.result == TEST_NOTRUN: + count[NOTRUN] += 1 + elif t.result == TEST_OMIT and t.result.default: + count[OMIT] += 1 + elif t.result in [TEST_WAIT, TEST_OMIT]: + count[SKIP] += 1 + elif t.result == TEST_FAIL: + count[FAIL] += 1 + elif t.result in [TEST_NOTSUP, TEST_WARN]: + count[WARN] += 1 + elif t.result == TEST_PASS: + count[PASS] += 1 + elif t.result == TEST_TOOLONG: + count[TOOLONG] += 1 + elif t.result == TEST_TOOLONGFAIL: + count[TOOLONGFAIL] += 1 + print("*" * 50, file=file) + for t in tests: + if t.result == TEST_NOTRUN: + continue + if t.result == TEST_OMIT and t.result.default: + continue + if (not opts.showomit) and t.result == TEST_OMIT: + continue + if (not opts.showpass) and t.result == TEST_PASS: + continue + if (not opts.showwarn) and t.result in [TEST_NOTSUP, TEST_WARN]: + continue + if (not opts.showfail) and t.result == TEST_FAIL: + continue + print(t.display(0, 0), file=file) + print("*" * 50, file=file) + if count[NOTRUN]: + print("Tests interrupted! Only %i tests run" % \ + sum(count[SKIP:]), file=file) + else: + print("Command line asked for %i of %i tests" % \ + (sum(count[SKIP:]), len(tests)), file=file) + print("Of those: %i Skipped, %i Failed, %i Warned," \ + "%i Passed, %i TooLongPass, %i TooLongFail" % \ + (count[SKIP], count[FAIL], count[WARN], count[PASS], \ + count[TOOLONG], count[TOOLONGFAIL]), file=file) + + # TEMP_FAILURES / TEMP_WARNINGS are the tests that we have yet to fix. + # COMP3 - Unicode. FIXME + # OPDG2/OPDG3 - Open downgrade subset issues. + # OPEN19 - Needs spec clarification. Inconclusive data here: + # http://old.nabble.com/open-share-modes-and-file-permissions-td26340522r0.html + # OPENDEL3 - Share modes FIXME + # OPENUP2_MULTICONN - Share modes FIXME + TEMP_FAILURES = ['COMP3', 'OPDG2', 'OPDG3', 'OPEN19', 'OPENDEL3', + 'EXP5', 'XPT8'] + + # If secondserver is configured SECONDSERV1 should pass and dependent + # tests that are not normally run will run and fail + if (opts.secondserver == None): + TEMP_FAILURES += ['SECONDSERV1'] + else: + TEMP_FAILURES += ['LKU1m_MULTICONN', 'LOCK1m_MULTICONN'] + + # Appending nfsv3 expected failures + TEMP_FAILURES.extend(['MOUNT_MNT_V1', 'MOUNT_DUMP_V1', 'MOUNT_DUMP']) + + TEMP_WARNINGS = ['LOCK8c', 'MKBLK', 'MKCHAR', 'RD12', 'SATT2c', + 'SATT9'] + + # The following failures/warnings are expected to fail/warn because of + # various reasons, as explained below: + + # WRT12, RD11: fail unless sysctl vfs.nfsrv.nfsv4.nfs4_returnoldstateid = 1 + # SATT2c: Returning BAD_STATEID makes sense to me... (ZLK) + # LINK2: fails due to order of errors - works as expected with adjusted input + # LOOKBLK / LOOKCHAR: requires test client to run as root and the export + # must have --maproot=root + # CID1: order of errors - STALECLIENTID defaults to EXPIRED. + # OPEN16: We now trust all reclaims, at least until lk can failover nfs + # locks. + # SEC7: This works on an export with '--security-options=sys:krb5' + # GATTACL: This works with sysctl vfs.nfsrv.nfsv4.acls_return_synthetic=1 + ALLOWED_FAILURES = ['WRT12', 'RD11', 'SATT2c', 'LINK2', 'LOOKBLK', 'LOOKCHAR', + 'CID1', 'OPEN16', 'SEC7', 'GATTACL'] + + # Missing features + FSLOCATIONS_FAILURES = ['FSLOC1', 'FSLOC2', 'FSLOC4a', 'FSLOC4b', 'FSLOC5a', + 'FSLOC6a', 'FSLOC6b', 'FSLOC7a', 'FSLOC8a', 'FSLOC8b'] + BLOCKING_LOCKS_WARNINGS = ['LOCK18', 'LOCK19', 'LOCK21', 'LOCK22'] + DELEGATIONS_WARNINGS = ['DELEG1', 'DELEG11', 'DELEG12', 'DELEG13a', + 'DELEG13b', 'DELEG13c', 'DELEG13d', 'DELEG13e', 'DELEG14', 'DELEG15', + 'DELEG2', 'DELEG3a', 'DELEG3b', 'DELEG3c', 'DELEG3d', 'DELEG3e', 'DELEG4', + 'DELEG5', 'DELEG6', 'DELEG7', 'DELEG8', 'DELEG9'] + + # The following tests have intermittent failures but we are keeping them + # for now because they have caused panics + IGNORE_RESULTS = ['XPT1', 'XPT2', 'XPT3', 'XPT4', 'XPT5', 'XPT6', 'XPT7', + 'XPT8', 'XPT9', 'XPT10'] + + EXPECTED_FAILURES = TEMP_FAILURES + FSLOCATIONS_FAILURES + ALLOWED_FAILURES + EXPECTED_WARNINGS = TEMP_WARNINGS + BLOCKING_LOCKS_WARNINGS + DELEGATIONS_WARNINGS + + print("*" * 50, file=file) + print("Isilon results:", file=file) + for t in tests: + ignore_results = t.code in IGNORE_RESULTS + if t.result == TEST_FAIL or t.result == TEST_TOOLONGFAIL: + if t.code in EXPECTED_FAILURES: + EXPECTED_FAILURES.remove(t.code) + elif t.code in EXPECTED_WARNINGS: + print("Unexpected test FAILURE: %s (expected WARNING)" % t.code, file=file) + if not ignore_results: + failures += 1 + else: + print("Ignoring FAILURE for test %s" % t.code, file=file) + else: + print("Unexpected test FAILURE: %s (expected PASS)" % t.code, file=file) + if not ignore_results: + failures += 1 + else: + print("Ignoring FAILURE for test %s" % t.code, file=file) + elif t.result in [TEST_NOTSUP, TEST_WARN]: + if t.code in EXPECTED_WARNINGS: + EXPECTED_WARNINGS.remove(t.code) + elif t.code in EXPECTED_FAILURES: + print("Unexpected test WARNING: %s (expected FAILURE)" % t.code, file=file) + if not ignore_results: + failures += 1 + else: + print("Ignoring WARNING for test %s" % t.code, file=file) + else: + print("Unexpected test WARNING: %s (expected PASS)" % t.code, file=file) + if not ignore_results: + failures += 1 + else: + print("Ignoring WARNING for test %s" % t.code, file=file) + elif t.result == TEST_PASS: + if t.code in EXPECTED_FAILURES: + print("Unexpected test PASS: %s (expected FAILURE)" % t.code, file=file) + if not ignore_results: + failures += 1 + else: + print("Ignoring PASS for test %s" % t.code, file=file) + elif t.code in EXPECTED_WARNINGS: + print("Unexpected test PASS: %s (expected WARNING)" % t.code, file=file) + if not ignore_results: + failures += 1 + else: + print("Ignoring PASS for test %s" % t.code, file=file) + + if (failures == 0): + print("\nYou have PASSED with flying colors.\n", file=file) + + return failures + +# faillist = [] +# warnlist = [] +# for t in tests: +# if t.result == TEST_FAIL: +# faillist.append(t.code) +# elif t.result in [TEST_NOTSUP, TEST_WARN]: +# warnlist.append(t.code) +# print "Failing tests = ", faillist +# print "(Length = ", len(faillist), ")" +# print "Warning tests = ", warnlist +# print "(Length = ", len(warnlist), ")" diff --git a/nfs3/selfcheck.py b/nfs3/selfcheck.py new file mode 100755 index 0000000..6c6b6e0 --- /dev/null +++ b/nfs3/selfcheck.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# selfcheck.py - smoke test for the vendored nfs3/NSM/NLM tester. +# +# Verifies the self-contained lib/ imports cleanly and that testmod can +# discover the nfs3 test suite, including the specific codes comet drives +# (NSM*, POSIXACL*, CREATE*, MOUNT_*, RDDIR*, WRITE*). Fails loudly if the +# vendored stack (rpc/nfs3/nlm/nsm/testmod) is broken. No test framework. +# +# Run: python3 nfs3/selfcheck.py +import os +import sys + +_here = os.path.dirname(os.path.realpath(__file__)) +sys.path.insert(1, os.path.join(_here, 'lib')) + +import testmod +import nfs3.servertests.environment # noqa: F401 (import must not explode) + +tests, fdict, cdict = testmod.createtests(['nfs3.servertests']) +codes = set(cdict.keys()) + +required = { + "NSM0", "NSM6", + "POSIXACL01", "POSIXACL02", + "CREATE9", "CREATE10", + "MOUNT_NULL", "MOUNT_MNT_V1", "MOUNT_DUMP", "MOUNT_EXPORT", + "RDDIR1", "RDDIRPLS1", + "WRITE1", "WRITEMW1", "WRITEDRC1", +} +missing = sorted(required - codes) +assert not missing, "missing test codes: %s" % missing +assert len(codes) > 40, "suspiciously few test codes discovered: %d" % len(codes) + +print("OK: %d nfs3 test codes discovered, all %d required codes present" + % (len(codes), len(required))) diff --git a/nfs3/showresults.py b/nfs3/showresults.py new file mode 100755 index 0000000..058a35f --- /dev/null +++ b/nfs3/showresults.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# showresults.py - redisplay results from nfsv4 server tester output file +# +# Requires python 2.3 +# +# Written by Fred Isaman +# Copyright (C) 2004 University of Michigan, Center for +# Information Technology Integration +# + + +# Allow to be run straight from the package dir or via a symlink. +import os.path +import sys +_here = os.path.dirname(os.path.realpath(__file__)) +if os.path.isfile(os.path.join(_here, 'lib', 'testmod.py')): + sys.path.insert(1, os.path.join(_here, 'lib')) + +#import cPickle as pickle +import pickle +import testmod +from optparse import OptionParser + +class MyUnpickler(pickle.Unpickler): + class Unknown(object): + def __init__(self, name): + self.name = name + + def find_class(self, module, name): + # Handle function renames gracefully + __import__(module) + mod = sys.modules[module] + try: + klass = getattr(mod, name) + return klass + except: + return self.Unknown(name) + +def show(filename, opt): + fd = open(filename, 'rb') + p = MyUnpickler(fd) + tests = p.load() + testmod.printresults(tests, opt) + +def scan_options(p): + """Parse command line options""" + p.add_option("--showpass", action="store_true", default=True, + help="Show passed tests [default]") + p.add_option("--hidepass", action="store_false", dest="showpass", + help="Hide passed tests") + p.add_option("--showomit", action="store_true", default=False, + help="Show omitted tests") + p.add_option("--hideomit", action="store_false", dest="showomit", + help="Hide omitted tests [default]") + p.add_option("--showwarn", action="store_true", default=True, + help="Show tests that gave warnings [default]") + p.add_option("--hidewarn", action="store_false", dest="showwarn", + help="Hide tests that gave warnings") + p.add_option("--showfail", action="store_true", default=True, + help="Show failed tests [default]") + p.add_option("--hidefail", action="store_false", dest="showfail", + help="Hide failed tests") + return p.parse_args() + +def main(): + p = OptionParser("%prog [options] filename") + opt, args = scan_options(p) + if not args: + p.error("Need a filename") + for a in args: + show(a, opt) + +if __name__ == "__main__": + main() diff --git a/nfs3/testserver.py b/nfs3/testserver.py new file mode 100755 index 0000000..02b4db3 --- /dev/null +++ b/nfs3/testserver.py @@ -0,0 +1,459 @@ +#!/usr/bin/env python3 +# nfs4stest.py - nfsv4 server tester +# +# Requires python 2.3 +# +# Written by Fred Isaman +# Copyright (C) 2004 University of Michigan, Center for +# Information Technology Integration +# +# Based on pynfs +# Written by Peter Astrand +# Copyright (C) 2001 Cendio Systems AB (http://www.cendio.se) +# +# 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; version 2 of the License. +# +# This program is distributed in the hope that it will 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 to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +import sys +if sys.hexversion < 0x02030000: + print("Requires python 2.3 or higher") + sys.exit(1) +import os +import random +# Make our bundled lib/ importable whether run from the source dir or via a +# symlink (e.g. /usr/bin/testserver.py -> .../nfs3/testserver.py). Using +# realpath() resolves the symlink so lib/ is found in the real package dir. +_here = os.path.dirname(os.path.realpath(__file__)) +if os.path.isfile(os.path.join(_here, 'lib', 'testmod.py')): + sys.path.insert(1, os.path.join(_here, 'lib')) + +import re +import testmod +from optparse import OptionParser, OptionGroup, IndentedHelpFormatter +import nfs3.servertests.environment as environment3 +import socket +import rpc +import pickle as pickle + +VERSION="0.2" + +# Auth_sys defaults +HOST = socket.gethostname() +if not hasattr(os, "getuid"): + UID = 0 +else: + UID = os.getuid() +if not hasattr(os, "getgid"): + GID = 0 +else: + GID = os.getgid() + +def parse_url(url): + """Parse [nfs://]host:port/path""" + p = re.compile(r""" + (?:nfs://)? # Ignore an optionally prepended 'nfs://' + (?P[^:]+) # set host=everything up to next : + :? + (?P[^/]*) # set port=everything up to next / + (?P/.*$|$) # set path=everything else + """, re.VERBOSE) + + m = p.match(url) + if m: + return m.group('host'), m.group('port'), m.group('path') + else: + return None, None, None + +def parse_ipv6_url(url): + """Parse """ + p = re.compile(r""" + (?:nfs://)? # Ignore an optionally prepended 'nfs://' + \[? + (?P[^\]/]+) # set host=everything up to next : + (/]:)? + (?P[^/]*) # set port=everything up to next / + (?P/.*$|$) # set path=everything else + """, re.VERBOSE) + m = p.match(url) + if m: + return m.group('host'), m.group('port'), m.group('path') + else: + return None, None, None + + +def unixpath2comps(str, pathcomps=None): + if pathcomps is None or str[0] == '/': + pathcomps = [] + else: + pathcomps = pathcomps[:] + for component in str.split('/'): + if (component == '') or (component == '.'): + pass + elif component == '..': + pathcomps = pathcomps[:-1] + else: + pathcomps.append(component) + return pathcomps + +def scan_options(p): + """Parse command line options + + Sets the following: + .showflags = (False) + .showcodes = (False) + .noinit = (False) + .nocleanup = (False) + .outfile = (None) + .debug_fail = (False) + .secondserver = (None) + .nisserver = (None) + .nfsvers = (4) + .ipv6 = (False) + + .security = (sys) + .uid = (UID) + .gid = (GID) + .machinename = (HOST) + + .force = (False) + .rundeps = (True) + .norundeps + .shuffle = (False) + + .verbose = (False) + .showpass = (True) + .showwarn = (True) + .showfail = (True) + .showomit = (False) + .showtime = (True) + .timeout = (0) + + .maketree = (True) + .nomaketree + .uselink = (None) + .useblock = (None) + .usechar = (None) + .usesocket = (None) + .usefifo = (None) + .usefile = (None) + .usedir = (None) + .usespecial= (None) + + """ + p.add_option("--showflags", action="store_true", default=False, + help="Print a list of all possible flags and exit") + p.add_option("--showcodes", action="store_true", default=False, + help="Print a list of all test codes and exit") + p.add_option("--noinit", action="store_true", default=False, + help="Skip initial cleanup of test directory") + p.add_option("--nocleanup", action="store_true", default=False, + help="Skip final cleanup of test directory") + p.add_option("--outfile", "--out", default="out_last", metavar="FILE", + help="Store test results in FILE [out_last]") + p.add_option("--debug_fail", action="store_true", default=False, + help="Force some checks to fail") + p.add_option("--secondserver", default=None, metavar="SERVER", + help="Use for multi-node tests, to specify SERVER2.") + p.add_option("--nisserver", default=None, + help="NIS server used for netgroup tests.") + p.add_option("--nfsvers", default='3', + help="NFS version to test (only 3 is supported here)") + p.add_option("--nlm", action="store_true", default=False, + help="Support NLM tests (experimental)") + p.add_option("--nsm", action="store_true", default=False, + help="Support NSM tests (experimental)") + p.add_option("--ipv6", action="store_true",default=False, help="Use ipv6") + + g = OptionGroup(p, "Security flavor options", + "These options choose or affect the security flavor used.") + g.add_option("--security", default='sys', + help="Choose security flavor such as krb5i [sys]") + g.add_option("--uid", default=UID, type='int', + help="uid for auth_sys [%i]" % UID) + g.add_option("--gid", default=GID, type='int', + help="gid for auth_sys [%i]" % GID) + g.add_option("--machinename", default=HOST, metavar="HOST", + help="Machine name to use for auth_sys [%s]" % HOST) + p.add_option_group(g) + + g = OptionGroup(p, "Test selection options", + "These options affect how flags are interpreted.") + g.add_option("--force", action="store_true", default=False, + help="Force tests to be run, ignoring dependencies.") + g.add_option("--rundeps", action="store_true", default=True, + help="Force test dependencies to be run, " + "even if not requested on command line") + g.add_option("--norundeps", action="store_false", dest="rundeps", + help="Do NOT Force test dependencies to be run.") + g.add_option("--shuffle", action="store_true", default=False, + help="Shuffle tests so they are run in a random order.") + p.add_option_group(g) + + g = OptionGroup(p, "Test output options", + "These options affect how test results are shown") + g.add_option("-v", "--verbose", action="store_true", default=False, + help="Show tests as they are being run") + g.add_option("--showpass", action="store_true", default=True, + help="Show passed tests [default]") + g.add_option("--hidepass", action="store_false", dest="showpass", + help="Hide passed tests") + g.add_option("--showwarn", action="store_true", default=True, + help="Show tests that gave warnings [default]") + g.add_option("--hidewarn", action="store_false", dest="showwarn", + help="Hide tests that gave warnings") + g.add_option("--showfail", action="store_true", default=True, + help="Show failed tests [default]") + g.add_option("--hidefail", action="store_false", dest="showfail", + help="Hide failed tests") + g.add_option("--showomit", action="store_true", default=False, + help="Show omitted tests") + g.add_option("--hideomit", action="store_false", dest="showomit", + help="Hide omitted tests [default]") + g.add_option("--showtime", action="store_true", default=True, + help="Show time taken for each test [default]") + g.add_option("--hidetime", action="store_false", dest="showtime", + help="Hide time taken for each test") + g.add_option("--timeout", default=0, type='int', + help="How many seconds until tests marked as TOOLONG [0]. " \ + "Note: This does not actually preempt the test.") + p.add_option_group(g) + + g = OptionGroup(p, "Test tree options", + "If the tester cannot create various objects, certain " + "tests will not run. You can indicate pre-existing " + "objects on the server which can be used " + "(they will not altered).") + g.add_option("--maketree", action="store_true", default=True, + help="(Re)create the test tree of object types") + g.add_option("--nomaketree", action="store_false", dest="maketree", + help="Do NOT (Re)create the test tree of object types") + g.add_option("--uselink", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as symlink") + g.add_option("--useblock", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as block device") + g.add_option("--usechar", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as char device") + g.add_option("--usesocket", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as socket") + g.add_option("--usefifo", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as fifo") + g.add_option("--usefile", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as regular file") + g.add_option("--usedir", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as directory") + g.add_option("--usespecial", default=None, metavar="OBJPATH", + help="Use SERVER:/OBJPATH as obj for certain specialized tests") + g.add_option("--usefh", default=None, metavar="FH", + help="Use FH for certain specialized tests") + p.add_option_group(g) + + g = OptionGroup(p, "Server workaround options", + "Certain servers handle certain things in unexpected ways." + " These options allow you to alter test behavior so that " + "they will run.") + g.add_option("--paddednull", action="store_true", default=False, + help="Allow NULL returns to have extra data appended [False]") + g.add_option("--newverf", action="store_true", default=False, + help="Force use of new verifier for SETCLIENTID [False]") + g.add_option("--secure", action="store_true", default=False, + help="Try to use 'secure' port number <1024 for client [False]") + g.add_option("--nonrandomxid", action="store_true", default=False, + help="Use non random XIDs (start XID at 0).") + p.add_option_group(g) + return p.parse_args() + +class Argtype(object): + """Args that are not options are either flags or testcodes""" + def __init__(self, obj, run=True, flag=True): + self.isflag = flag # True if flag, False if a test + self.run = run # True for inclusion, False for exclusion + self.obj = obj # The flag or test itself + + def __str__(self): + return "Isflag=%i, run=%i" % (self.isflag, self.run) + +def run_filter(test, options): + """Determine whether a test was directly asked for by the command line.""" + run = False # default + for arg in options.args: + if arg.isflag: + if test.flags & arg.obj: + run = arg.run + else: + if test == arg.obj: + run = arg.run + return run + +def printflags(list): + """Print all legal flag names, which are given in list""" + for s in sorted(list): + print(s) + +def main(): + p = OptionParser("%prog SERVER:/PATH [options] flags|testcodes\n" + " %prog --help\n" + " %prog SHOWOPTION", + version="%prog "+VERSION, + formatter=IndentedHelpFormatter(2, 25) + ) + opt, args = scan_options(p) + failures = 0 + + # This is the nfs3/NSM/NLM tester; only NFS version 3 is supported here. + # (NFSv4 lives in the sibling nfs4.1/ tree.) + if opt.nfsvers != '3': + p.error("Unsupported NFS version: %s (this tester only supports 3)" % + opt.nfsvers) + + # Create test database and select environment-specific options + testdirs = list() + testdirs.append('nfs3.servertests') + environment3.debug_fail = opt.debug_fail + + tests, fdict, cdict = testmod.createtests(testdirs) + + # Deal with any informational options + if opt.showflags: + printflags(list(fdict.keys())) + sys.exit(0) + + if opt.showcodes: + codes = list(cdict.keys()) + codes.sort() + for c in codes: + print(c) + sys.exit(0) + + # Grab server info and set defaults + if not args: + p.error("Need a server") + url = args.pop(0) + if opt.ipv6: + opt.server, opt.port, opt.path = parse_ipv6_url(url) + else: + opt.server, opt.port, opt.path = parse_url(url) + if not opt.server: + p.error("%s not a valid server name" % url) + if not opt.port: + opt.port = 2049 + else: + opt.port = int(opt.port) + if not opt.path: + opt.path = [] + else: + opt.path = unixpath2comps(opt.path) + + # Check --use* options are valid + for attr in dir(opt): + if attr.startswith('use') and attr != "usefh": + path = getattr(opt, attr) + #print attr, path + if path is None: + path = opt.path + ['tree', attr[3:]] + else: + # FIXME - have funct that checks path validity + if path[0] != '/': + p.error("Need to use absolute path for --%s" % attr) + # print path + if path[-1] == '/' and attr != 'usedir': + p.error("Can't use dir for --%s" %attr) + try: + path = unixpath2comps(path) + except Exception as e: + p.error(e) + setattr(opt, attr, [comp for comp in path if comp]) + + # Check that --security option is valid + # sets --flavor to a rpc.SecAuth* class, and sets flags for its options + valid = rpc.supported.copy() + # FIXME - STUB - the only gss mech available is krb5 + if 'gss' in valid: + valid['krb5'] = valid['krb5i'] = valid['krb5p'] = valid['gss'] + del valid['gss'] + if opt.security not in valid: + p.error("Unknown security: %s\nValid flavors are %s" % + (opt.security, str(list(valid.keys())))) + opt.flavor = valid[opt.security] + opt.service = {'krb5':1, 'krb5i':2, 'krb5p':3}.get(opt.security, 0) + opt.path += ['tmp' + opt.nfsvers]; + + # Make sure args are valid + opt.args = [] + for a in args: + if a.lower().startswith('no'): + include = False + a = a[2:] + else: + include = True + if a in fdict: + opt.args.append(Argtype(fdict[a], include)) + elif a in cdict: + opt.args.append(Argtype(cdict[a], include, flag=False)) + else: + p.error("Unknown code or flag: %s" % a) + + # Place tests in desired order + if not opt.shuffle: + tests.sort() + else: + random.shuffle(tests) + + # Run the tests and save/print results + try: + env = environment3.Environment(opt) + + env.init() + + except socket.gaierror as e: + if e.args[0] == -2: + print("Unknown server '%s'" % opt.server) + elif opt.secondserver == None: + print("Error connecting to server '%s'" % opt.server) + else: + print(("Error connecting to server '%s' or secondserver '%s'" % + opt.server, opt.secondserver)) + sys.exit(1) + + except Exception as e: + print("Initialization failed, no tests run.") + if not opt.maketree: + print("Perhaps you need to use the --maketree option") + print(sys.exc_info()[1]) + sys.exit(1) + + if opt.outfile is not None: + fd = open(opt.outfile, 'wb') + try: + clean_finish = False + testmod.runtests(tests, opt, env, run_filter) + clean_finish = True + finally: + if opt.outfile is not None: + pickle.dump(tests, fd, 0) + if not clean_finish: + testmod.printresults(tests, opt) + try: + fail = False + env.finish() + except Exception as e: + fail = True + failures = testmod.printresults(tests, opt) + if fail: + print("\nWARNING: could not clean testdir due to:\n%s\n" % str(e)) + + return failures + +if __name__ == "__main__": + failures = main() + sys.exit(failures)