def O_Create(self, ncl, op): print "SERVER CREATE" print " CURRENT FILEHANDLE: %s" % self.curr_fh.ref old_cinfo = self.curr_fh.change if op.opcreate.objtype.type == NF4DIR: newfh = self.curr_fh.create_dir(op.opcreate.objname) else: newfh = self.curr_fh new_cinfo = self.curr_fh.change self.curr_fh = newfh attrs = nfs4lib.list2attrmask([]) cin4 = change_info4(ncl, before=old_cinfo, after=new_cinfo, atomic=1) c4resok = CREATE4resok(ncl, cinfo=cin4, attrset = attrs) c4res = CREATE4res(ncl, NFS4_OK, c4resok) argop = nfs_resop4(ncl, resop=OP_CREATE, opcreate=c4res) return (NFS4_OK, argop)
def O_Create(self, ncl, op): print "SERVER CREATE" print " CURRENT FILEHANDLE: %s" % self.curr_fh.ref old_cinfo = self.curr_fh.change if op.opcreate.objtype.type == NF4DIR: newfh = self.curr_fh.create_dir(op.opcreate.objname) else: newfh = self.curr_fh new_cinfo = self.curr_fh.change self.curr_fh = newfh attrs = nfs4lib.list2attrmask([]) cin4 = change_info4(ncl, before=old_cinfo, after=new_cinfo, atomic=1) c4resok = CREATE4resok(ncl, cinfo=cin4, attrset=attrs) c4res = CREATE4res(ncl, NFS4_OK, c4resok) argop = nfs_resop4(ncl, resop=OP_CREATE, opcreate=c4res) return (NFS4_OK, argop)
def do_getfacl(self, line): """Get regular attributes""" argv = line.split() object = argv[0] attributes = argv[1:] attrlist = [ 12 ] pathcomps = self.ncl.get_pathcomps_rel(object) lookupops = self.ncl.lookup_path(pathcomps) operations = [self.ncl.putrootfh_op()] + lookupops operations.append(self.ncl.getattr_op(nfs4lib.list2attrmask(attrlist))) try: res = self.ncl.compound(operations) except nfs4lib.BadCompoundRes, result: print "getattr failed: ", result return
def do_getattr(self, line): """Get regular attributes""" argv = line.split() object = argv[0] attributes = argv[1:] attrlist = [] dict = nfs4lib.get_attrbitnum_dict() for attr in attributes: if attr.isdigit() == 1: attrlist.append(attr.atoi()) elif dict.has_key(attr): attrlist.append(dict[attr]) pathcomps = self.ncl.get_pathcomps_rel(object) lookupops = self.ncl.lookup_path(pathcomps) operations = [self.ncl.putrootfh_op()] + lookupops operations.append( self.ncl.getattr_op(nfs4lib.list2attrmask(attrlist))) try: res = self.ncl.compound(operations) except nfs4lib.BadCompoundRes, result: print "getattr failed: ", result return
def O_SetAttr(self, ncl, op): attrsset = nfs4lib.list2attrmask([]) sa4res = SETATTR4res(ncl, NFS4_OK, attrsset) argop = nfs_resop4(ncl, resop=OP_SETATTR, opsetattr=sa4res) return (NFS4_OK, argop)
def main(ncl, unix_prefix): ncl.init_connection() prefix = nfs4lib.unixpath2comps(unix_prefix) putrootfhop = ncl.putrootfh_op() lookup_treeroot = [putrootfhop] + ncl.lookup_path(prefix) lookup_dev = lookup_treeroot + ncl.lookup_path(["dev"]) lookup_doc = lookup_treeroot + ncl.lookup_path(["doc"]) lookup_src = lookup_treeroot + ncl.lookup_path(["src"]) lookup_tmp = lookup_treeroot + ncl.lookup_path(["tmp"]) lookup_private = lookup_treeroot + ncl.lookup_path(["private"]) print "Creating path", unix_prefix create_leading_paths(ncl, prefix) print "Clearing", unix_prefix clean_dir(prefix) print "Creating /dev" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "dev") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/floppy" operations = lookup_dev[:] objtype = createtype4(ncl, type=NF4LNK, linkdata="fd0") createop = ncl.create(objtype, "floppy") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/fd0" operations = lookup_dev[:] devdata = specdata4(ncl, 2, 0) objtype = createtype4(ncl, type=NF4BLK, devdata=devdata) createop = ncl.create(objtype, "fd0") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/ttyS0" operations = lookup_dev[:] devdata = specdata4(ncl, 4, 64) objtype = createtype4(ncl, type=NF4CHR, devdata=devdata) createop = ncl.create(objtype, "ttyS0") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/log" operations = lookup_dev[:] objtype = createtype4(ncl, type=NF4SOCK) createop = ncl.create(objtype, "log") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/initctl" operations = lookup_dev[:] objtype = createtype4(ncl, type=NF4FIFO) createop = ncl.create(objtype, "initctl") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /doc" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "doc") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /doc/README" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "doc/README"), "w") data = """\ Welcome to this NFS4 server. Enjoy. """ remote.write(data) remote.close() print "Creating directory doc/porting" operations = lookup_doc[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "porting") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating doc/porting/TODO" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "doc/porting/TODO"), "w") data = """\ Need to work on DNIX support... Enjoy. """ remote.write(data) remote.close() print "Creating src" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "src") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating src/hello.c" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "src/hello.c"), "w") data = """\ #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!\\n"); exit(0); } """ remote.write(data) remote.close() print "Creating tmp" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "tmp") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating tmp/gazonk" operations = lookup_tmp[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "gazonk") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating tmp/gazonk/foo.c" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "tmp/gazonk/foo.c"), "w") data = """\ #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!\\n"); exit(0); } """ remote.write(data) remote.close() print "Creating directory private" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "private") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating private/info.txt" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "private/info.txt"), "w") remote.write("Personal data.\n") remote.close() print "Changing UNIX permissions of private dir to 0000" operations = lookup_private[:] stateid = stateid4(ncl, 0, "") attrmask = nfs4lib.list2attrmask([FATTR4_MODE]) dummy_ncl = nfs4lib.DummyNcl() dummy_ncl.packer.pack_uint(0000) attr_vals = dummy_ncl.packer.get_buffer() obj_attributes = fattr4(ncl, attrmask, attr_vals) operations.append(ncl.setattr_op(stateid, obj_attributes)) res = ncl.compound(operations) if res.status == NFS4ERR_ATTRNOTSUPP: print "UNIX mode attribute not supported" else: nfs4lib.check_result(res) print "Creating symlink src/doc -> ../doc" operations = lookup_src[:] objtype = createtype4(ncl, type=NF4LNK, linkdata="../doc") createop = ncl.create(objtype, "doc") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res)
operations = [putrootfhop] + lookupops getfhop = self.ncl.getfh_op() operations.append(getfhop) res = self.ncl.compound(operations) try: nfs4lib.check_result(res) except nfs4lib.BadCompoundRes, r: print "Cannot list directory:", r return getfhresult = res.resarray[-1].arm fh = getfhresult.arm.object attr_request = nfs4lib.list2attrmask([FATTR4_TYPE, FATTR4_SIZE, FATTR4_TIME_MODIFY]) entries = self.ncl.do_readdir(fh, attr_request) for entry in entries: attrdict = nfs4lib.fattr2dict(entry.attrs) # Name name = entry.name # Size if attrdict.has_key("size"): size = str(attrdict["size"]) else: size = "?" # File type if attrdict.has_key("type"): ftype = nfs_ftype4_id[attrdict["type"]]
def main(ncl, unix_prefix): ncl.init_connection() prefix = nfs4lib.unixpath2comps(unix_prefix) putrootfhop = ncl.putrootfh_op() lookup_treeroot = [putrootfhop] + ncl.lookup_path(prefix) lookup_dev = lookup_treeroot + ncl.lookup_path(["dev"]) lookup_doc = lookup_treeroot + ncl.lookup_path(["doc"]) lookup_src = lookup_treeroot + ncl.lookup_path(["src"]) lookup_tmp = lookup_treeroot + ncl.lookup_path(["tmp"]) lookup_private = lookup_treeroot + ncl.lookup_path(["private"]) print "Creating path", unix_prefix create_leading_paths(ncl, prefix) print "Clearing", unix_prefix clean_dir(prefix) print "Creating /dev" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "dev") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/floppy" operations = lookup_dev[:] objtype = createtype4(ncl, type=NF4LNK, linkdata="fd0") createop = ncl.create(objtype, "floppy") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/fd0" operations = lookup_dev[:] devdata = specdata4(ncl, 2, 0) objtype = createtype4(ncl, type=NF4BLK, devdata=devdata) createop = ncl.create(objtype, "fd0") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/ttyS0" operations = lookup_dev[:] devdata = specdata4(ncl, 4, 64) objtype = createtype4(ncl, type=NF4CHR, devdata=devdata) createop = ncl.create(objtype, "ttyS0") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/log" operations = lookup_dev[:] objtype = createtype4(ncl, type=NF4SOCK) createop = ncl.create(objtype, "log") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /dev/initctl" operations = lookup_dev[:] objtype = createtype4(ncl, type=NF4FIFO) createop = ncl.create(objtype, "initctl") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /doc" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "doc") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating /doc/README" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "doc/README"), "w") data ="""\ Welcome to this NFS4 server. Enjoy. """ remote.write(data) remote.close() print "Creating directory doc/porting" operations = lookup_doc[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "porting") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating doc/porting/TODO" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "doc/porting/TODO"), "w") data ="""\ Need to work on DNIX support... Enjoy. """ remote.write(data) remote.close() print "Creating src" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "src") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating src/hello.c" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "src/hello.c"), "w") data = """\ #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!\\n"); exit(0); } """ remote.write(data) remote.close() print "Creating tmp" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "tmp") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating tmp/gazonk" operations = lookup_tmp[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "gazonk") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating tmp/gazonk/foo.c" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "tmp/gazonk/foo.c"), "w") data = """\ #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!\\n"); exit(0); } """ remote.write(data) remote.close() print "Creating directory private" operations = lookup_treeroot[:] objtype = createtype4(ncl, type=NF4DIR) createop = ncl.create(objtype, "private") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res) print "Creating private/info.txt" remote = nfs4lib.NFS4OpenFile(ncl) remote.open(os.path.join(unix_prefix, "private/info.txt"), "w") remote.write("Personal data.\n") remote.close() print "Changing UNIX permissions of private dir to 0000" operations = lookup_private[:] stateid = stateid4(ncl, 0, "") attrmask = nfs4lib.list2attrmask([FATTR4_MODE]) dummy_ncl = nfs4lib.DummyNcl() dummy_ncl.packer.pack_uint(0000) attr_vals = dummy_ncl.packer.get_buffer() obj_attributes = fattr4(ncl, attrmask, attr_vals) operations.append(ncl.setattr_op(stateid, obj_attributes)) res = ncl.compound(operations) if res.status == NFS4ERR_ATTRNOTSUPP: print "UNIX mode attribute not supported" else: nfs4lib.check_result(res) print "Creating symlink src/doc -> ../doc" operations = lookup_src[:] objtype = createtype4(ncl, type=NF4LNK, linkdata="../doc") createop = ncl.create(objtype, "doc") operations.append(createop) res = ncl.compound(operations) nfs4lib.check_result(res)