qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/3] qio: add support for SO_PEERCRED for socket channel


From: Paolo Bonzini
Subject: Re: [PATCH v2 1/3] qio: add support for SO_PEERCRED for socket channel
Date: Wed, 1 Nov 2023 15:23:01 +0100
User-agent: Mozilla Thunderbird

On 11/1/23 11:20, Daniel P. Berrangé wrote:
On Tue, Oct 31, 2023 at 03:46:01PM +0100, Anthony Harivel wrote:
The function qio_channel_get_peercred() returns a pointer to the
credentials of the peer process connected to this socket.

This credentials structure is defined in <sys/socket.h> as follows:

struct ucred {
        pid_t pid;    /* Process ID of the sending process */
        uid_t uid;    /* User ID of the sending process */
        gid_t gid;    /* Group ID of the sending process */
};

The use of this function is possible only for connected AF_UNIX stream
sockets and for AF_UNIX stream and datagram socket pairs.

Signed-off-by: Anthony Harivel <aharivel@redhat.com>
---
  include/io/channel.h | 20 ++++++++++++++++++++
  io/channel-socket.c  | 17 +++++++++++++++++
  io/channel.c         | 12 ++++++++++++
  3 files changed, 49 insertions(+)

diff --git a/include/io/channel.h b/include/io/channel.h
index 5f9dbaab65b0..99c02d61c3d9 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -149,6 +149,9 @@ struct QIOChannelClass {
                                    void *opaque);
      int (*io_flush)(QIOChannel *ioc,
                      Error **errp);
+    void (*io_peercred)(QIOChannel *ioc,
+                        struct ucred *cred,
+                        Error **errp);

This isn't going to fly. 'struct ucred' is Linux specific, so this won't
compile on macOS, Windows, *BSD, and we don't really want a huge #ifdef
ladder in these APIs. This will need to explode the struct and return
the individual fields that are present instead, and the impl side must
compile on other OS, even if its just stubbed out to return an error.

I would further reduce it to to io_peerpid, because the BSDs can only provide the peer uid and gid.

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]