Commit c95743eb authored by Jonh Wendell's avatar Jonh Wendell
Browse files

Add reverse-vnc plugin

Moved this feature from vnc plugin into its own.
parent d7802c86
......@@ -311,6 +311,7 @@ plugins/Makefile
plugins/vnc/Makefile
plugins/ssh/Makefile
plugins/rdp/Makefile
plugins/reverse-vnc/Makefile
vinagre/Makefile
vinagre/view/Makefile
])
......
DIST_SUBDIRS = \
vnc \
ssh \
rdp
rdp \
reverse-vnc
SUBDIRS = \
vnc
SUBDIRS = vnc reverse-vnc
if SSH
SUBDIRS += ssh
......
# reverse-vnc plugin
plugindir = $(VINAGRE_PLUGINS_LIBS_DIR)
INCLUDES = \
-DDATADIR=\"$(VINAGRE_PLUGINS_DATA_DIR)/reverse-vnc\" \
-I$(top_srcdir) \
$(VINAGRE_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS)
plugin_LTLIBRARIES = libreversevnc.la
libreversevnc_la_SOURCES = \
vinagre-reverse-vnc-plugin.h vinagre-reverse-vnc-plugin.c \
vinagre-reverse-vnc-listener.h vinagre-reverse-vnc-listener.c \
vinagre-reverse-vnc-listener-dialog.h vinagre-reverse-vnc-listener-dialog.c
if SELF_IFADDRS
libreversevnc_la_SOURCES += if/ifaddrs.h if/getifaddrs.c
endif
libreversevnc_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
libreversevnc_la_LIBADD = $(VNC_LIBS)
uidir = $(VINAGRE_PLUGINS_DATA_DIR)/reverse-vnc
ui_DATA = reverse-vnc.ui
plugin_in_files = reverse-vnc.vinagre-plugin.desktop.in
reverse-vnc.vinagre-plugin: reverse-vnc.vinagre-plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
plugin_DATA = $(plugin_in_files:.vinagre-plugin.desktop.in=.vinagre-plugin)
EXTRA_DIST = $(ui_DATA) $(plugin_in_files)
CLEANFILES = $(plugin_DATA)
DISTCLEANFILES = $(plugin_DATA)
-include $(top_srcdir)/git.mk
/*
* Copyright (c) 2006 WIDE Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/sockio.h>
#include <sys/socket.h>
#include <net/if.h>
#include "ifaddrs.h"
static int
get_lifreq(int fd, struct lifreq **ifr_ret)
{
struct lifnum lifn;
struct lifconf lifc;
struct lifreq *lifrp;
lifn.lifn_family = AF_UNSPEC;
lifn.lifn_flags = 0;
if (ioctl(fd, SIOCGLIFNUM, &lifn) == -1)
lifn.lifn_count = 16;
else
lifn.lifn_count += 16;
for (;;) {
lifc.lifc_len = lifn.lifn_count * sizeof (*lifrp);
lifrp = malloc(lifc.lifc_len);
if (lifrp == NULL)
return (-1);
lifc.lifc_family = AF_UNSPEC;
lifc.lifc_flags = 0;
lifc.lifc_buf = (char *)lifrp;
if (ioctl(fd, SIOCGLIFCONF, &lifc) == -1) {
free(lifrp);
if (errno == EINVAL) {
lifn.lifn_count <<= 1;
continue;
}
(void) close(fd);
return (-1);
}
if (lifc.lifc_len < (lifn.lifn_count - 1) * sizeof (*lifrp))
break;
free(lifrp);
lifn.lifn_count <<= 1;
}
*ifr_ret = lifrp;
return (lifc.lifc_len / sizeof (*lifrp));
}
static size_t
nbytes(const struct lifreq *lifrp, int nlif, size_t socklen)
{
size_t len = 0;
size_t slen;
while (nlif > 0) {
slen = strlen(lifrp->lifr_name) + 1;
len += sizeof (struct ifaddrs) + ((slen + 3) & ~3);
len += 3 * socklen;
lifrp++;
nlif--;
}
return (len);
}
static struct sockaddr *
addrcpy(struct sockaddr_storage *addr, char **bufp)
{
char *buf = *bufp;
size_t len;
len = addr->ss_family == AF_INET ? sizeof (struct sockaddr_in) :
sizeof (struct sockaddr_in6);
(void) memcpy(buf, addr, len);
*bufp = buf + len;
return ((struct sockaddr *)buf);
}
static int
populate(struct ifaddrs *ifa, int fd, struct lifreq *lifrp, int nlif, int af,
char **bufp)
{
char *buf = *bufp;
size_t slen;
while (nlif > 0) {
ifa->ifa_next = (nlif > 1) ? ifa + 1 : NULL;
(void) strcpy(ifa->ifa_name = buf, lifrp->lifr_name);
slen = strlen(lifrp->lifr_name) + 1;
buf += (slen + 3) & ~3;
if (ioctl(fd, SIOCGLIFFLAGS, lifrp) == -1)
ifa->ifa_flags = 0;
else
ifa->ifa_flags = lifrp->lifr_flags;
if (ioctl(fd, SIOCGLIFADDR, lifrp) == -1)
ifa->ifa_addr = NULL;
else
ifa->ifa_addr = addrcpy(&lifrp->lifr_addr, &buf);
if (ioctl(fd, SIOCGLIFNETMASK, lifrp) == -1)
ifa->ifa_netmask = NULL;
else
ifa->ifa_netmask = addrcpy(&lifrp->lifr_addr, &buf);
if (ifa->ifa_flags & IFF_POINTOPOINT) {
if (ioctl(fd, SIOCGLIFDSTADDR, lifrp) == -1)
ifa->ifa_dstaddr = NULL;
else
ifa->ifa_dstaddr =
addrcpy(&lifrp->lifr_dstaddr, &buf);
} else if (ifa->ifa_flags & IFF_BROADCAST) {
if (ioctl(fd, SIOCGLIFBRDADDR, lifrp) == -1)
ifa->ifa_broadaddr = NULL;
else
ifa->ifa_broadaddr =
addrcpy(&lifrp->lifr_broadaddr, &buf);
} else {
ifa->ifa_dstaddr = NULL;
}
ifa++;
nlif--;
lifrp++;
}
*bufp = buf;
return (0);
}
int
getifaddrs(struct ifaddrs **ifap)
{
int fd4, fd6;
int nif4, nif6 = 0;
struct lifreq *ifr4 = NULL;
struct lifreq *ifr6 = NULL;
struct ifaddrs *ifa = NULL;
char *buf;
if ((fd4 = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
return (-1);
if ((fd6 = socket(AF_INET6, SOCK_DGRAM, 0)) == -1 &&
errno != EAFNOSUPPORT) {
(void) close(fd4);
return (-1);
}
if ((nif4 = get_lifreq(fd4, &ifr4)) == -1 ||
(fd6 != -1 && (nif6 = get_lifreq(fd6, &ifr6)) == -1))
goto failure;
if (nif4 == 0 && nif6 == 0) {
*ifap = NULL;
return (0);
}
ifa = malloc(nbytes(ifr4, nif4, sizeof (struct sockaddr_in)) +
nbytes(ifr6, nif6, sizeof (struct sockaddr_in6)));
if (ifa == NULL)
goto failure;
buf = (char *)(ifa + nif4 + nif6);
if (populate(ifa, fd4, ifr4, nif4, AF_INET, &buf) == -1)
goto failure;
if (nif4 > 0 && nif6 > 0)
ifa[nif4 - 1].ifa_next = ifa + nif4;
if (populate(ifa + nif4, fd6, ifr6, nif6, AF_INET6, &buf) == -1)
goto failure;
*ifap = ifa;
return (0);
failure:
free(ifa);
(void) close(fd4);
if (fd6 != -1)
(void) close(fd6);
free(ifr4);
free(ifr6);
return (-1);
}
void
freeifaddrs(struct ifaddrs *ifa)
{
free(ifa);
}
/*
* Copyright (c) 2006 WIDE Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __IFADDRS_H
#define __IFADDRS_H
#include <sys/types.h>
#undef ifa_broadaddr
#undef ifa_dstaddr
struct ifaddrs {
struct ifaddrs *ifa_next; /* Pointer to next struct */
char *ifa_name; /* Interface name */
uint64_t ifa_flags; /* Interface flags */
struct sockaddr *ifa_addr; /* Interface address */
struct sockaddr *ifa_netmask; /* Interface netmask */
struct sockaddr *ifa_dstaddr; /* P2P interface destination */
};
#define ifa_broadaddr ifa_dstaddr
extern int getifaddrs(struct ifaddrs **);
extern void freeifaddrs(struct ifaddrs *);
#endif
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="listener_dialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Reverse Connections</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="xpad">6</property>
<property name="stock">gtk-dialog-info</property>
<property name="icon-size">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">By activating reverse connections you can access machines that are behind a firewall. The remote side is supposed to initiate the connection with you. For further information, checkout the help.</property>
<property name="wrap">True</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkCheckButton" id="enable_reverse_check">
<property name="label" translatable="yes">_Enable Reverse Connections</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="always_enabled_check">
<property name="label" translatable="yes" comments="Translators: this is the reverse connection mode. &quot;Always enabled&quot; means it will be enabled by default in the program startup. You can see this string in the dialog Machine-&gt;Reverse connections.">_Always Enabled</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkExpander" id="connectivity_exp">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkVBox" id="vbox3">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<child>
<object class="GtkTextView" id="ip_textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="pixels_above_lines">3</property>
<property name="pixels_below_lines">3</property>
<property name="editable">False</property>
<property name="buffer">ip_textbuffer</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">This machine is reachable through the following IP address(es):</property>
<attributes>
<attribute name="style" value="italic"/>
</attributes>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="port_label">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">label</property>
<attributes>
<attribute name="style" value="italic"/>
<attribute name="scale" value="1,000000"/>
</attributes>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes">Connectivity</property>
</object>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="button1">
<property name="label">gtk-help</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-11">button1</action-widget>
<action-widget response="0">button2</action-widget>
</action-widgets>
</object>
<object class="GtkTextBuffer" id="ip_textbuffer"/>
</interface>
[Vinagre Plugin]
Module=reversevnc
IAge=1
_Name=Reverse VNC
_Description=Allows reverse VNC connections
Authors=Jonh Wendell
Copyright=Copyright © 2009-2010 Jonh Wendell
Website=http://www.bani.com.br
Version=1.0
Depends=vnc
/*
* vinagre-reverse-vnc-listener-dialog.c
* This file is part of vinagre
*
* Copyright (C) 2009 Jonh Wendell <wendell@bani.com.br>
*
* 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; either version 2 of the License, or