add library to override addresses
This commit is contained in:
44
build/files/addr_aliases.c
Normal file
44
build/files/addr_aliases.c
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user