Patch created 3/2/3004 Jeremy Kitchen - kitchen@scriptkitchen.com jeremy@inter7.com Info: this patch makes relay-ctrl more ucspi compliant. Gotchas: unfortunately it imposes an arbitrary limit on $PROTO, although I don't think there will be much of a problem with this in the wild. Testing: I've tested this with ucspi-tcp and ucspi-ssl, and it appears to work in both situations. Using strncpy and strncat protect from buffer overflows hopefully. Thanks: Thanks to Ken Jones (kbo@inter7.com) for verifying my thoughts and assisting me with the theory behind using strncpy and strncat instead of strcpy and strcat. Thanks to Bruce Guenter for writing this excellent software for me to patch! :) diff -urN relay-ctrl-3.1.1.orig/relay-ctrl-allow.c relay-ctrl-3.1.1.ucspi/relay-ctrl-allow.c --- relay-ctrl-3.1.1.orig/relay-ctrl-allow.c 2002-04-26 11:07:38.000000000 -0500 +++ relay-ctrl-3.1.1.ucspi/relay-ctrl-allow.c 2004-03-02 12:50:03.000000000 -0600 @@ -73,7 +73,14 @@ int main(int argc, char* argv[]) { - if ((ip = getenv("TCPREMOTEIP")) == 0 || (ip = validate_ip(ip)) == 0) + const char* proto; + char envremoteip[50]; + + if ((proto = getenv("PROTO")) == 0) + die1(111, "PROTO not set, caller is not ucspi compliant"); + strncpy(envremoteip, proto, sizeof(envremoteip)); + strncat(envremoteip, "REMOTEIP", sizeof(envremoteip)); + if ((ip = getenv(envremoteip)) == 0 || (ip = validate_ip(ip)) == 0) die1(111, "Must be run from tcp-env or tcpserver."); if ((dir = getenv("RELAY_CTRL_DIR")) == 0) warn1("$RELAY_CTRL_DIR is not set."); diff -urN relay-ctrl-3.1.1.orig/relay-ctrl-check.c relay-ctrl-3.1.1.ucspi/relay-ctrl-check.c --- relay-ctrl-3.1.1.orig/relay-ctrl-check.c 2002-04-26 11:07:38.000000000 -0500 +++ relay-ctrl-3.1.1.ucspi/relay-ctrl-check.c 2004-03-02 12:11:25.000000000 -0600 @@ -74,6 +74,8 @@ const char* ip; const char* dir; const char* tmp; + const char* proto; + char envremoteip[50]; if (argc < 2) die1(1, "usage: relay-ctrl-check program [arguments]\n"); if (getenv("RELAY_CTRL_LOG_IPS") != 0) msg_debug_bits |= LOG_IPS; @@ -82,10 +84,16 @@ if ((tmp = getenv("RELAY_CTRL_EXPIRY")) != 0) expiry = atol(tmp); if (expiry <= 0) expiry = 900; if ((rc = getenv("RELAY_CTRL_RELAYCLIENT")) == 0) rc = ""; - if ((ip = getenv("TCPREMOTEIP")) == 0) - warn1("$TCPREMOTEIP not set, not checking IP"); - else if (do_chdir()) - stat_ip(ip); + if ((proto = getenv("PROTO")) == 0) + warn1("$PROTO not set, not checking IP"); + else { + strncpy(envremoteip, proto, sizeof(envremoteip)); + strncat(envremoteip, "REMOTEIP", sizeof(envremoteip)); + if ((ip = getenv(envremoteip)) == 0) + warn3("$", envremoteip, " not set, not checking IP"); + else if (do_chdir()) + stat_ip(ip); + } } else debug1(LOG_IPS, "$RELAYCLIENT already set, not checking IP"); diff -urN relay-ctrl-3.1.1.orig/relay-ctrl-send.c relay-ctrl-3.1.1.ucspi/relay-ctrl-send.c --- relay-ctrl-3.1.1.orig/relay-ctrl-send.c 2002-04-26 11:07:38.000000000 -0500 +++ relay-ctrl-3.1.1.ucspi/relay-ctrl-send.c 2004-03-02 12:16:35.000000000 -0600 @@ -114,10 +114,16 @@ { char* remotes; const char* tmp; + const char* proto; + char envremoteip[50]; if (argc < 2) die1(111, "usage: relay-ctrl-send program [args ...]"); - if ((tmp = getenv("TCPREMOTEIP")) == 0 || (tmp = validate_ip(tmp)) == 0) - die1(111, "Must be run from tcp-env or tcpserver."); + if ((proto = getenv("PROTO")) == 0) + die1(111, "Caller program is not ucspi compliant."); + strncpy(envremoteip, proto, sizeof(envremoteip)); + strncat(envremoteip, "REMOTEIP", sizeof(envremoteip)); + if ((tmp = getenv(envremoteip)) == 0 || (tmp = validate_ip(tmp)) == 0) + die3(111, "$" , envremoteip, "not set, caller program is not ucspi compliant"); if (!make_packet(tmp)) die1(111, "Failed to build packet data"); strcpy(packet, tmp);