stream-lua-nginx-module icon indicating copy to clipboard operation
stream-lua-nginx-module copied to clipboard

Add getpeercred operation on unix request socket

Open bjne opened this issue 6 years ago • 2 comments

SO_PEERCRED is afaik available on Linux only, and so far only on unix sockets. This command will not be compiled on other platforms.

syntax: local client = assert(ngx.req.socket(true)) uid, gid, pid = client:getpeercred() if not uid then ... end

bjne avatar Sep 05 '18 18:09 bjne

@bjne Should we reuse the existing getoption() method instead? There are just too many getsockopt() possibilities.

Also, I think we should add a feature test for the SO_PEERCRED thing directly in the config file instead of assuming all linux versions do support this thing.

For such things without I/O, it might indeed be more flexible to expose the fd from the cosocket object.

agentzh avatar Sep 05 '18 18:09 agentzh

@agentzh getpeercred is inspired by luasocket's getpeername, but I have no strong opinions here, so just tell me what to do. sock:getoption("peercred")?

Agree with feature testing, will look into it.

so you are suggesting exposing sock:fd()?

bjne avatar Sep 05 '18 19:09 bjne