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

Feature Request: unix socket file descriptor support #64

Closed
Dretch opened this issue Jul 2, 2023 · 2 comments
Closed

Feature Request: unix socket file descriptor support #64

Dretch opened this issue Jul 2, 2023 · 2 comments

Comments

@Dretch
Copy link
Contributor

Dretch commented Jul 2, 2023

Currently file descriptors are just (de)serialized as regular integers. However, since file descriptors are an index into a per-process table, and d-bus normally operates between different processes, the file descriptors passed from one dbus client process will not normally make any sense on the receiving client process. Moreover this does not seem to be the way the dbus protocol is intended to be implemented.

The spec says that "...file descriptors need to be transferred via platform specific mechanism out-of-band. They must be sent at the same time as part of the message itself. They may not be sent before the first byte of the message itself is transferred or after the last byte of the message itself.".

In practice (i.e. the reference implementation), this seems to mean the following:

  • File descriptor passing is only supported for unix sockets (not TCP).
  • This uses a special feature that Unix sockets have for passing file descriptors (see e.g. https://blog.cloudflare.com/know-your-scm_rights/).
  • The file descriptors in the message itself are serialized as indices into the array of file descriptors that are passed in SCM_RIGHTS for that particular message (rather than indices into the per-process array)
  • Where a client wants to send/receive file descriptors they need to request permission during the connection process by sending "NEGOTIATE_UNIX_FD" and getting back "AGREE_UNIX_FD".

This ticket is to request that unix-socket-fd-passing be supported in haskell-dbus-client.

I'd be happy to implement this myself, if this meets with approval. I have some prototype code to prove it works, but this needs a lot of finishing / cleaning up.

@rblaze
Copy link
Owner

rblaze commented Jul 2, 2023

Sure, if you send a pull request, I'll be happy to merge this feature.

Dretch added a commit to Dretch/haskell-dbus that referenced this issue Aug 10, 2023
rblaze added a commit that referenced this issue Aug 22, 2023
* Allow sending and receiving Unix file descriptors.

Fixes issue #64

* Make file descriptor support backwards compatible.

* Fix benchmarks.

---------

Co-authored-by: Andrey Sverdlichenko <blaze@rusty.zone>
@Dretch
Copy link
Contributor Author

Dretch commented Aug 26, 2023

This is now implemented, thanks for merging and releasing @rblaze

@Dretch Dretch closed this as completed Aug 26, 2023
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