- perform dns lookup on hostname, - randomize local tunnel port - simple autobuild script - bump rpm spec version --- autobuild.sh | 41 +++++++++++++++++++++++++++++++++++++++++ main.c | 14 +++++--------- ovirt-viewer.spec | 9 ++++++++- tunnel.c | 29 ++++++++++++++++++++--------- 4 files changed, 74 insertions(+), 19 deletions(-) create mode 100755 autobuild.sh diff --git a/autobuild.sh b/autobuild.sh new file mode 100755 index 0000000..a646a83 --- /dev/null +++ b/autobuild.sh @@ -0,0 +1,41 @@ +#!/bin/sh +#oVirt viewer autobuild script +# +# Copyright (C) 2008 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + +echo "Running oVirt viewer Autobuild" + +set -e +set -v + +test -f Makefile && make -k distclean || : + +./autogen.sh +./configure --prefix=$AUTOBUILD_INSTALL_ROOT +make + +if [ -f /usr/bin/rpmbuild ]; then + if [ -n "$AUTOBUILD_COUNTER" ]; then + EXTRA_RELEASE=".auto$AUTOBUILD_COUNTER" + else + NOW=`date +"%s"` + EXTRA_RELEASE=".$USER$NOW" + fi + + rpmbuild --nodeps --define "extra_release $EXTRA_RELEASE" -ba ovirt-viewer.spec +fi diff --git a/main.c b/main.c index 2962f3f..222a9fd 100644 --- a/main.c +++ b/main.c @@ -36,6 +36,8 @@ #include <netinet/in.h> #endif +#include <arpa/inet.h> + #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -903,13 +905,12 @@ viewer_credential (GtkWidget *vnc, GValueArray *credList) gtk_widget_destroy(GTK_WIDGET(dialog)); } -#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) +#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) static int viewer_open_vnc_socket(const char* vnchost, int vncport) { int socketfd; - struct hostent *serv; struct sockaddr_in serv_addr; socketfd = socket(PF_INET, SOCK_STREAM, 0); @@ -917,14 +918,9 @@ viewer_open_vnc_socket(const char* vnchost, int vncport) return -1; } - serv = gethostbyname(vnchost); - if(serv == NULL){ - return -1; - } - serv_addr.sin_family = PF_INET; serv_addr.sin_port = htons(vncport); - serv_addr.sin_addr.s_addr = ((struct in_addr *)(serv->h_addr))->s_addr; + serv_addr.sin_addr.s_addr = inet_addr(vnchost); if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0){ return -1; @@ -933,7 +929,7 @@ viewer_open_vnc_socket(const char* vnchost, int vncport) return socketfd; } -#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) */ +#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) */ /* Remove all menu items from the Connect menu. */ static void diff --git a/ovirt-viewer.spec b/ovirt-viewer.spec index a320ecd..a4d826e 100644 --- a/ovirt-viewer.spec +++ b/ovirt-viewer.spec @@ -2,7 +2,7 @@ Name: ovirt-viewer Version: 1.0.0 -Release: 2%{?dist} +Release: 4%{?dist} Summary: ovirt-viewer is a vnc viewer for ovirt managed vms Group: Applications/System @@ -61,6 +61,13 @@ rm -rf $RPM_BUILD_ROOT %{_bindir}/ovirt-viewer %changelog +* Mon Jun 01 2009 <mmorsi at redhat.com> - 1.0.0-4 +- bugfixes, dns lookup and local tunnel port assignment + +* Wed May 20 2009 <mmorsi at redhat.com> - 1.0.0-3 +- changes to viewer to connect to ovirt server + through vnc proxy + * Thu Apr 30 2009 <mmorsi at redhat.com> - 1.0.0-2 - ssl support, see check-certificate cmd line flag - wire up send key menu diff --git a/tunnel.c b/tunnel.c index a03ef0b..c6d091d 100644 --- a/tunnel.c +++ b/tunnel.c @@ -34,6 +34,7 @@ #include <sys/socket.h> #include <stdlib.h> #include <stdio.h> +#include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> @@ -46,9 +47,6 @@ /* constants */ -// port to try to listen on, if we can't, increment until we find one we can -const int PORT_RANGE_START = 5600; - // max length of a vm name const int VM_NAME_MAX_LEN = 250; @@ -137,6 +135,8 @@ stop_tunnel(void) static gpointer tunnel_thread (gpointer _data) { + struct hostent *dns_serv; + //char vm_data[VM_NAME_MAX_LEN]; int local_server_socketfd, ovirt_server_socket, client_socketfd; unsigned int local_server_len, client_len, ovirt_server_len; @@ -145,6 +145,9 @@ tunnel_thread (gpointer _data) struct sockaddr_in ovirt_server_address; struct sockaddr_in client_address; + struct sockaddr_in local_server_address_lookup; + unsigned int local_server_address_lookup_len = sizeof(local_server_address_lookup); + GThread *client_server_gthread = NULL; GThread *server_client_gthread = NULL; @@ -154,8 +157,13 @@ tunnel_thread (gpointer _data) DEBUG ("tunnel thread starting up"); // ovirt server address + dns_serv = gethostbyname(hostname); + if(dns_serv == NULL){ + DEBUG("ovirt server lookup failed"); + return NULL; + } ovirt_server_address.sin_family = PF_INET; - ovirt_server_address.sin_addr.s_addr = inet_addr(hostname); + ovirt_server_address.sin_addr.s_addr = ((struct in_addr*)(dns_serv->h_addr))->s_addr; //inet_addr(hostname); ovirt_server_address.sin_port = htons(OVIRT_SERVER_PORT); ovirt_server_len = sizeof(ovirt_server_address); @@ -165,18 +173,21 @@ tunnel_thread (gpointer _data) sockets = g_slist_prepend(sockets, c_socket); // local server address - tunnel_port = PORT_RANGE_START; local_server_address.sin_family = PF_INET; local_server_address.sin_addr.s_addr = inet_addr("127.0.0.1"); - local_server_address.sin_port = htons(tunnel_port); + local_server_address.sin_port = 0; local_server_len = sizeof(local_server_address); // increment ports until one is available - while(bind(local_server_socketfd, (struct sockaddr*)&local_server_address, local_server_len) < 0){ - tunnel_port += 1; - local_server_address.sin_port += htons(tunnel_port); + if(bind(local_server_socketfd, (struct sockaddr*)&local_server_address, local_server_len) < 0){ + DEBUG("tunnel bind failed"); + return NULL; } + getsockname(local_server_socketfd, + (struct sockaddr*) &local_server_address_lookup, + &local_server_address_lookup_len); + tunnel_port = (int)ntohs(local_server_address_lookup.sin_port); DEBUG ("tunnel bound to local port %i", tunnel_port); // increase client buffer size? -- 1.6.0.6
- perform dns lookup on hostname, - randomize local tunnel port - bump rpm spec version --- main.c | 14 +++++--------- ovirt-viewer.spec | 9 ++++++++- tunnel.c | 29 ++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index 2962f3f..222a9fd 100644 --- a/main.c +++ b/main.c @@ -36,6 +36,8 @@ #include <netinet/in.h> #endif +#include <arpa/inet.h> + #ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> #endif @@ -903,13 +905,12 @@ viewer_credential (GtkWidget *vnc, GValueArray *credList) gtk_widget_destroy(GTK_WIDGET(dialog)); } -#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) +#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) static int viewer_open_vnc_socket(const char* vnchost, int vncport) { int socketfd; - struct hostent *serv; struct sockaddr_in serv_addr; socketfd = socket(PF_INET, SOCK_STREAM, 0); @@ -917,14 +918,9 @@ viewer_open_vnc_socket(const char* vnchost, int vncport) return -1; } - serv = gethostbyname(vnchost); - if(serv == NULL){ - return -1; - } - serv_addr.sin_family = PF_INET; serv_addr.sin_port = htons(vncport); - serv_addr.sin_addr.s_addr = ((struct in_addr *)(serv->h_addr))->s_addr; + serv_addr.sin_addr.s_addr = inet_addr(vnchost); if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0){ return -1; @@ -933,7 +929,7 @@ viewer_open_vnc_socket(const char* vnchost, int vncport) return socketfd; } -#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) */ +#endif /* defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) */ /* Remove all menu items from the Connect menu. */ static void diff --git a/ovirt-viewer.spec b/ovirt-viewer.spec index a320ecd..a4d826e 100644 --- a/ovirt-viewer.spec +++ b/ovirt-viewer.spec @@ -2,7 +2,7 @@ Name: ovirt-viewer Version: 1.0.0 -Release: 2%{?dist} +Release: 4%{?dist} Summary: ovirt-viewer is a vnc viewer for ovirt managed vms Group: Applications/System @@ -61,6 +61,13 @@ rm -rf $RPM_BUILD_ROOT %{_bindir}/ovirt-viewer %changelog +* Mon Jun 01 2009 <mmorsi at redhat.com> - 1.0.0-4 +- bugfixes, dns lookup and local tunnel port assignment + +* Wed May 20 2009 <mmorsi at redhat.com> - 1.0.0-3 +- changes to viewer to connect to ovirt server + through vnc proxy + * Thu Apr 30 2009 <mmorsi at redhat.com> - 1.0.0-2 - ssl support, see check-certificate cmd line flag - wire up send key menu diff --git a/tunnel.c b/tunnel.c index a03ef0b..c6d091d 100644 --- a/tunnel.c +++ b/tunnel.c @@ -34,6 +34,7 @@ #include <sys/socket.h> #include <stdlib.h> #include <stdio.h> +#include <netdb.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> @@ -46,9 +47,6 @@ /* constants */ -// port to try to listen on, if we can't, increment until we find one we can -const int PORT_RANGE_START = 5600; - // max length of a vm name const int VM_NAME_MAX_LEN = 250; @@ -137,6 +135,8 @@ stop_tunnel(void) static gpointer tunnel_thread (gpointer _data) { + struct hostent *dns_serv; + //char vm_data[VM_NAME_MAX_LEN]; int local_server_socketfd, ovirt_server_socket, client_socketfd; unsigned int local_server_len, client_len, ovirt_server_len; @@ -145,6 +145,9 @@ tunnel_thread (gpointer _data) struct sockaddr_in ovirt_server_address; struct sockaddr_in client_address; + struct sockaddr_in local_server_address_lookup; + unsigned int local_server_address_lookup_len = sizeof(local_server_address_lookup); + GThread *client_server_gthread = NULL; GThread *server_client_gthread = NULL; @@ -154,8 +157,13 @@ tunnel_thread (gpointer _data) DEBUG ("tunnel thread starting up"); // ovirt server address + dns_serv = gethostbyname(hostname); + if(dns_serv == NULL){ + DEBUG("ovirt server lookup failed"); + return NULL; + } ovirt_server_address.sin_family = PF_INET; - ovirt_server_address.sin_addr.s_addr = inet_addr(hostname); + ovirt_server_address.sin_addr.s_addr = ((struct in_addr*)(dns_serv->h_addr))->s_addr; //inet_addr(hostname); ovirt_server_address.sin_port = htons(OVIRT_SERVER_PORT); ovirt_server_len = sizeof(ovirt_server_address); @@ -165,18 +173,21 @@ tunnel_thread (gpointer _data) sockets = g_slist_prepend(sockets, c_socket); // local server address - tunnel_port = PORT_RANGE_START; local_server_address.sin_family = PF_INET; local_server_address.sin_addr.s_addr = inet_addr("127.0.0.1"); - local_server_address.sin_port = htons(tunnel_port); + local_server_address.sin_port = 0; local_server_len = sizeof(local_server_address); // increment ports until one is available - while(bind(local_server_socketfd, (struct sockaddr*)&local_server_address, local_server_len) < 0){ - tunnel_port += 1; - local_server_address.sin_port += htons(tunnel_port); + if(bind(local_server_socketfd, (struct sockaddr*)&local_server_address, local_server_len) < 0){ + DEBUG("tunnel bind failed"); + return NULL; } + getsockname(local_server_socketfd, + (struct sockaddr*) &local_server_address_lookup, + &local_server_address_lookup_len); + tunnel_port = (int)ntohs(local_server_address_lookup.sin_port); DEBUG ("tunnel bound to local port %i", tunnel_port); // increase client buffer size? -- 1.6.0.6
On Mon, Jun 01, 2009 at 11:35:40AM -0400, Mohammed Morsi wrote:> + > +test -f Makefile && make -k distclean || : > + > +./autogen.sh > +./configure --prefix=$AUTOBUILD_INSTALL_ROOTNormally autogen.sh will run configure for you ? If the ovirt-viewer script does, then you can just pass the --prefix arg straight to autogen.sh and script configure> -#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) && defined(HAVE_GETHOSTBYNAME) > +#if defined(HAVE_SOCKET) && defined(HAVE_CONNECT) && defined(HAVE_HTONS) > > static int > viewer_open_vnc_socket(const char* vnchost, int vncport) > { > int socketfd; > - struct hostent *serv; > struct sockaddr_in serv_addr; > > socketfd = socket(PF_INET, SOCK_STREAM, 0); > @@ -917,14 +918,9 @@ viewer_open_vnc_socket(const char* vnchost, int vncport) > return -1; > } > > - serv = gethostbyname(vnchost); > - if(serv == NULL){ > - return -1; > - } > - > serv_addr.sin_family = PF_INET; > serv_addr.sin_port = htons(vncport); > - serv_addr.sin_addr.s_addr = ((struct in_addr *)(serv->h_addr))->s_addr; > + serv_addr.sin_addr.s_addr = inet_addr(vnchost); > > if (connect(socketfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0){ > return -1; > @@ -933,7 +929,7 @@ viewer_open_vnc_socket(const char* vnchost, int vncport) > return socketfd; > }This method should really be re-written to just use getaddrinfo() for lookups. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|