erlang / otp

Erlang/OTP
http://erlang.org
Apache License 2.0
11.4k stars 2.95k forks source link

ERL-1201: cmsghdr data should accept structures/lists where acceptable #4356

Open OTP-Maintainer opened 4 years ago

OTP-Maintainer commented 4 years ago

Original reporter: hauleth Affected version: Not Specified Component: kernel Migrated from: https://bugs.erlang.org/browse/ERL-1201


Currently most of the possible {{cmsghdr}} entries accept only binary, this is problematic as there is no way to safely encode for example {{pid_t}} in Erlang that would be platform independent. So the proposal is to allow passing "meaningful" data to such structure, such types would be:
 * Map in form of {{#\{pid => integer(), uid => integer(), gid => integer()\}}} for {{credentials}} type
 * List in form of {{[integer()]}} in case of {{rights}}

I haven't found what is the expected data in case of {{timestamp}} type. Without such constructs it make usage of {{socket:sendmsg}} pretty impossible without using NIFs.
OTP-Maintainer commented 4 years ago

hauleth said:

Ok, I have read a little bit about it and it is even a little bit more complex. In FreeBSD (and derivatives like macOS) it uses [different structure|https://github.com/freebsd/freebsd/blob/401e02f6005b2cbeb79c8a6ebaf412be79ff2775/tools/regression/sockets/unix_cmsg/t_cmsgcred.c#L43] (actually [two structs|https://github.com/freebsd/freebsd/blob/401e02f6005b2cbeb79c8a6ebaf412be79ff2775/tools/regression/sockets/unix_cmsg/t_sockcred.c#L43] depending on how the creds are sent) than [Linux|https://linux.die.net/man/7/unix]. So the only fields that are *guaranteed to be present* on both are {{uid}} and {{gid}}. I have no idea how to solve sending part, on receiving end we can just check which one is the arriving and decode respectively.
OTP-Maintainer commented 4 years ago

bmk said:

Yes, and OpenBSD and NetBSD has also different structures.