I am trying to implement a way to determine which user is owner of some process's session, in a way that's as cross-platform as possible.
In Linux I can trace the process's pty by following the link /proc/PID/fd/0 -> /dev/pts/31
and looking up who is the owner of this terminal in the utmp file.
How do I do this in, say, AIX 6.1? /proc/PID/fd
contains char files and not symlinks as Linux does… Also what is the exact structure of a single entry in utmp file on AIX 6.1? Tried to read it using 7.1 [http://www-01.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.files/utmp.h.htm] utmp structures but it does not really fit the pattern.
Best Answer
Maybe I am over simplifying, but, can you just do this?
Here is an example:
Here is how you could determine to allow or deny access to a particular process:
You first determine who owns the process and which pts device started it by using:
Then you check the owner of the pts/X device, like this:
If the owner of /dev/pts/X is the same as the process owner then then the process was started by the login user and you will grant access, if the owner of the /dev/pts/X device is not the same as the owner of the process then you deny access.