3

Is there some way or something similar like ucred for AF_UNIX in the case of AF_INET sockets (TCP in my case) for finding out the UID of the client connected to my socket?

There's also /proc/net/tcp but it shows the UID of the creator of the socket and not of the connected client.

Thank you.

emmerich
  • 512
  • 1
  • 5
  • 14
  • What do you mean by "connected client"? – President James K. Polk Jun 14 '17 at 21:08
  • Also see [Is it possible to find which user is at the other end of a localhost TCP connection?](https://stackoverflow.com/q/44534040/608639) – jww Jun 14 '17 at 22:10
  • In most cases the creator and the connected client will have the same UID. – Omnifarious Jun 15 '17 at 00:24
  • @JamesKPolk: an entity who called connect() and reads() what I, as a server, write() jww: there it mentions what I already knew about /proc/net/tcp Omnifarious: for my use case, the clients may be either root or some other, unprivileged user whom I need to distinguish. – emmerich Jun 15 '17 at 03:42
  • 1
    In general, there is no way to associate a UID (which is a linux thing) with the remote peer of a TCP connection. At the TCP level the connecting client is not authenticated. If the client can complete the TCP handshake then it is "connected". There is nothing in that handshake that would identify the user on the client side, so there's really no way to obtain a UID. If you ran a higher-level protocol like ssh on top of TCP, you could have the concept of a "logged in" user and you could obtain the UID at that point. – President James K. Polk Jun 15 '17 at 13:47
  • @emmerich in the localhost case the connection shows up twice in /proc/net/tcp under two different ujds. – Omnifarious Jun 15 '17 at 19:59

0 Answers0