ピアクレデンシャルを確認する最も簡単な方法は、SO_PEERCRED
です。 tlpiexampleから
int len;
struct ucred ucred;
len = sizeof(struct ucred);
if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1)
// check errno
printf("Credentials from SO_PEERCRED: pid=%ld, euid=%ld, egid=%ld\n",
(long) ucred.pid, (long) ucred.uid, (long) ucred.gid);
SO_PEERCRED
Return the credentials of the foreign process connected to
this socket. This is possible only for connected AF_UNIX
stream sockets and AF_UNIX stream and datagram socket pairs
created using socketpair(2); see unix(7). The returned
credentials are those that were in effect at the time of the
call to connect(2) or socketpair(2). The argument is a ucred
structure; define the _GNU_SOURCE feature test macro to obtain
the definition of that structure from <sys/socket.h>. This
socket option is read-only.
:ソケットsock
のためにこれを行うには 。 PostgreSQLには他のユニックスのいくつかの亜種があります。
実際これは私が今までの違いを気付かなかったのに、 。 :P – yuyichao
'struct ucred'を定義するためにヘッダファイルを' 'にする前に' #define _GNU_SOURCE'する必要があるLinuxシステムがあることにも言及する価値があります。 –
mormegil