Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fd.writable misreporting #302

Open
yellephen opened this issue Nov 22, 2024 · 1 comment
Open

fd.writable misreporting #302

yellephen opened this issue Nov 22, 2024 · 1 comment

Comments

@yellephen
Copy link

yellephen commented Nov 22, 2024

I noticed that fd.writable was returning true when a file was opened with 'rb'.

with smbclient.open_file(file, 'rb') as fd:
    if fd.writable:
        print("     [x] The above file is writable by the smbuser passed.")
        fd.write("test")

The print line was printed and fd.write resulted in an exception.

The following works for the purpose.

try:
    with smbclient.open_file(file,'w') as fdw:
        print("     [x] The above file is writable by the smbuser passed.")
except:
    print("     [ ] No write access to above file.")
@jborean93
Copy link
Owner

jborean93 commented Nov 24, 2024

The writable member is not an attribute but rather a method https://docs.python.org/3/library/io.html#io.IOBase.writable. You can see this when you compare it to the builtin open method where writeable is also a function.

with open("/tmp/test.txt, mode="wb") as fd:
    print(fd.writable)  # <built-in method writable of _io.BufferedWriter object at 0xffffa23f4f60>
    print(fd.writeable()) # True

You need to do

with smbclient.open_file(file, 'wb') as fd:
    if fd.writable():
        print("     [x] The above file is writable by the smbuser passed.")
        fd.write("test")

Keep in mind it doesn't do an access check, it just tells you whether the opened IO object is opened as a writable stream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants