[PATCH] New ORB_init option "ORBNetID=<string>"



Hi,

Remote ORBs might not be able to resolve object references generated by
ORBit2. The reason is that the short form of the hostname generally is
used. 

An example: 

* Imagine a host with the FQDN "thor.test.com" and the IP address
"10.0.3.2". ior-decode-2 will show that any locally generated IOR
resolves to "thor"

This will necessitate DNS or host configuration changes. It is therefore
necessary to introduce a new ORB_init option to control how host
resolvable names are generated by ORBit2.

The patch below introduces the ORB_init option "ORBNetID". The argument
is a string. The value of ORBLocalOnly will always take precedence to
preserve compatibility with current applications.

Possible values of ORBNetID is:

"local": all attempts to resolve the local host will be done using "localhost"
"short": all attempts to resolve the local host will be done using "thor".
"fqdn" : all attempts to resolve the local host will be done using "thor.test.com".
"ipaddr: all attempts to resolve the local host will be done using "10.0.3.2".

Patch against CVS HEAD below. Tested on Gentoo 2005.0 AMD64.

Please review. I'll commit in a week or so if no-one objects. 

Best regards,
  jules




? depcomp
? gtk-doc.make
? orbit2-zip
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/ORBit2/ChangeLog,v
retrieving revision 1.715
diff -u -p -r1.715 ChangeLog
--- ChangeLog	2 Jul 2005 11:55:24 -0000	1.715
+++ ChangeLog	25 Jul 2005 00:46:01 -0000
@@ -1,3 +1,14 @@
+2005-07-25  Jules Colding  <colding omesc com>
+
+	* src/orb/orb-core/corba-orb.c: Added new ORB_init option, ORBNetID.
+	Valid values for a hypothetical local host (FQDN:thor.test.com, IP:10.0.3.2):
+	   "local": all attempts to resolve the local host will be done using "localhost"
+	   "short": all attempts to resolve the local host will be done using "thor".
+	   "fqdn" : all attempts to resolve the local host will be done using "thor.test.com".
+	   "ipaddr: all attempts to resolve the local host will be done using "10.0.3.2".
+	The new option will be evaluated after ORBLocalOnly but ORBLocalOnly will always take
+	precedence.
+
 2005-06-20  Fernando Herrera  <fherrera onirica com>
 
 	* include/orbit/orb-core/corba-orb-type.h:
Index: linc2/ChangeLog
===================================================================
RCS file: /cvs/gnome/ORBit2/linc2/ChangeLog,v
retrieving revision 1.243
diff -u -p -r1.243 ChangeLog
--- linc2/ChangeLog	8 Jul 2005 22:59:57 -0000	1.243
+++ linc2/ChangeLog	25 Jul 2005 00:46:02 -0000
@@ -1,3 +1,19 @@
+2005-07-25  Jules Colding  <colding omesc com>
+
+	* src/linc-protocols.c (get_netid): New function get_netid(). This 
+	function will full a preallocated buffer with a string describing 
+	the name of the local host according to the value of use_local_host.
+
+	link_get_local_hostname(): Modified to produce a resolvable hostname 
+	according to the value of use_local_host. This hostname will be used 
+	when composing IORs. 
+
+	use_local_host: Defaults now to LINK_NET_ID_IS_IPADDR fopr maximum
+	resolvability.
+
+	* include/linc/linc-protocol.h: Added new enum type "LinkNetIdType" to
+	use as argument in link_use_local_hostname().
+
 2005-07-09  Sebastian Rittau  <srittau jroger in-berlin de>
 
 	* src/cleanup.c: (main): Use g_get_tmpdir() instead of hardcoding
Index: linc2/include/linc/linc-protocol.h
===================================================================
RCS file: /cvs/gnome/ORBit2/linc2/include/linc/linc-protocol.h,v
retrieving revision 1.21
diff -u -p -r1.21 linc-protocol.h
--- linc2/include/linc/linc-protocol.h	14 Apr 2005 13:00:26 -0000	1.21
+++ linc2/include/linc/linc-protocol.h	25 Jul 2005 00:46:02 -0000
@@ -70,12 +70,20 @@ struct _LinkProtocolInfo {
 	gpointer                    dummy[8];
 };
 
+typedef enum {
+	LINK_NET_ID_IS_LOCAL,
+	LINK_NET_ID_IS_SHORT_HOSTNAME,
+	LINK_NET_ID_IS_FQDN,
+	LINK_NET_ID_IS_IPADDR
+} LinkNetIdType;
+
+
 LinkProtocolInfo * const link_protocol_find     (const char *name);
 LinkProtocolInfo * const link_protocol_find_num (const int   family);
 LinkProtocolInfo * const link_protocol_all      (void);
 char                    *link_get_tmpdir        (void);
 void                     link_set_tmpdir        (const char *dir);
-void                     link_use_local_hostname (gboolean use);
+void                     link_use_local_hostname (LinkNetIdType use);
 const char*              link_get_local_hostname (void);
 
 G_END_DECLS
Index: linc2/src/linc-protocols.c
===================================================================
RCS file: /cvs/gnome/ORBit2/linc2/src/linc-protocols.c,v
retrieving revision 1.67
diff -u -p -r1.67 linc-protocols.c
--- linc2/src/linc-protocols.c	13 Apr 2005 11:40:07 -0000	1.67
+++ linc2/src/linc-protocols.c	25 Jul 2005 00:46:02 -0000
@@ -19,10 +19,13 @@
 
 #include <glib/gstdio.h>
 
+#include <net/if.h>
+#include <sys/ioctl.h>
+
 #undef LOCAL_DEBUG
 
 static char *link_tmpdir = NULL;
-static gboolean use_local_host = FALSE;
+static LinkNetIdType use_local_host = LINK_NET_ID_IS_IPADDR;
 
 /*
  * make_local_tmpdir:
@@ -124,22 +127,90 @@ link_get_tmpdir (void)
 #define LINK_RESOLV_UNSET_IPV6
 #endif
 
+static char *
+get_netid(LinkNetIdType which, 
+	  char *buf, 
+	  size_t len)
+{
+	if (LINK_NET_ID_IS_LOCAL == which)
+		return strncpy(buf, "localhost", len);
+
+	if (LINK_NET_ID_IS_IPADDR == which) {
+		struct ifreq my_ifreqs[2];
+		struct ifconf my_ifconf;
+		my_ifconf.ifc_len = sizeof(my_ifreqs);
+		my_ifconf.ifc_req = my_ifreqs;
+		int sock = socket(AF_INET,SOCK_DGRAM,0);
+		if (-1 == sock) 
+			goto out;;
+
+		if (ioctl(sock,SIOCGIFCONF,&my_ifconf) < 0) {
+			close(sock);
+			goto out;;
+		}
+		close(sock);
+
+		int num = my_ifconf.ifc_len / sizeof(struct ifreq);
+		if (!num) 
+			goto out;
+
+		int i;
+		struct sockaddr_in *adr = NULL;
+ 		for (i = 0; i < num; i++) {
+			adr = (struct sockaddr_in *)&my_ifreqs[i].ifr_ifru.ifru_addr;
+			if (strcmp("127.0.0.1", inet_ntoa((struct in_addr)adr->sin_addr)))
+				break;
+		}
+		// will be 127.0.0.1 anyway, if no other address is defined...
+		return strncpy(buf, (const char*)inet_ntoa((struct in_addr)adr->sin_addr), len);
+	}
+
+	if ((LINK_NET_ID_IS_SHORT_HOSTNAME == which) || (LINK_NET_ID_IS_FQDN == which)) {
+		if (gethostname(buf, len))
+			goto out;
+		if (errno == EINVAL)
+			goto out;
+
+		if (LINK_NET_ID_IS_SHORT_HOSTNAME == which) {
+			char *retv = buf;
+			while (*buf) {
+				if ('.' == *buf)
+					*buf = '\0';
+				buf++;
+			}
+			return retv;
+		}
+	}
+
+	if (LINK_NET_ID_IS_FQDN == which) {
+		struct addrinfo *result, hints;
+		memset(&hints, 0, sizeof(struct addrinfo));
+		hints.ai_flags = AI_CANONNAME;
+		if (!getaddrinfo(buf, NULL, &hints, &result)) {
+			strncpy(buf, result->ai_canonname, len);
+			freeaddrinfo(result);
+		} else
+			goto out;
+
+		return buf;
+	}
+
+out:
+	return NULL;
+}
 
 
 #if defined(AF_INET) || defined(AF_INET6) || defined (AF_UNIX)
 const char *
 link_get_local_hostname (void)
 {
-	static char local_host[NI_MAXHOST] = { 0 };
+	static char local_host[HOST_NAME_MAX] = { 0 };
 
-	if (use_local_host)
-		return "localhost";
-
-	if (local_host [0])
+	if (local_host[0])
 		return local_host;
 
-	if (gethostname (local_host, NI_MAXHOST) == -1)
-		return NULL;
+	get_netid(use_local_host, local_host, HOST_NAME_MAX);
+
 #ifdef G_OS_WIN32
 	{
 		/* Make sure looking up that name works */
@@ -166,7 +237,7 @@ link_get_local_hostname (void)
 }
 
 void
-link_use_local_hostname (gboolean use)
+link_use_local_hostname (LinkNetIdType use)
 {
         use_local_host = use;
 }
Index: src/orb/orb-core/corba-orb.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/orb-core/corba-orb.c,v
retrieving revision 1.112
diff -u -p -r1.112 corba-orb.c
--- src/orb/orb-core/corba-orb.c	2 Jul 2005 11:55:25 -0000	1.112
+++ src/orb/orb-core/corba-orb.c	25 Jul 2005 00:46:03 -0000
@@ -49,6 +49,7 @@ static gboolean     orbit_use_irda      
 static gboolean     orbit_use_ssl            = FALSE;
 static gboolean     orbit_use_genuid_simple  = FALSE;
 static gboolean     orbit_local_only         = FALSE;
+static char        *orbit_net_id             = NULL;
 static gboolean     orbit_use_http_iors      = FALSE;
 static char        *orbit_ipsock             = NULL;
 static char        *orbit_ipname             = NULL;
@@ -74,8 +75,28 @@ ORBit_ORB_start_servers (CORBA_ORB orb)
 		create_options |= LINK_CONNECTION_LOCAL_ONLY;
 
 	if (orbit_local_only || (orbit_use_usocks && !(orbit_use_ipv4 || orbit_use_ipv6 || orbit_use_irda || orbit_use_ssl)))
-			link_use_local_hostname (TRUE);
-
+			link_use_local_hostname (LINK_NET_ID_IS_LOCAL);
+	else {
+		do {
+			if (!strcmp(orbit_net_id, "local")) {
+				link_use_local_hostname (LINK_NET_ID_IS_LOCAL);
+				break;
+			}
+			if (!strcmp(orbit_net_id, "short")) {
+				link_use_local_hostname (LINK_NET_ID_IS_SHORT_HOSTNAME);
+				break;
+			}
+			if (!strcmp(orbit_net_id, "fqdn")) {
+				link_use_local_hostname (LINK_NET_ID_IS_FQDN);
+				break;
+			}
+			if (!strcmp(orbit_net_id, "ipaddr")) {
+				link_use_local_hostname (LINK_NET_ID_IS_IPADDR);
+				break;
+			}
+		} while (0);
+	}
+		    
 	for (info = link_protocol_all (); info->name; info++) {
 		GIOPServer           *server;
 
@@ -1363,6 +1384,7 @@ const ORBit_option orbit_supported_optio
  	{ "ORBIIOPIPSock",      ORBIT_OPTION_STRING,  &orbit_ipsock },
 	{ "ORBInitialMsgLimit", ORBIT_OPTION_INT,     &orbit_initial_recv_limit },
 	{ "ORBLocalOnly",       ORBIT_OPTION_BOOLEAN, &orbit_local_only },
+ 	{ "ORBNetID",           ORBIT_OPTION_STRING,  &orbit_net_id },
 	/* warning: this option is a security risk unless used with LocalOnly */
 	{ "ORBIIOPIPv4",        ORBIT_OPTION_BOOLEAN, &orbit_use_ipv4 },
 	{ "ORBIIOPIPv6",        ORBIT_OPTION_BOOLEAN, &orbit_use_ipv6 },




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]