From 663ed78329141b2fdf87946f17fc6e28290cdc28 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 19 Jul 2013 18:11:19 -0400 Subject: [PATCH 1/7] _pts: Remove unreachable return statements Fixes warning: afs/_pts.pyx:115:8: Unreachable code warning: afs/_pts.pyx:130:8: Unreachable code Signed-off-by: Anders Kaseorg --- afs/_pts.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/afs/_pts.pyx b/afs/_pts.pyx index 3c10b70..0dd65ef 100644 --- a/afs/_pts.pyx +++ b/afs/_pts.pyx @@ -112,7 +112,6 @@ cdef class PTEntry: cdef int _ptentry_from_c(PTEntry p_entry, prcheckentry * c_entry) except -1: if p_entry is None: raise TypeError - return -1 p_entry.flags = c_entry.flags p_entry.id = c_entry.id @@ -127,7 +126,6 @@ cdef int _ptentry_from_c(PTEntry p_entry, prcheckentry * c_entry) except -1: cdef int _ptentry_to_c(prcheckentry * c_entry, PTEntry p_entry) except -1: if p_entry is None: raise TypeError - return -1 c_entry.flags = p_entry.flags c_entry.id = p_entry.id From 7eedff965777f3d5c8f8ea4fb50148c89a6bf238 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 19 Jul 2013 18:15:40 -0400 Subject: [PATCH 2/7] _util: Remove extern from definitions that are not extern Fixes warning: afs/_util.pyx:15:5: Function 'pioctl_read' previously declared as 'private' warning: afs/_util.pyx:29:5: Function 'pioctl_write' previously declared as 'private' Signed-off-by: Anders Kaseorg --- afs/_util.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afs/_util.pyx b/afs/_util.pyx index 932bdf0..af5e698 100644 --- a/afs/_util.pyx +++ b/afs/_util.pyx @@ -12,7 +12,7 @@ cdef int _init = 0 # pioctl convenience wrappers -cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned short size, afs_int32 follow) except -1: +cdef int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned short size, afs_int32 follow) except -1: cdef ViceIoctl blob cdef afs_int32 code blob.in_size = 0 @@ -26,7 +26,7 @@ cdef extern int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned shor pyafs_error(code) return code -cdef extern int pioctl_write(char *dir, afs_int32 op, char *buffer, afs_int32 follow) except -1: +cdef int pioctl_write(char *dir, afs_int32 op, char *buffer, afs_int32 follow) except -1: cdef ViceIoctl blob cdef afs_int32 code blob.cin = buffer From b083d4e98e65008dbc2a17b506b07785c8253ff4 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 19 Jul 2013 18:30:39 -0400 Subject: [PATCH 3/7] PTS.__cinit__: Prevent use of uninitialized security object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, PTS.__cinit__ would leave sc uninitialized when passed an invalid negative sec argument. Fixes afs/_pts.c: In function ‘__pyx_pf_3afs_4_pts_3PTS___cinit__’: afs/_pts.c:2999:56: warning: ‘__pyx_v_sc’ may be used uninitialized in this function [-Wmaybe-uninitialized] (__pyx_v_serverconns[__pyx_v_i]) = rx_NewConnection((__pyx_v_info.hostAddr[__pyx_v_i]).sin_addr.s_addr, (__pyx_v_info.hostAddr[__pyx_v_i]).sin_port, PRSRV, __pyx_v_sc, __pyx_t_9); ^ Signed-off-by: Anders Kaseorg --- afs/_pts.pyx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/afs/_pts.pyx b/afs/_pts.pyx index 0dd65ef..b211b56 100644 --- a/afs/_pts.pyx +++ b/afs/_pts.pyx @@ -225,7 +225,9 @@ cdef class PTS: self.cell = info.name - if sec > 0: + if sec == 0: + sc = rxnull_NewClientSecurityObject() + else: strncpy(prin.cell, info.name, sizeof(prin.cell)) prin.instance[0] = 0 strncpy(prin.name, "afs", sizeof(prin.name)) @@ -235,6 +237,7 @@ cdef class PTS: if sec >= 2: # No really - we wanted authentication pyafs_error(code) + sc = rxnull_NewClientSecurityObject() sec = 0 else: if sec == 3: @@ -244,11 +247,7 @@ cdef class PTS: sc = rxkad_NewClientSecurityObject(level, &token.sessionKey, token.kvno, token.ticketLen, token.ticket) - - if sec == 0: - sc = rxnull_NewClientSecurityObject() - else: - sec = 2 + sec = 2 memset(serverconns, 0, sizeof(serverconns)) for 0 <= i < info.numServers: From 5f7ad208187d031650a0428d622333eaef5debc7 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 13 Dec 2019 01:29:12 -0500 Subject: [PATCH 4/7] Use Python 3-compatible exceptions --- afs/acl.py | 2 +- afs/fs.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/afs/acl.py b/afs/acl.py index 20a416f..1729442 100644 --- a/afs/acl.py +++ b/afs/acl.py @@ -119,7 +119,7 @@ def _clean(self): def set(self, user, bitmask, negative=False): """Set the bitmask for a given user""" if bitmask < 0 or bitmask > max(_char2bit.values()): - raise ValueError, "Invalid bitmask" + raise ValueError("Invalid bitmask") if negative: self.neg[user] = bitmask else: diff --git a/afs/fs.py b/afs/fs.py index 02c2756..870964d 100644 --- a/afs/fs.py +++ b/afs/fs.py @@ -6,7 +6,7 @@ def inafs(path): """Return True if a path is in AFS.""" try: whichcell(path) - except OSError, e: + except OSError as e: if e.errno in (errno.EINVAL, errno.ENOENT): return False From f866fe2bed8cc14ed44ccacf590877cb362699cb Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 13 Dec 2019 12:19:50 -0500 Subject: [PATCH 5/7] Link against new AFS libraries --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4c5c317..17b3ba0 100755 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ suffix = '_pic' else: suffix = '' -libraries = ['afsauthent%s' % suffix, 'afsrpc%s' % suffix, 'resolv'] +libraries = ['afsauthent%s' % suffix, 'afsrpc%s' % suffix, 'rokenafs', 'afshcrypto', 'resolv'] define_macros = [('AFS_PTHREAD_ENV', None)] def PyAFSExtension(module, *args, **kwargs): From e4425007c76bba38f5713bad6d66b008b5416614 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 13 Dec 2019 12:20:25 -0500 Subject: [PATCH 6/7] Python 3-compatible string and path handling --- afs/_acl.pyx | 15 ++++++++------- afs/_fs.pyx | 7 ++++--- afs/_pts.pyx | 1 + afs/_util.pyx | 8 +++++++- afs/acl.py | 2 +- afs/pts.py | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/afs/_acl.pyx b/afs/_acl.pyx index bf1b1f9..8fe9b55 100644 --- a/afs/_acl.pyx +++ b/afs/_acl.pyx @@ -1,5 +1,6 @@ +# cython: c_string_type=str, c_string_encoding=ascii from afs._util cimport * -from afs._util import pyafs_error +from afs._util import path_to_bytes cdef extern from "afs/prs_fs.h": enum: @@ -34,15 +35,15 @@ USR7 = PRSFS_USR7 DEF MAXSIZE = 2048 -def getAcl(char* dir, int follow=1): +def getAcl(dir, int follow=1): cdef char space[MAXSIZE] - pioctl_read(dir, VIOCGETAL, space, MAXSIZE, follow) + pioctl_read(path_to_bytes(dir), VIOCGETAL, space, MAXSIZE, follow) return space -def getCallerAccess(char *dir, int follow=1): +def getCallerAccess(dir, int follow=1): cdef vcxstat2 stat - pioctl_read(dir, VIOC_GETVCXSTATUS2, &stat, sizeof(vcxstat2), follow) + pioctl_read(path_to_bytes(dir), VIOC_GETVCXSTATUS2, &stat, sizeof(vcxstat2), follow) return stat.callerAccess -def setAcl(char* dir, char* acl, int follow=1): - pioctl_write(dir, VIOCSETAL, acl, follow) +def setAcl(dir, char* acl, int follow=1): + pioctl_write(path_to_bytes(dir), VIOCSETAL, acl, follow) diff --git a/afs/_fs.pyx b/afs/_fs.pyx index 57ac603..c1df053 100644 --- a/afs/_fs.pyx +++ b/afs/_fs.pyx @@ -1,9 +1,10 @@ +# cython: c_string_type=str, c_string_encoding=ascii from afs._util cimport * -from afs._util import pyafs_error +from afs._util import path_to_bytes -def whichcell(char* path): +def whichcell(path): """Determine which AFS cell a particular path is in.""" cdef char cell[MAXCELLCHARS] - pioctl_read(path, VIOC_FILE_CELL_NAME, cell, sizeof(cell), 1) + pioctl_read(path_to_bytes(path), VIOC_FILE_CELL_NAME, cell, sizeof(cell), 1) return cell diff --git a/afs/_pts.pyx b/afs/_pts.pyx index b211b56..6494173 100644 --- a/afs/_pts.pyx +++ b/afs/_pts.pyx @@ -1,3 +1,4 @@ +# cython: c_string_type=str, c_string_encoding=ascii from afs._util cimport * from afs._util import pyafs_error import re diff --git a/afs/_util.pyx b/afs/_util.pyx index af5e698..f3b9a2b 100644 --- a/afs/_util.pyx +++ b/afs/_util.pyx @@ -1,7 +1,7 @@ """ General PyAFS utilities, such as error handling """ - +# cython: c_string_type=str, c_string_encoding=ascii import sys # otherwise certain headers are unhappy @@ -18,6 +18,7 @@ cdef int pioctl_read(char *dir, afs_int32 op, void *buffer, unsigned short size, blob.in_size = 0 blob.out_size = size blob.out = buffer + code = pioctl(dir, op, &blob, follow) # This might work with the rest of OpenAFS, but I'm not convinced # the rest of it is consistent @@ -66,3 +67,8 @@ def pyafs_error(code): if code != 0: raise AFSException(code) + +def path_to_bytes(path): + if isinstance(path, unicode): + return path.encode(sys.getfilesystemencoding(), 'surrogateescape') + return path diff --git a/afs/acl.py b/afs/acl.py index 1729442..65ec595 100644 --- a/afs/acl.py +++ b/afs/acl.py @@ -11,7 +11,7 @@ "none": "", } -_reverseCanonical = dict((y, x) for (x, y) in _canonical.iteritems()) +_reverseCanonical = dict((y, x) for (x, y) in _canonical.items()) _charBitAssoc = [ ('r', READ), diff --git a/afs/pts.py b/afs/pts.py index 95c6d4a..eb69c77 100644 --- a/afs/pts.py +++ b/afs/pts.py @@ -381,7 +381,7 @@ def getEntry(self, ident): elt) return ident - elif isinstance(ident, basestring): + elif isinstance(ident, (str, bytes)): return PTEntry(self, name=ident) else: return PTEntry(self, id=ident) From 035a1a7b0ecb118e73c1cd7e46f6ba2e9efa5298 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 13 Dec 2019 12:22:36 -0500 Subject: [PATCH 7/7] Bump version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 17b3ba0..f61f81f 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ def PyAFSExtension(module, *args, **kwargs): setup( name="PyAFS", - version="0.1.1", + version="0.1.2", description="PyAFS - Python bindings for AFS", author="Evan Broder", author_email="broder@mit.edu",