diff options
author | Chris Cleeland <chris.cleeland@gmail.com> | 2005-05-27 22:15:46 +0000 |
---|---|---|
committer | Chris Cleeland <chris.cleeland@gmail.com> | 2005-05-27 22:15:46 +0000 |
commit | 23506b3d4afaf7d774eddb11eb6c5b7ebddfe2ab (patch) | |
tree | 3a1431ffa912637b2a9222a856411071ad5de759 | |
parent | e7fe1596fb0190d5fc6df0371f6139db64cccb41 (diff) | |
download | ATCD-23506b3d4afaf7d774eddb11eb6c5b7ebddfe2ab.tar.gz |
ChangelogTag: Fri May 27 17:01:24 2005 Chris Cleeland <cleeland_c@ociweb.com>
Fix bidir GIOP and -ORBDottedDecimalAddresses; fix hostname_in_ior rules.
-rw-r--r-- | TAO/ChangeLog | 80 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/PortableGroup/UIPMC_Acceptor.cpp | 2 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp | 11 | ||||
-rwxr-xr-x | TAO/orbsvcs/tests/Security/BiDirectional/run_test.pl | 8 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/Security/BiDirectional/server.conf | 2 | ||||
-rw-r--r-- | TAO/tao/IIOP_Acceptor.cpp | 81 | ||||
-rw-r--r-- | TAO/tao/IIOP_Acceptor.h | 18 | ||||
-rw-r--r-- | TAO/tao/IIOP_Connection_Handler.cpp | 9 | ||||
-rw-r--r-- | TAO/tao/IIOP_Transport.cpp | 13 | ||||
-rw-r--r-- | TAO/tests/IOR_Endpoint_Hostnames/IOR_Endpoint_Hostnames.mpc | 15 | ||||
-rw-r--r-- | TAO/tests/IOR_Endpoint_Hostnames/bogus.idl | 11 | ||||
-rw-r--r-- | TAO/tests/IOR_Endpoint_Hostnames/bogus_i.cpp | 17 | ||||
-rw-r--r-- | TAO/tests/IOR_Endpoint_Hostnames/bogus_i.h | 30 | ||||
-rw-r--r-- | TAO/tests/IOR_Endpoint_Hostnames/generate_ior.cpp | 52 | ||||
-rw-r--r-- | TAO/tests/IOR_Endpoint_Hostnames/list_interfaces.cpp | 88 | ||||
-rwxr-xr-x | TAO/tests/IOR_Endpoint_Hostnames/run_test.pl | 256 | ||||
-rw-r--r-- | TAO/utils/catior/catior.cpp | 114 |
17 files changed, 752 insertions, 55 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 1eeb774c228..763eb41ee5f 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,83 @@ +Fri May 27 17:01:24 2005 Chris Cleeland <cleeland_c@ociweb.com> + + * orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp: + * tao/IIOP_Connection_Handler.cpp: + + Corrected a problem whereby, when listen points received in a + bidirectional context get processed, the key for the entry made + in the transport cache was created using the receiver's notion + of whether dotted decimal addresses (-ORBDottedDecimalAddresses) + should be used, rather than how the listen points were sent by + the sender. In doing so, when, for example, a CORBA server was + using -ORBDottedDecimalAddresses and the client was not, the + client's listen point got cached using its IP address rather + than its hostname. However, all the IORs distributed by the + client would use the hostname, and, thus, the server would not + be able to find a match for the client's endpoint in its cache, + and subsequently try to create a new one. + + The change now creates an entry in the cache using, for the + hostname portion of the key, the host name however the client + sent the hostname. This should insure that a receiver of a + bidirectional context will have the ability to find a match in + the transport cache. + + This change supercedes the following changelog entry: + + Thu Sep 13 11:05:13 2001 Balachandran Natarajan <bala@cs.wustl.edu> + + * orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp: + * tao/IIOP_Connection_Handler.cpp (process_listen_point_list): + + When creating an IIOP Endpoint, passed in the value of the + ORBDottedDecimal address value from the ORB_Core. This is a real + stupid mistake :(. Added a debug statement. Thanks to Werner + Buchert <w.buchert@medat.de> for reporting this problem. + + * tao/IIOP_Connection_Handler.cpp: + * orbsvcs/orbsvcs/PortableGroup/UIPMC_Acceptor.cpp: + * tao/IIOP_Acceptor.h: + * tao/IIOP_Acceptor.cpp: + * tao/IIOP_Transport.cpp: + + Modified the IIOP Acceptor so that the behavior for the host + identifier (hostname or IP address) that appears in IIOP + profiles is consistent with the following: + + 1. value from "hostname_in_ior", if specified; + 2. setting of -ORBDottedDecimalAddresses option + 3. value for <hostname> used in -ORBEndpoint iiop://<hostname> + 4. whatever TAO magically comes up with + + The significant change here is that previous to this change, + numbers 1 and 2 were reversed, i.e., -ORBDottedDecimalAddresses + took precedence over hostname_in_ior. + + * tests/IOR_Endpoint_Hostnames/IOR_Endpoint_Hostnames.mpc: + * tests/IOR_Endpoint_Hostnames/bogus.idl: + * tests/IOR_Endpoint_Hostnames/bogus_i.cpp: + * tests/IOR_Endpoint_Hostnames/bogus_i.h: + * tests/IOR_Endpoint_Hostnames/generate_ior.cpp: + * tests/IOR_Endpoint_Hostnames/list_interfaces.cpp: + * tests/IOR_Endpoint_Hostnames/run_test.pl: + + Added a new functionality/regression test for the change listed + above. The run_test.pl prints out a matrix for permutations and + expected results, and indicates whether each permutation + succeeds or fails. It also depends upon a new option to catior, + found in the next entry. + + * orbsvcs/tests/Security/BiDirectional/server.conf: + + Removed some hardcoded paths to OCI personal home directories. + + * utils/catior/catior.cpp: + + Added a "-x" option that works like "-f" except that it reads + the IOR from standard input (stdin or cin) rather than from a + file. This makes catior much more like the unix "cat" command, + and enables it to be used in a pipeline. + Fri May 27 15:54:44 2005 Justin Michel <michel_j@ociweb.com> * docs/Options.html: diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/UIPMC_Acceptor.cpp b/TAO/orbsvcs/orbsvcs/PortableGroup/UIPMC_Acceptor.cpp index 19c52c01f6a..0b7cbefeffc 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/UIPMC_Acceptor.cpp +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/UIPMC_Acceptor.cpp @@ -221,6 +221,7 @@ TAO_UIPMC_Acceptor::hostname (TAO_ORB_Core *, return this->dotted_decimal_address (addr, host); } +#if 0 int TAO_UIPMC_Acceptor::dotted_decimal_address (ACE_INET_Addr &addr, char *&host) @@ -240,6 +241,7 @@ TAO_UIPMC_Acceptor::dotted_decimal_address (ACE_INET_Addr &addr, host = CORBA::string_dup (tmp); return 0; } +#endif CORBA::ULong TAO_UIPMC_Acceptor::endpoint_count (void) diff --git a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp index abb85b4637c..2f6bef7091e 100644 --- a/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp +++ b/TAO/orbsvcs/orbsvcs/SSLIOP/SSLIOP_Connection_Handler.cpp @@ -371,13 +371,16 @@ TAO::SSLIOP::Connection_Handler::process_listen_point_list ( listen_point.host.in ())); } - // Construct an IIOP_Endpoint object - // Construct an IIOP_Endpoint object. + // Construct an IIOP_Endpoint object using the host as provided + // in the listen point list. We must use the host in that form + // because that's also how the ORB on the other side will + // advertise the host in an IOR. // // Note that the port in the ACE_INET_Addr is actually the SSL // port! - TAO_IIOP_Endpoint tmpoint (addr, - this->orb_core()->orb_params()->use_dotted_decimal_addresses ()); + TAO_IIOP_Endpoint tmpoint (listen_point.host.in (), + listen_point.port, + addr); // @@ This is broken. Instead of just using the default CORBA // SecurityAssociation options, by not supplying SSLIOP::SSL diff --git a/TAO/orbsvcs/tests/Security/BiDirectional/run_test.pl b/TAO/orbsvcs/tests/Security/BiDirectional/run_test.pl index ab2fe900834..7a181ebc862 100755 --- a/TAO/orbsvcs/tests/Security/BiDirectional/run_test.pl +++ b/TAO/orbsvcs/tests/Security/BiDirectional/run_test.pl @@ -19,7 +19,7 @@ $iter = 10; sub options () { my $help = 0; # handled locally my $man = 0; # handled locally - my $ssl = 1; # handled locally + my $ssl = 0; # handled locally my $dotdec = 0; # handled locally my $debug; # handled locally my $shost; # handled locally @@ -139,12 +139,12 @@ B<run_test.pl> [B<-help|?>] [B<-iter iterations>] [B<-chost host>] This is a test that exercises the birectional GIOP connection implementation in TAO over SSLIOP connection. Start the server like this -$ server -ORBSvcConf server.conf -o <file.ior> -i <no_iterations> -$ client -ORBSvcConf client.conf -k file://<file.ior> -x + $ server -ORBSvcConf server.conf -o <file.ior> -i <no_iterations> + $ client -ORBSvcConf client.conf -k file://<file.ior> -x Or, simply -$ ./run_test.pl -ssl + $ ./run_test.pl -ssl The server starts up writing the IOR to the file. The client then starts up, creates its own object and passes the reference to the server. Then diff --git a/TAO/orbsvcs/tests/Security/BiDirectional/server.conf b/TAO/orbsvcs/tests/Security/BiDirectional/server.conf index 94ef4319ef5..6ad7e6d78a8 100644 --- a/TAO/orbsvcs/tests/Security/BiDirectional/server.conf +++ b/TAO/orbsvcs/tests/Security/BiDirectional/server.conf @@ -1,6 +1,6 @@ dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() - "-SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey 'PEM:ssl/server-key.pem' -SSLCertificate 'PEM:ssl/server-cert.pem' -SSLCAFile 'PEM:ssl/ca.pem' -SSLRand /home/local/jeliazkov_i/.bashrc:/home/local/jeliazkov_i/.ssh/id_dsa.pub" + "-SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey 'PEM:ssl/server-key.pem' -SSLCertificate 'PEM:ssl/server-cert.pem' -SSLCAFile 'PEM:ssl/ca.pem'" dynamic Advanced_Resource_Factory Service_Object* TAO_Strategies:_make_TAO_Advanced_Resource_Factory () diff --git a/TAO/tao/IIOP_Acceptor.cpp b/TAO/tao/IIOP_Acceptor.cpp index 9ecf56cc44b..4e09e19d68b 100644 --- a/TAO/tao/IIOP_Acceptor.cpp +++ b/TAO/tao/IIOP_Acceptor.cpp @@ -122,6 +122,12 @@ TAO_IIOP_Acceptor::create_new_profile (const TAO::ObjectKey &object_key, // Create a profile for each acceptor endpoint. for (CORBA::ULong i = 0; i < this->endpoint_count_; ++i) { + // Skip if the host name + if (i > 0 + && ACE_OS::strcmp(this->hosts_[i], this->hosts_[0]) == 0 + && (this->addrs_[i].get_port_number() == this->addrs_[0].get_port_number())) + continue; + TAO_IIOP_Profile *pfile = 0; ACE_NEW_RETURN (pfile, TAO_IIOP_Profile (this->hosts_[i], @@ -217,6 +223,9 @@ TAO_IIOP_Acceptor::create_shared_profile (const TAO::ObjectKey &object_key, index < this->endpoint_count_; ++index) { + if (ACE_OS::strcmp(this->hosts_[index], this->hosts_[0]) == 0) + continue; + TAO_IIOP_Endpoint *endpoint = 0; ACE_NEW_RETURN (endpoint, TAO_IIOP_Endpoint (this->hosts_[index], @@ -270,6 +279,13 @@ TAO_IIOP_Acceptor::open (TAO_ORB_Core *orb_core, const char *address, const char *options) { + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("IIOP_Acceptor::open, address==%s, options=%s\n"), + address, options)); + } + this->orb_core_ = orb_core; if (this->hosts_ != 0) @@ -345,6 +361,14 @@ TAO_IIOP_Acceptor::open (TAO_ORB_Core *orb_core, specified_hostname = tmp_host; } + if (TAO_debug_level > 2) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("IIOP_Acceptor: specified host=%s:%d\n"), + (specified_hostname==0 ? "<null>" : specified_hostname), + addr.get_port_number ())); + } + this->endpoint_count_ = 1; // Only one hostname to store ACE_NEW_RETURN (this->addrs_, @@ -365,21 +389,15 @@ TAO_IIOP_Acceptor::open (TAO_ORB_Core *orb_core, ACE_TEXT ("Overriding address in IOR with %s\n"), ACE_TEXT_CHAR_TO_TCHAR (this->hostname_in_ior_))); } - if (this->hostname (orb_core, - addr, - this->hosts_[0], - this->hostname_in_ior_) != 0) - return -1; - } - else - { - if (this->hostname (orb_core, - addr, - this->hosts_[0], - specified_hostname) != 0) - return -1; + specified_hostname = this->hostname_in_ior_; } + if (this->hostname (orb_core, + addr, + this->hosts_[0], + specified_hostname) != 0) + return -1; + // Copy the addr. The port is (re)set in // TAO_IIOP_Acceptor::open_i(). if (this->addrs_[0].set (addr) != 0) @@ -562,7 +580,16 @@ TAO_IIOP_Acceptor::hostname (TAO_ORB_Core *orb_core, char *&host, const char *specified_hostname) { - if (orb_core->orb_params ()->use_dotted_decimal_addresses ()) + if (this->hostname_in_ior_ != 0) + { + if (TAO_debug_level >= 5) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("TAO (%P|%t) IIOP_Acceptor - Overriding the hostname with <%s>\n"), + this->hostname_in_ior_)); + + host = CORBA::string_dup (this->hostname_in_ior_); + } + else if (orb_core->orb_params ()->use_dotted_decimal_addresses ()) { // If dotted decimal addresses are enabled, // just return ours. @@ -707,27 +734,11 @@ TAO_IIOP_Acceptor::probe_interfaces (TAO_ORB_Core *orb_core) if_addrs[i].get_ip_address () == INADDR_LOOPBACK) continue; - if (this->hostname_in_ior_ != 0) - { - if (TAO_debug_level > 2) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Overriding address in IOR with %s\n"), - ACE_TEXT_CHAR_TO_TCHAR (this->hostname_in_ior_))); - } - if (this->hostname (orb_core, - if_addrs[i], - this->hosts_[host_cnt], - this->hostname_in_ior_) != 0) - return -1; - } - else - { - if (this->hostname (orb_core, - if_addrs[i], - this->hosts_[host_cnt]) != 0) - return -1; - } + if (this->hostname (orb_core, + if_addrs[i], + this->hosts_[host_cnt]) != 0) + return -1; + // Copy the addr. The port is (re)set in // TAO_IIOP_Acceptor::open_i(). diff --git a/TAO/tao/IIOP_Acceptor.h b/TAO/tao/IIOP_Acceptor.h index baf56b59359..1e56680f1b7 100644 --- a/TAO/tao/IIOP_Acceptor.h +++ b/TAO/tao/IIOP_Acceptor.h @@ -90,13 +90,25 @@ public: * A hostname may be forced by using specified_hostname. This * is useful if the given address corresponds to more than one * hostname and the desired one cannot be determined in any - * other way. + * other way. + * This method is used both when constructing IOR endpoints and LPL + * (listen point lists). + * + * The algorithm used is: + * - If hostname_in_ior_ has been set, it is used "as is"; + * - else if use_dotted_decimal_addresses_ is set, the text representaion + * of the IP is used; + * - else if specified_hostname is given, it used "as is"; + * - else a reverse (address to name) lookup is used to obtain the + * hostname or the IP if no reverse mapping exists. */ - int hostname (TAO_ORB_Core *orb_core, + virtual int hostname (TAO_ORB_Core *orb_core, ACE_INET_Addr &addr, char *&host, const char *specified_hostname = 0); +protected: + /** * Set the host name for the given address using the dotted decimal * format. @@ -104,8 +116,6 @@ public: int dotted_decimal_address (ACE_INET_Addr &addr, char *&host); -protected: - /** * Implement the common part of the open*() methods. This method is * virtual to allow a derived class implementation to be invoked diff --git a/TAO/tao/IIOP_Connection_Handler.cpp b/TAO/tao/IIOP_Connection_Handler.cpp index ed6e0d1d808..383f69f55d5 100644 --- a/TAO/tao/IIOP_Connection_Handler.cpp +++ b/TAO/tao/IIOP_Connection_Handler.cpp @@ -333,9 +333,12 @@ TAO_IIOP_Connection_Handler::process_listen_point_list ( ACE_TEXT_CHAR_TO_TCHAR(listen_point.host.in ()))); } - // Construct an IIOP_Endpoint object - TAO_IIOP_Endpoint endpoint (addr, - this->orb_core()->orb_params()->use_dotted_decimal_addresses ()); + // Construct an IIOP_Endpoint object using the host as provided + // in the listen point list. We must use host in that form because + // that's also how the ORB on the other side will advertise the host + // in an IOR. + TAO_IIOP_Endpoint endpoint (listen_point.host.in (), + listen_point.port, addr); // Construct a property object TAO_Base_Transport_Property prop (&endpoint); diff --git a/TAO/tao/IIOP_Transport.cpp b/TAO/tao/IIOP_Transport.cpp index 78106b6b34e..75ff779b373 100644 --- a/TAO/tao/IIOP_Transport.cpp +++ b/TAO/tao/IIOP_Transport.cpp @@ -352,8 +352,8 @@ TAO_IIOP_Transport::get_listen_point ( // Get the hostname for the local address if (iiop_acceptor->hostname (this->orb_core_, - local_addr, - local_interface.out ()) == -1) + local_addr, + local_interface.out ()) == -1) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("TAO (%P|%t) - IIOP_Transport::get_listen_point, ") @@ -379,6 +379,15 @@ TAO_IIOP_Transport::get_listen_point ( IIOP::ListenPoint & point = listen_point_list[len]; point.host = CORBA::string_dup (local_interface.in ()); point.port = endpoint_addr[index].get_port_number (); + + if (TAO_debug_level >= 5) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT("TAO (%P:%t) Listen_Point_List[%d] = <%s:%d>"), + len, + point.host.in (), + point.port)); + } + } } diff --git a/TAO/tests/IOR_Endpoint_Hostnames/IOR_Endpoint_Hostnames.mpc b/TAO/tests/IOR_Endpoint_Hostnames/IOR_Endpoint_Hostnames.mpc new file mode 100644 index 00000000000..f097eae9bc9 --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/IOR_Endpoint_Hostnames.mpc @@ -0,0 +1,15 @@ +// What I'd really like to have is a separate project +// that is a library for the CORBA Object. + +project(list_interfaces) : aceexe { + Source_Files { + list_interfaces.cpp + } +} + +project(generate_ior) : taoexe, portableserver { + Source_Files { + generate_ior.cpp + bogus_i.cpp + } +} diff --git a/TAO/tests/IOR_Endpoint_Hostnames/bogus.idl b/TAO/tests/IOR_Endpoint_Hostnames/bogus.idl new file mode 100644 index 00000000000..48c3ef6ef34 --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/bogus.idl @@ -0,0 +1,11 @@ +// +// $Id$ +// + +module Test +{ + interface bogus + { + void noop(); + }; +}; diff --git a/TAO/tests/IOR_Endpoint_Hostnames/bogus_i.cpp b/TAO/tests/IOR_Endpoint_Hostnames/bogus_i.cpp new file mode 100644 index 00000000000..fa04ba07a95 --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/bogus_i.cpp @@ -0,0 +1,17 @@ +ACE_RCSID (IOR_Endpoint_Hostnames, bogus_i, "$Id$") + +#include "bogus_i.h" + +bogus::bogus() +{ +} + +bogus::~bogus() +{ +} + +void +bogus::noop (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} diff --git a/TAO/tests/IOR_Endpoint_Hostnames/bogus_i.h b/TAO/tests/IOR_Endpoint_Hostnames/bogus_i.h new file mode 100644 index 00000000000..8d2b59c256f --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/bogus_i.h @@ -0,0 +1,30 @@ +// +// $Id$ +// + +#ifndef bogus_h +#define bogus_h +#include "ace/pre.h" + +#include "bogusS.h" + +#if defined (_MSC_VER) +# if (_MSC_VER >= 1200) +# pragma warning(push) +# endif /* _MSC_VER >= 1200 */ +# pragma warning (disable:4250) +#endif /* _MSC_VER */ + +class bogus + : public virtual POA_Test::bogus + , public virtual PortableServer::RefCountServantBase +{ +public: + bogus (); + virtual ~bogus (); + + virtual void noop (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); +}; + +#endif //bogus_h diff --git a/TAO/tests/IOR_Endpoint_Hostnames/generate_ior.cpp b/TAO/tests/IOR_Endpoint_Hostnames/generate_ior.cpp new file mode 100644 index 00000000000..032f56a797d --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/generate_ior.cpp @@ -0,0 +1,52 @@ +// +// This initializes an ORB, a POA, an Object within that POA, and +// obtains and prints an IOR for that Object. +// + +ACE_RCSID (IOR_Endpoint_Hostnames, generate_ior, "$Id$") + +#include "tao/corba.h" +#include "tao/PortableServer/PortableServer.h" + +#include "bogus_i.h" + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + int x = 0; + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var poa_object = + orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var rp = + PortableServer::POA::_narrow(poa_object.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (CORBA::is_nil (rp.in())) + ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) panic: nil root poa\n"), 1); + + bogus* bogus_impl = new bogus(); + PortableServer::ServantBase_var owner_transfer(bogus_impl); + Test::bogus_var b = bogus_impl->_this(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + CORBA::String_var ior = + orb->object_to_string (b.in() ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + printf ("%s\n", ior.in()); + + orb->shutdown(); + orb->destroy(); + } + ACE_CATCH (CORBA::Exception, e) + { + ACE_PRINT_EXCEPTION (e, "Caught exception:"); + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/IOR_Endpoint_Hostnames/list_interfaces.cpp b/TAO/tests/IOR_Endpoint_Hostnames/list_interfaces.cpp new file mode 100644 index 00000000000..75db7015da8 --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/list_interfaces.cpp @@ -0,0 +1,88 @@ +// +// Extract the address for each network interface using EXACTLY +// the same algorithm as TAO_IIOP_Acceptor, and then print +// it. This is used by the run_test.pl to know how to set up +// "expected results" for hostnames in IORs. +// + +#include "ace/ACE.h" +#include "ace/Auto_Ptr.h" +#include "ace/INET_Addr.h" +#include "ace/Log_Msg.h" + +ACE_RCSID (IOR_Endpoint_Hostnames, list_interfaces, "$Id$") + +int +main (int argc, char *argv[]) +{ + // network interfaces. + ACE_INET_Addr *if_addrs = 0; + size_t if_cnt = 0; + + unsigned long endpoint_count; + + if (ACE::get_ip_interfaces (if_cnt, + if_addrs) != 0 + && errno != ENOTSUP) + { + // In the case where errno == ENOTSUP, if_cnt and if_addrs will + // not be modified, and will each remain equal to zero. This + // causes the default interface to be used. + return -1; + } + + if (if_cnt == 0 || if_addrs == 0) + { + ACE_DEBUG ((LM_WARNING, + ACE_TEXT ("TAO (%P|%t) Unable to probe network ") + ACE_TEXT ("interfaces. Using default.\n"))); + + if_cnt = 1; // Force the network interface count to be one. + delete [] if_addrs; + if_addrs = new ACE_INET_Addr[if_cnt]; + } + + // Scan for the loopback interface since it shouldn't be included in + // the list of cached hostnames unless it is the only interface. + size_t lo_cnt = 0; // Loopback interface count + for (size_t j = 0; j < if_cnt; ++j) + if (if_addrs[j].get_ip_address () == INADDR_LOOPBACK) + lo_cnt++; + + ACE_Auto_Basic_Array_Ptr<ACE_INET_Addr> safe_if_addrs (if_addrs); + + // If the loopback interface is the only interface then include it + // in the list of interfaces to query for a hostname, otherwise + // exclude it from the list. + if (if_cnt == lo_cnt) + endpoint_count = ACE_static_cast(unsigned long, if_cnt); + else + endpoint_count = ACE_static_cast(unsigned long, if_cnt - lo_cnt); + + // The number of hosts/interfaces we want to cache may not be the + // same as the number of detected interfaces so keep a separate + // count. + size_t host_cnt = 0; + + for (size_t i = 0; i < if_cnt; ++i) + { + // Ignore any loopback interface if there are other + // non-loopback interfaces. + if (if_cnt != lo_cnt && + if_addrs[i].get_ip_address() == INADDR_LOOPBACK) + continue; + + // Print the address as a string. + printf ("%s\n", if_addrs[i].get_host_addr()); + + host_cnt++; + } + + return 0; +} + +#if defined(ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Auto_Basic_Array_Ptr<ACE_INET_Addr>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Auto_Basic_Array_Ptr<ACE_INET_Addr> +#endif diff --git a/TAO/tests/IOR_Endpoint_Hostnames/run_test.pl b/TAO/tests/IOR_Endpoint_Hostnames/run_test.pl new file mode 100755 index 00000000000..e979bf853bc --- /dev/null +++ b/TAO/tests/IOR_Endpoint_Hostnames/run_test.pl @@ -0,0 +1,256 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +# +# This run_test.pl does not use the standard harness as used by other +# run_test.pl. Since it is testing a behavior of TAO which is +# affected by environmental influences, it uses perl features as well +# as separate executables to obtain information about the environment +# so that it can inspect the information inside IORs and decide if +# that information is "correct" given the environment. +# +# At the end, it prints out a matrix of each permutation of the test +# and indicates whether or not that permutation FAILed. +# + +use lib '../../../bin'; +use PerlACE::Run_Test; +use Sys::Hostname; + +# Add the current directory to our execution path +use Env qw(@PATH); +push @PATH, $PerlACE::Process::ExeSubDir; + +open STDERR, ">&STDOUT" or die "cannot dup STDERR to STDOUT: $!\n"; + +open (INTERFACES, "list_interfaces|") || die "Unable to exec list_interfaces: $!\n"; +# We want this global... +chomp(@IPADDRS = <INTERFACES>); +close (INTERFACES); + +# Fill up the array of hostnames; can't use the hostname() from +# Sys::Hostname because it's too good at figuring out that IP +# addresses that aren't in a host table actually DO match to a host +# name. So, we use gethostbyaddr(). +use Socket; +@HOSTNAMES = map { (gethostbyaddr(inet_aton($_),AF_INET))[0] || $_ } @IPADDRS; + +$HN = hostname; # Shorthand so we do not have to use 'hostname' all over. + +# +# $TEST_DATA is a reference to an anonymous hash that has +# key: string representation/description of a test +# value: ref to anonymous array consisting of +# [0] = -ORBDottedDecimalAddresses value (must be 0 or 1) +# [1] = -ORBendpoint hosname spec (undef if not provided) +# [2] = -ORBendpoint "hostname_in_ior" value (undef if not provided) +# [3] = ref to array containing profiles expected in IOR +# + +$TEST_DATA = { + +# +# This is kind of like a "truth table" for what should happen when +# -ORBDottedDecimalAddresses (DDA) and the "hostname_in_ior" (HIOR) +# option for -ORBListenEndpoints (nee -ORBEndpoint) interact. Note +# that DDA's default value is "0", so there is no way to have an +# unspecified value for DDA. +# +# +# +# | -ORBendpoint | +# DDA | hostspec | HIOR | Profile(s) in IOR +# -------------------------------------------------------------- +# 0 | unspec | unspec | One profile for each interface +# discovered in +# TAO_IIOP_Acceptor::probe_interfaces(), +# where the host's name is that +# returned from a reverse lookup of +# the interface's address from +# whatever facility is doing +# name<->address translations for +# that host. + +"0:unspec:unspec" => [ 0, undef, undef, \@HOSTNAMES ], + +# 1 | unspec | unspec | One profile for each interface +# discovered in +# TAO_IIOP_Acceptor::probe_interfaces(), +# where the host's name is the IP +# address associated with the +# interface. + +"1:unspec:unspec" => [ 1, undef, undef, \@IPADDRS ], + +# 0 | "foo" | unspec | Exactly one profile where the +# host's name is "foo". + +"0:$HN:unspec" => [ 0, $HN, undef, [$HN] ], + +# 1 | "foo" | unspec | Exactly one profile where the +# host's name is the IP address +# from the name<->address +# translation for the host. + +"1:$HN:unspec" => [ 1, $HN, undef, [ inet_ntoa((gethostbyname(hostname))[4]) ] ], + +# X | unspec | "bar" | Exactly one profile where the +# host's name is "bar". +#"d/c:unspec:".$HN."_blech" => [ undef, undef, $HN."_blech", [$HN."_blech"] ], +#"d/c:unspec:blech" => [ undef, undef, "blech", ["blech"] ], +"0:unspec:blech" => [ 0, undef, "blech", ["blech"] ], +"1:unspec:blech" => [ 1, undef, "blech", ["blech"] ], +# +# X | "foo" | "bar" | Exactly one profile where the +# host's name is "bar". +#"d/c:$HN:".$HN."_blech" => [ undef, $HN, $HN."_blech", [$HN."_blech"] ], +#"d/c:$HN:blech" => [ undef, $HN, "blech", ["blech"] ], +"0:$HN:blech" => [ 0, $HN, "blech", ["blech"] ], +"1:$HN:blech" => [ 1, $HN, "blech", ["blech"] ], +}; + + +sub do_test { + # pass in undef for 'unspec' in the table + my ($dda, $endpointhost, $hior) = @_; + $dda = 0 if (!defined($dda)); + $endpointhost = '' if (!defined($endpointhost)); + $hior_opt = ($hior ne '') ? "/hostname_in_ior=$hior" : ''; + + my $command = "generate_ior " . + "-ORBDottedDecimalAddresses $dda " . + "-ORBendpoint iiop://$endpointhost".$hior_opt; + + my @profiles; + my $line; +# print "$command\n"; + open (PIOR, "$command | catior -x 2>&1 |") + || die "Unable to exec generate_ior: $!\n"; +# print "XXX: $_" while (<PIOR>); + while ($line = <PIOR>) { + # Need to look for the following lines: + # Host Name: <ipaddr_or_host> + # and + # endpoint: <ipaddr_or_host>:<portnum> + chomp $line; + my $x; +# print "Looking at $line\n"; + if ($line =~ /.*Host Name:\s+(.+)$/) { + chomp($x = $1); +# print "HN pushing $x\n"; + push @profiles, $x; + } + elsif ($line =~ /.*endpoint: ([^:]+):.*/) { + chomp($x = $1); +# print "EP pushing $x\n"; + push @profiles, $x; + } + } + close (PIOR); + + return @profiles; +} + + +# Usage: +# $are_equal = compare_arrays(\@frogs, \@toads); +sub compare_arrays { + my ($first, $second) = @_; + no warnings; # silence spurious -w undef complaints + return 0 unless @$first == @$second; + @sorted_first = sort @$first; + @sorted_second = sort @$second; + $first = \@sorted_first; + $second = \@sorted_second; + for (my $i = 0; $i < @$first; $i++) { + return 0 if $first->[$i] ne $second->[$i]; + } + return 1; +} + + +sub print_profiles { + my ($test_info, $profiles_a) = @_; + + print "$test_info: ", join(' ', @$profiles_a), "\n"; +} + +sub check_profiles { + my ($test_info, $found_profiles, $expected_profiles) = @_; +# &print_profiles($test_info, $profiles); + + my $failinfo = []; + # Do number of found profiles match expected? + if ($#$found_profiles != $#$expected_profiles) { + push @$failinfo, "(num IOR profiles[$#$found_profiles] != expected[$#$expected_profiles]"; + } + + # Really need to compare these as hashes to avoid ordering issues. + if (compare_arrays ($found_profiles, $expected_profiles) == 0) { + push @$failinfo, "(profiles in IOR != profiles expected)"; + push @$failinfo, "Found profiles (".join(',', @$found_profiles).")"; + } + + return $failinfo; +} + +# Brute force implementation of each of the lines in the table above + +format STDOUT_TOP = + | | -ORBendpoint | | Expected +FAIL? | DDA | hostspec | hostname_in_ior | Profile(s) in IOR +=============================================================================== +. +format STDOUT = +@<<< | @|| | @<<<<<<<<<<<<<<<<<< | @<<<<<<<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<< +$pf, $dda, $endpointhost, $hior, $expected_prof_in_ior +~~ | | | | ^<<<<<<<<<<<<<<<<<<< + $expected_prof_in_ior +~ | Details: ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + $detail +~~ | | ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + $detail + +-----+---------------------+----------------------+--------------------- +. + +$: = ', '; +for $test (sort keys %$TEST_DATA) { + my $testargs = $TEST_DATA->{$test}; + my @p = &do_test ($testargs->[0], $testargs->[1], $testargs->[2]); + my $failinfo = &check_profiles ($test, \@p, $TEST_DATA->{$test}[3]); + + # Set up all the global vars so we can write our output + ($dda, $endpointhost, $hior) = split(':', $test); + $expected_prof_in_ior = join(',', @{$TEST_DATA->{$test}[3]}); + if ($#$failinfo != -1) { + $pf = 'FAIL'; + $detail = join("\r", @$failinfo); + } + else { + $pf = $detail = ''; + } + + write; +} +exit; +@p = &do_test(0, undef, undef); +&check_profiles("0 unspec unspec", \@p, \@HOSTNAMES); + +@p = &do_test(1, undef, undef); +&check_profiles("1 unspec unspec", \@p, \@IPADDRS); + +@p = &do_test(0, hostname, undef); +&check_profiles("0 ".hostname." undef", \@p, [hostname]); + +@p = &do_test(1, hostname, undef); +&check_profiles("1 ".hostname." undef", \@p, [ inet_ntoa((gethostbyname(hostname))[4]) ] ); + +@p = &do_test(undef, undef, hostname . "_blech"); +&check_profiles("undef undef ".hostname."_blech", \@p, [hostname."_blech"]); + +@p = &do_test(undef, hostname, hostname."_blech"); +&check_profiles("undef ".hostname." ".hostname."_blech", \@p, [hostname."_blech"]); diff --git a/TAO/utils/catior/catior.cpp b/TAO/utils/catior/catior.cpp index 79ca6577e8d..c0e1116e37b 100644 --- a/TAO/utils/catior/catior.cpp +++ b/TAO/utils/catior/catior.cpp @@ -466,7 +466,7 @@ ACE_TMAIN (int argcw, ACE_TCHAR *argvw[]) int opt; ACE_Get_Opt get_opt (argcon.get_argc (), argcon.get_TCHAR_argv (), - ACE_TEXT ("f:n:")); + ACE_TEXT ("f:n:x")); while ((opt = get_opt ()) != EOF) { @@ -598,7 +598,117 @@ ACE_TMAIN (int argcw, ACE_TCHAR *argvw[]) ACE_OS::fclose (ifstr); #endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */ } - break; + break; + case 'x': + { + // Read the file into a CORBA::String_var. + ACE_DEBUG ((LM_DEBUG, + "reading from stdin\n")); + +#if !defined (ACE_LACKS_IOSTREAM_TOTALLY) + if (!cin.good ()) + { + return -1; + } + + int have_some_input = 0; + while (!cin.eof()) + { + char ch; + ACE_CString aString; + + while (!cin.eof ()) + { + cin.get (ch); + if (ch == '\n' || cin.eof ()) + break; + aString += ch; + have_some_input = 1; + } +#else + FILE* ifstr = stdin; + + if (ifstr && !ferror (ifstr)) + { + if (ifstr) + ACE_OS::fclose (ifstr); + return -1; + } + + int have_some_input = 0; + while (!feof (ifstr)) + { + char ch; + ACE_CString aString; + + while (!feof (ifstr)) + { + ch = ACE_OS::fgetc (ifstr); + if (ch == '\n' || ch == EOF) + break; + aString += ch; + have_some_input = 1; + } +#endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */ + + if (have_some_input == 0) + break; + ACE_DEBUG ((LM_DEBUG, + "\nhere is the IOR\n%s\n\n", + aString.rep ())); + + char* str; + if (aString.find ("IOR:") == 0) + { + ACE_DEBUG ((LM_DEBUG, + "decoding an IOR:\n")); + + // Strip the IOR: off the string. + ACE_CString prefix = "IOR:"; + size_t prefixLength = prefix.length (); + + ACE_CString subString = + aString.substring (prefixLength, + aString.length () - prefixLength); + subString[subString.length ()] = '\0'; + str = subString.rep (); + b = catior (str ACE_ENV_ARG_PARAMETER); + } + else if (aString.find ("iiop:") == 0) + { + ACE_DEBUG ((LM_DEBUG, + "decoding an IIOP URL IOR\n")); + + ACE_CString prefix = "IIOP:"; + size_t prefixLength = prefix.length (); + + ACE_CString subString = + aString.substring (prefixLength, + aString.length () - prefixLength); + //subString[subString.length () - 1] = '\0'; + str = subString.rep (); + b = catiiop (str ACE_ENV_ARG_PARAMETER); + } + else if (aString.find (":IR:") > 0) + { + ACE_DEBUG ((LM_DEBUG, + "decoding an POOP IOR\n")); + + str = aString.rep (); + b = catpoop (str ACE_ENV_ARG_PARAMETER); + } + else + ACE_ERROR ((LM_ERROR, + "Don't know how to decode this IOR\n")); + } + if (b == 1) + ACE_DEBUG ((LM_DEBUG, + "catior returned true\n")); + else + ACE_DEBUG ((LM_DEBUG, + "catior returned false\n")); + } + break; case '?': case 'h': default: |