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

freebsdlike: add SCM_CREDS, struct sockcred #1740

Merged
merged 2 commits into from
Apr 15, 2020

Conversation

valpackett
Copy link
Contributor

@valpackett valpackett commented Apr 14, 2020

  • SCM_CREDS is present on both FreeBSD and DragonFly, is used for sending struct cmsgcred control messages
  • struct sockcred is present on FreeBSD, is used with LOCAL_CREDS socket option

@rust-highfive
Copy link

r? @JohnTitor

(rust_highfive has picked a reviewer for you, use r? to override)

@asomers
Copy link
Contributor

asomers commented Apr 14, 2020

This change looks good, but you should also define that constant for NetBSD (0x4), OpenBSD (0x2), and OSX (0x3).

@valpackett
Copy link
Contributor Author

valpackett commented Apr 15, 2020

It's already defined for Apple and NetBSD — but it's (correctly) not 0x4 on the latter:

src/unix/bsd/netbsdlike/netbsd/mod.rs
1101:pub const SCM_CREDS: ::c_int = 0x10;

@valpackett
Copy link
Contributor Author

And it hasn't been available in OpenBSD since 2012 (I wonder what these "newer APIs" are lol)

openbsd/src@8dd28dc

@asomers
Copy link
Contributor

asomers commented Apr 15, 2020

It's already defined for Apple and NetBSD — but it's (correctly) not 0x4 on the latter:

src/unix/bsd/netbsdlike/netbsd/mod.rs
1101:pub const SCM_CREDS: ::c_int = 0x10;

Ahh, good catch. It looks like NetBSD changed it 4 years ago, and wisely added a backwards-compatibility version: NetBSD/src@8e79650 . I was looking at NetBSD 6 source.

It is present on both FreeBSD and DragonFly
Like on NetBSD, but without a pid field in the struct.
@valpackett valpackett changed the title freebsdlike: add SCM_CREDS freebsdlike: add SCM_CREDS, struct sockcred Apr 15, 2020
Copy link
Member

@JohnTitor JohnTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@JohnTitor JohnTitor merged commit 59d3dab into rust-lang:master Apr 15, 2020
@valpackett valpackett deleted the freebsd-creds branch April 15, 2020 19:23
bors bot added a commit to nix-rust/nix that referenced this pull request May 2, 2020
1216: Add UnixCredentials support on FreeBSD/DragonFly r=asomers a=myfreeweb

This allows working with `SCM_CREDS` messages, which are like `SCM_CREDENTIALS` on Linux, but slightly different (always overwritten by the kernel, contain a bit more info — euid and groups).

With this PR, it is possible to write portable code that would use the appropriate message for the platform, but one remaining quirk is that `PassCred` thing still has to be present and `cfg`'d to Linux.

Adding the `SCM_CREDS` constant to libc: rust-lang/libc#1740

Co-authored-by: Greg V <[email protected]>
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

Successfully merging this pull request may close these issues.

4 participants