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

Windows compatibility #1

Closed
3 tasks done
Frederick888 opened this issue May 17, 2020 · 4 comments
Closed
3 tasks done

Windows compatibility #1

Frederick888 opened this issue May 17, 2020 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Frederick888
Copy link
Owner

Frederick888 commented May 17, 2020

Tasks to tackle:

  • Socket path

thread_local!(pub static SOCKET_PATH: OnceCell<PathBuf> = OnceCell::new());
pub fn get_socket_path() -> Result<PathBuf> {
SOCKET_PATH.with(|s| -> Result<_> {
Ok(s.get_or_try_init(|| -> Result<_> {
let xdg_dirs = xdg::BaseDirectories::new().unwrap();
xdg_dirs
.find_runtime_file(KEEPASS_SOCKET_NAME)
.ok_or(anyhow!(SocketPathError {}))
})?
.clone())
})
}

XDG probably doesn't work under Win. KeePassXC uses named pipes under Win and the path is %TMP%\kpxc_server (e.g. C:\Users\Administrator\AppData\Local\Temp\kpxc_server). It listens on another one called keepassxc-Administrator.socket at the same time, not sure whether it's for browser integration as well or not.

  • UnixStream -> Named pipe

fn get_stream() -> Result<Rc<RefCell<UnixStream>>> {
thread_local!(static STREAM: OnceCell<Rc<RefCell<UnixStream>>> = OnceCell::new());
Ok(STREAM.with(|s| -> Result<_> {
Ok(s.get_or_try_init(|| -> Result<_> {
let path = get_socket_path()?;
Ok(Rc::new(RefCell::new(UnixStream::connect(path)?)))
})?
.clone())
})?)
}

Two most popular implementations are:
https://crates.io/crates/named_pipe
https://crates.io/crates/mio-named-pipes

We should probably use the first one as it doesn't seem to require a runtime. It's a synchronous CLI tool at the end of the day and we don't need asynchronous stuff.

pub fn exchange_message(request: String) -> Result<String> {
debug!(crate::LOGGER.get().unwrap(), "SEND: {}", request);
let mut stream = get_stream()?.borrow().try_clone()?;
stream.write_all(request.as_bytes())?;
stream.write_all(b"\n")?;
let mut response = String::new();
const BUF_SIZE: usize = 128;
let mut buf = [0u8; BUF_SIZE];
loop {
let len = stream.read(&mut buf)?;
response.push_str(str::from_utf8(&buf[0..len]).unwrap());
if len < BUF_SIZE {
break;
}
}
debug!(crate::LOGGER.get().unwrap(), "RECV: {}", response);
Ok(response)
}

exchange_message() needs to be updated as well.

  • Logger

let decorator = slog_term::TermDecorator::new().build();

Does TermDecorator work in cmd/PowerShell? Do we need to switch to PlainSyncDecorator under Win?

@Frederick888 Frederick888 added the help wanted Extra attention is needed label May 17, 2020
@Frederick888
Copy link
Owner Author

Might be useful: https://crates.io/crates/directories-next

@Frederick888
Copy link
Owner Author

@riedel Could you please give 1-windows-support branch a shot?

I cross-compiled to x86_64-pc-windows-gnu using MinGW and I was able to use the program in Cygwin, e.g.

$ git-credential-keepassxc configure
$ git config --global credential.helper keepassxc
$ printf "url=https://example.com\nusername=foo\n" | git credential fill

In CMD/PowerShell the coloured output also looked ok but I don't know how to do I/O redirection in CMD/PowerShell so I didn't test credential retrieval.

And if everything on 1-windows-support looks alright (fingers crossed lol!), is it also possible for you to try targeting x86_64-pc-windows-msvc then test it again? Thanks.

@riedel
Copy link

riedel commented May 29, 2020

Cool it works on 1-windows-support !!!! Thanks!

However, I had a problem with multiple accounts. I guess I can open a ticket.

I managed to to compile it via with msvc too.

@Frederick888
Copy link
Owner Author

@riedel Thanks for testing msvc.

However, I had a problem with multiple accounts. I guess I can open a ticket.

Because currently usernames are not used when retrieving credentials I guess. Anyway, please open another ticket for this and some debug (-vvv) logs would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants