add library to override addresses

This commit is contained in:
2016-05-19 22:05:25 +01:00
parent c9ee4af3a3
commit 0f1569663c
3 changed files with 53 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
#include <resolv.h>
#include <netdb.h>
#define __USE_GNU
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char* getfield(char* line, int num) {
char* tmp = strdup(line);
const char* tok;
for (tok = strtok(tmp, " ");
tok && *tok;
tok = strtok(NULL, " ")) {
if (--num < 0) {
return strdup(tok);
}
}
return NULL;
}
int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
FILE* stream = fopen("/host/etc/addr_aliases", "r");
char line[1024];
while (fgets(line, 1024, stream)) {
const char* host_from = getfield(line, 0);
const char* port_from = getfield(line, 1);
const char* host_to = getfield(line, 2);
const char* port_to = getfield(line, 3);
if (strcmp(node, host_from) == 0 && strcmp(service, port_from) == 0) {
fprintf(stderr, "%s:%s => %s:%s\n", host_from, port_from, host_to, port_to);
node = host_to;
service = host_to;
}
}
if (res_init () < 0) {
return EAI_SYSTEM;
} else {
int (*f)() = dlsym (RTLD_NEXT, "getaddrinfo");
return f(node, service, hints, res);
}
}

View File

@@ -1,4 +1,5 @@
csync: base sshd compile csync: base sshd compile
$(call aux,addr_aliases.c)
$(call script,$@) $(call script,$@)
$(call runit,xinetd) $(call runit,xinetd)
$(call runit,lsyncd) $(call runit,lsyncd)

View File

@@ -19,6 +19,14 @@ make
make install make install
make cert make cert
## Address aliases
cd /opt
mv /addr_aliases.c .
gcc -fPIC -shared -o addr_aliases.so addr_aliases.c
mkdir -p /host/etc/
touch /host/etc/addr_aliases
echo /opt/addr_aliases.so >> /etc/ld.so.preload
## Xinetd ## Xinetd
apt_install_permanent xinetd apt_install_permanent xinetd
@@ -39,8 +47,6 @@ echo "csync2 30865/tcp" >> /etc/services
## Lsyncd dependencies ## Lsyncd dependencies
apt_install_permanent lua5.2 liblua5.2-dev bash-completion apt_install_permanent lua5.2 liblua5.2-dev bash-completion
ln -s /usr/share/bash-completion/completions/a2x /usr/bin/a2x
chmod +x /usr/bin/a2x
## Lsyncd ## Lsyncd
cd /opt cd /opt