[exim] Sane way to establish username given a UID

Páxina inicial
Borrar esta mensaxe
Responder a esta mensaxe
Autor: Patrick J Cherry
Data:  
Para: exim-users
Asunto: [exim] Sane way to establish username given a UID
Hello all,

I was wondering if there was a sane way of working out username given a
numeric user id during the RCPT TO ACL. There are plenty of ways to do
it vice versa (passwd db lookup, lsearch /etc/passwd).

So far I've come up with either using perl, or running a command. So
I've got:

-----------8<-----------------------
# This variable contains the user ID of the owner of the vhost directory
set acl_m0 = ${extract{uid}{${stat:/home/${domain}}}}

# This variable then contains the username (or nobody if grep fails, or the
# userid < 1000)
set acl_m1  = ${if <{1000}{$acl_m0}{nobody}\
                {${extract{1}{:}\
                  {${run{ \
                    /bin/egrep "^[^:]+:[^:]+:$acl_m0:" /etc/passwd\
                  }{$value}{nobody}}}\
                }}\
              }
-----------8<-----------------------


which is OK, but not great. I'd much rather have

-----------8<-----------------------
set acl_m0 = ${extract{username}{\
               ${lookup getpwid{\
                 ${extract{uid}{${stat:/home/${domain}}}}
                }} \
             }}
-----------8<-----------------------


which is marginally neater. Having had a look at lookup/passwd.c in the
source, I fear patching the code!

Thanks!

--
Patrick Cherry