From 324450579cca7161112e3d7b50092a8865071136 Mon Sep 17 00:00:00 2001 From: David Hedbor <david@hedbor.org> Date: Tue, 7 Apr 1998 22:38:52 -0700 Subject: [PATCH] First version if the Ident protocol. Rev: lib/modules/Protocols.pmod/Ident.pmod:1.1 --- .gitattributes | 1 + lib/modules/Protocols.pmod/Ident.pmod | 57 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 lib/modules/Protocols.pmod/Ident.pmod diff --git a/.gitattributes b/.gitattributes index 83c042cf3e..78a473397e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -37,6 +37,7 @@ testfont binary /lib/modules/LR.pmod/rule.pike foreign_ident /lib/modules/LR.pmod/scanner.pike foreign_ident /lib/modules/MIME.pmod foreign_ident +/lib/modules/Protocols.pmod/Ident.pmod foreign_ident /lib/modules/Protocols.pmod/TELNET.pmod foreign_ident /lib/modules/Protocols.pmod/X.pmod/Atom.pmod foreign_ident /lib/modules/Protocols.pmod/X.pmod/Auth.pmod foreign_ident diff --git a/lib/modules/Protocols.pmod/Ident.pmod b/lib/modules/Protocols.pmod/Ident.pmod new file mode 100644 index 0000000000..d615035fe1 --- /dev/null +++ b/lib/modules/Protocols.pmod/Ident.pmod @@ -0,0 +1,57 @@ +// An implementation of the IDENT protocol, specified in RFC 931. +// +// $Id: Ident.pmod,v 1.1 1998/04/08 05:38:52 neotron Exp $ + + +class client { + + int|array (string) lookup(object fd) + { + mixed raddr; // Remote Address. + mixed laddr; // Local Address. + array err; + object remote_fd; + if(!fd) + return 0; + err = catch(raddr = fd->query_address()); + if(err) + throw(err + ({"Error in Protocols.Ident:"})); + err = catch(laddr = fd->query_address(1)); + if(err) + throw(err + ({"Error in Protocols.Ident:" })); + if(!raddr || !laddr) + throw(backtrace() +({ "Protocols.Ident - cannot lookup address"})); + + laddr = laddr / " "; + raddr = raddr / " "; + + remote_fd = Stdio.File(); + if(!remote_fd->open_socket()) { + destruct(remote_fd); + throw(backtrace() +({ "Protocols.Ident: open_socket() failed."})); + } + if(err = catch(remote_fd->connect(raddr[0], 113))) + { + destruct(remote_fd); + throw(err); + } + if(remote_fd->write(laddr[1]+","+raddr[1]+"\r\n") == -1) { + destruct(remote_fd); + throw(backtrace() +({ "Protocols.Ident: write failed."})); + } + mixed response = remote_fd->read(); + if(!response || !strlen(response)) + { + destruct(remote_fd); + throw(backtrace() +({ "Protocols.Ident: read failed."})); + } + remote_fd->close(); + destruct(remote_fd); + response -= " "; + response -= "\r\n"; + response /= ":"; + if(sizeof(response) < 3) + return ({ "ERROR", "UNKNOWN-ERROR" }); + return response[1..]; + } +} -- GitLab