1997-10-26 01:04:02 +00:00
|
|
|
/*
|
|
|
|
* $Id: $
|
|
|
|
*/
|
|
|
|
|
1997-05-26 00:44:10 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
#include <alias.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
1997-05-26 00:44:10 +00:00
|
|
|
#include <stdlib.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <sys/socket.h>
|
1997-05-26 00:44:10 +00:00
|
|
|
#include <unistd.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
#include "command.h"
|
1997-05-26 00:44:10 +00:00
|
|
|
#include "systems.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
|
|
|
|
1997-09-06 11:16:02 +00:00
|
|
|
#define _PATH_ALIAS "/usr/lib/libalias.so." ## __libalias_version
|
1997-05-26 00:44:10 +00:00
|
|
|
|
|
|
|
#define off(item) ((int)&(((struct aliasHandlers *)0)->item))
|
|
|
|
#define entry(a) { off(a), "_" #a }
|
|
|
|
|
|
|
|
static struct {
|
1997-08-25 00:29:32 +00:00
|
|
|
int offset;
|
|
|
|
char *name;
|
1997-05-26 00:44:10 +00:00
|
|
|
} map[] = {
|
1997-08-25 00:29:32 +00:00
|
|
|
entry(PacketAliasGetFragment),
|
|
|
|
entry(PacketAliasInit),
|
|
|
|
entry(PacketAliasIn),
|
|
|
|
entry(PacketAliasOut),
|
|
|
|
entry(PacketAliasRedirectAddr),
|
|
|
|
entry(PacketAliasRedirectPort),
|
|
|
|
entry(PacketAliasSaveFragment),
|
|
|
|
entry(PacketAliasSetAddress),
|
|
|
|
entry(PacketAliasSetMode),
|
|
|
|
entry(PacketAliasFragmentIn),
|
|
|
|
{ 0, 0 }
|
1997-05-26 00:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void *dl;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
int
|
|
|
|
loadAliasHandlers(struct aliasHandlers * h)
|
1997-05-26 00:44:10 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
char *path;
|
|
|
|
char *env;
|
|
|
|
int i;
|
1997-05-26 00:44:10 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
path = _PATH_ALIAS;
|
|
|
|
env = getenv("_PATH_ALIAS");
|
|
|
|
if (env)
|
|
|
|
if (OrigUid() == 0)
|
|
|
|
path = env;
|
|
|
|
else
|
1997-08-31 22:59:49 +00:00
|
|
|
LogPrintf(LogALERT, "Ignoring environment _PATH_ALIAS value (%s)\n", env);
|
1997-05-26 00:44:10 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
dl = dlopen(path, RTLD_LAZY);
|
|
|
|
if (dl == (void *) 0) {
|
|
|
|
LogPrintf(LogWARN, "_PATH_ALIAS (%s): Invalid lib: %s\n",
|
|
|
|
path, dlerror());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; map[i].name; i++) {
|
|
|
|
*(void **) ((char *) h + map[i].offset) = dlsym(dl, map[i].name);
|
|
|
|
if (*(void **) ((char *) h + map[i].offset) == (void *) 0) {
|
|
|
|
LogPrintf(LogWARN, "_PATH_ALIAS (%s): %s: %s\n", path,
|
|
|
|
map[i].name, dlerror());
|
|
|
|
(void) dlclose(dl);
|
|
|
|
dl = (void *) 0;
|
|
|
|
return -1;
|
1997-05-26 00:44:10 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1997-05-26 00:44:10 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
VarPacketAliasInit();
|
1997-05-26 00:44:10 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
return 0;
|
1997-05-26 00:44:10 +00:00
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
void
|
|
|
|
unloadAliasHandlers()
|
1997-05-26 00:44:10 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
if (dl) {
|
|
|
|
dlclose(dl);
|
|
|
|
dl = (void *) 0;
|
|
|
|
}
|
1997-05-26 00:44:10 +00:00
|
|
|
}
|