summaryrefslogtreecommitdiff
path: root/nocompile/bin/identd.sh
blob: 67de2441fb704f42617b46f9d397aac61dc5829f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
IPA="$(/usr/local/libexec/sockip | head -n1)"
IPB="$(/usr/local/libexec/peerip | head -n1)"
#read the ports from stdin to be looked up.
#in the format: PORT, PORT\r\n
read LINE
PB="$(printf "%s" "$LINE" | cut -d, -f1 | tr -cd "[0-9]")"
PA="$(printf "%s" "$LINE" | cut -d, -f2 | tr -cd "[0-9]")"
#example output:
#57132,6667:USERID:UNIX:segfault
#5132,6667:ERROR:NO-USER
USER="$(getent passwd "$(tcpident $IPA $PA $IPB $PB)" | cut -d: -f1)"
if [ "_$USER" != "_" ];then
 printf "%s,%s:USERID:UNIX:%s\r\n" "$PB" "$PA" "$USER"
else
 printf "%s,%s:ERROR:NO-USER\r\n" "$PB" "$PA"
fi