Does SwiftNIO support LOCAL_PEERCRED option when using Unix domain sockets?

Hi all, I am fairly new to SwiftNIO and Swift in general and was wondering if it is possible to send user credentials using Unix domain sockets with the LOCAL_PEERCRED socket option?

thanks!

The answer is "sort of".

You can use the SocketOptionProvider protocol to achieve what you need. This is a protocol to which the builtin NIO Channels conform, and which allows you to get and set "wide" socket options.

Currently this API does not provide a type safe helper for LOCAL_PEERCRED, so you will need to use the unsafe API to do it:

import Darwin

let future: EventLoopFuture<xucred> = (channel as! SocketOptionProvider).unsafeGetSocketOption(level: SOL_LOCAL, name: LOCAL_PEERCRED)

We'd be happy to accept an enhancement to add support for LOCAL_PEERCRED in the type-safe portion of the API. This would be Darwin and FreeBSD specific.

2 Likes

Awesome, thanks for the quick response!

2 Likes