
The MPL 2.0 license is a "file-level" copyleft license vs the "project-level" nature of the L/GPL. The intention of noVNC has always been that it should be easy to incorporate into existing projects and sites whether free/open or proprietary/commercial. The MPL 2.0 is designed for this sort of combination project but still requires that any distributed modifications to noVNC source files must also be published under the same license. In addition, the MPL 2.0 allows the code to be used in L/GPL projects (the secondary license clause). This means that any projects that are already incorporating noVNC should not be impacted by this change and in fact it should clarify the licensing situation (the exact application of the L/GPL to web applications and interpreted code is somewhat ambiguous). The HTML, CSS, image and font files continue to be under more permissive licenses (see LICENSE.txt). The included websockify python code remains under a LGPLv3 license although the include/websock.js file from the websockify component is now under MPL 2.0 as well. Permission was received from other noVNC authors to make this change to their code license on the following dates: - Chris Gordon (UI): Jun 24, 2012 - Antoine Mercadal (DOM,*util.js): Oct 10, 2012 - William Lightning (UltraVNC repeater): Oct 10, 2012 - Mike Tinglof (tight encoding): Oct 15, 2012
95 lines
2.8 KiB
C
95 lines
2.8 KiB
C
/*
|
|
* rebind: Intercept bind calls and bind to a different port
|
|
* Copyright 2010 Joel Martin
|
|
* Licensed under MPL-2.0 (see docs/LICENSE.MPL-2.0)
|
|
*
|
|
* Overload (LD_PRELOAD) bind system call. If REBIND_PORT_OLD and
|
|
* REBIND_PORT_NEW environment variables are set then bind on the new
|
|
* port (of localhost) instead of the old port.
|
|
*
|
|
* This allows a proxy (such as wsproxy) to run on the old port and translate
|
|
* traffic to/from the new port.
|
|
*
|
|
* Usage:
|
|
* LD_PRELOAD=./rebind.so \
|
|
* REBIND_PORT_OLD=23 \
|
|
* REBIND_PORT_NEW=2023 \
|
|
* program
|
|
*/
|
|
|
|
//#define DO_DEBUG 1
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define __USE_GNU 1 // Pull in RTLD_NEXT
|
|
#include <dlfcn.h>
|
|
|
|
#include <string.h>
|
|
#include <netinet/in.h>
|
|
|
|
|
|
#if defined(DO_DEBUG)
|
|
#define DEBUG(...) \
|
|
fprintf(stderr, "wswrapper: "); \
|
|
fprintf(stderr, __VA_ARGS__);
|
|
#else
|
|
#define DEBUG(...)
|
|
#endif
|
|
|
|
|
|
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
|
|
{
|
|
static void * (*func)();
|
|
int do_move = 0;
|
|
struct sockaddr_in * addr_in = (struct sockaddr_in *)addr;
|
|
struct sockaddr_in addr_tmp;
|
|
socklen_t addrlen_tmp;
|
|
char * PORT_OLD, * PORT_NEW, * end1, * end2;
|
|
int ret, oldport, newport, askport = htons(addr_in->sin_port);
|
|
uint32_t askaddr = htons(addr_in->sin_addr.s_addr);
|
|
if (!func) func = (void *(*)()) dlsym(RTLD_NEXT, "bind");
|
|
|
|
DEBUG(">> bind(%d, _, %d), askaddr %d, askport %d\n",
|
|
sockfd, addrlen, askaddr, askport);
|
|
|
|
/* Determine if we should move this socket */
|
|
if (addr_in->sin_family == AF_INET) {
|
|
// TODO: support IPv6
|
|
PORT_OLD = getenv("REBIND_OLD_PORT");
|
|
PORT_NEW = getenv("REBIND_NEW_PORT");
|
|
if (PORT_OLD && (*PORT_OLD != '\0') &&
|
|
PORT_NEW && (*PORT_NEW != '\0')) {
|
|
oldport = strtol(PORT_OLD, &end1, 10);
|
|
newport = strtol(PORT_NEW, &end2, 10);
|
|
if (oldport && (*end1 == '\0') &&
|
|
newport && (*end2 == '\0') &&
|
|
(oldport == askport)) {
|
|
do_move = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (! do_move) {
|
|
/* Just pass everything right through to the real bind */
|
|
ret = (int) func(sockfd, addr, addrlen);
|
|
DEBUG("<< bind(%d, _, %d) ret %d\n", sockfd, addrlen, ret);
|
|
return ret;
|
|
}
|
|
|
|
DEBUG("binding fd %d on localhost:%d instead of 0x%x:%d\n",
|
|
sockfd, newport, ntohl(addr_in->sin_addr.s_addr), oldport);
|
|
|
|
/* Use a temporary location for the new address information */
|
|
addrlen_tmp = sizeof(addr_tmp);
|
|
memcpy(&addr_tmp, addr, addrlen_tmp);
|
|
|
|
/* Bind to other port on the loopback instead */
|
|
addr_tmp.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
|
addr_tmp.sin_port = htons(newport);
|
|
ret = (int) func(sockfd, &addr_tmp, addrlen_tmp);
|
|
|
|
DEBUG("<< bind(%d, _, %d) ret %d\n", sockfd, addrlen, ret);
|
|
return ret;
|
|
}
|