Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Consider supporting Windows #15

Open
Cobertos opened this issue Feb 18, 2019 · 11 comments
Open

Consider supporting Windows #15

Cobertos opened this issue Feb 18, 2019 · 11 comments

Comments

@Cobertos
Copy link

Cobertos commented Feb 18, 2019

Your upstream fusepy supports Windows using winfsp.

I was able to get standardnotes-fs to run on Windows but wasn't able to get it to actually work. Because I was originally using dummy gid and uid values, I would get permission denied errors (similar to this user doing a similar migration)

It seems the only change that needs to be made is to have Windows call it's equivalent of getuid() and getgid() and then register the conversion from Windows sid to uid/gid with winfsp. I tried my best but got stuck when trying to convert between the pywin32 sid object and the winfspy cffi binding sid object. They're not the same size and the latter doesn't expose anything do me to use and I'm not familiar enough with the intricacies of these frameworks to get further.

Here's what I ended up with, replaced a few lines in sn_fuse.py

from platform import system
_system = system()
        if _system == 'Windows' or _system.startswith('CYGWIN'):
            #Convert windows sid to uid and gid with WinFSP
            #use WinFSP bindings
            from win32security import GetTokenInformation, OpenProcessToken, TOKEN_QUERY, TokenUser
            from win32process import GetCurrentProcess
            from winfspy.operations import lib
            sid = GetTokenInformation(OpenProcessToken(GetCurrentProcess(), TOKEN_READ), TokenUser)
            lib.FspPosixMapSidToUid(sid[0], 2) #Errors, here, sid is a PySID (from pywin32), where lib FspPosixMapSidToUid expects a cffi PSID
            lib.FspPosixMapSidToUid(sid[0], 3)
            self.uid = 2
            self.gid = 3
        else:
            self.uid = os.getuid()
            self.gid = os.getgid()
@tannercollin
Copy link
Owner

This is a good idea! Unfortunately, I don't know anything about windows and don't have easy access to a system I can test on. I'll definitely need help on this one.

What about blasting away self.uid and self.gid? On Linux, this will make the notes appear owned by root:root but it makes no difference in usability because FUSE still allows reading and writing.

You might get those same permission denied errors from before, however. This would only help if winfsp sets it to defaults that work.

@Cobertos
Copy link
Author

Cobertos commented Feb 18, 2019

You mean like not even passing them to the dir_stat and node_stat dicts at all? Originally I tried setting both to -1 to get the service to run on Windows and mount a folder but I didn't try removing them completely. I'll have to try that the next time I give this a shot, it'd be nice to have this working on Windows even without proper permissions.

IIRC I also read about a flag in winfsp for setting default permissions uid and gid, perhaps I should figure out if it's possible to query/use those. I'll look into this as well.

@tannercollin
Copy link
Owner

@Cobertos did you get a chance to test removing self.uid and self.gid?

@Cobertos
Copy link
Author

Cobertos commented Feb 22, 2019 via email

@Cobertos
Copy link
Author

Tried blowing away the passing of st_gid and st_uid into the dict and I get the same error. The default parameters I was looking into are also only for the CLI invocation of winfsp and I don't think they're supported through fusepy.

@Cobertos
Copy link
Author

Cobertos commented Feb 25, 2019

So after looking at this more, I think the route needs to be either to add all the windows functions from win32api or just ConvertStringSidToSid to winsfpy.

I figured out how to use cffi and compiled my own module with ConvertStringSidToSid but apparently you're not allowed to mix types from two instances of ffi, so I'll probably have to locally clone [winsfpy] and make a PR to get this to work. I'll probably be back once I have time to do that.

@tannercollin
Copy link
Owner

Sounds good, thanks for looking at this!

@AlJohri
Copy link

AlJohri commented Apr 22, 2020

I would also be really interested in Windows support. @Cobertos do you have any thoughts on where you left off with this?

@Cobertos
Copy link
Author

Cobertos commented Apr 22, 2020

@AlJohri

IIRC, using winsfpy and win32api separately get you 95% of the way there. You can get the current user SID with win32api code above, but there's no way to convert it to winsfpys internal SID object to store an SID to UID/GID mapping. Unfortunately wasn't able to get any insight from winsfpys developers Scille/winfspy#1

Cloning winsfpy and adding a binding to convert from a string SID to it's internal SID object should be the final step of this problem (or perhaps there's a lower level solution by working with CFFI internals but I'm unaware). I think there's already bindings for certain win32 API calls in winsfpy so it should be as simple as adding another for ConvertStringSidToSid. Then, using the code in the OP, that should add the functionality to this library, where on Windows, it'll do the SID conversion to get the UID/GID to set the files with when passing it to fusepy.

I've since transitioned to using a different note app though, so I haven't put any more work into this.

@tannercollin
Copy link
Owner

tannercollin commented Apr 23, 2020

@Cobertos which note app? I'm always interested in alternatives.

Edit: I see you're using Notion.so. What made you switch? Do you pay for it?

@Cobertos
Copy link
Author

Cobertos commented Apr 23, 2020 via email

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

No branches or pull requests

3 participants