Getting ircII to honor the IRCUSER environment variable
I just recently had a problem with getting an ircII client install under a unix shell account a friend gave me to honor the IRCUSER environment variable.
mainly I wanted my username in the host part of the whois information to be different than the shell account users name. ircII-epic4 allowes you to change this with the IRCUSER envrionment variable, but plain ircII just calls the
getpwuid function with your user id as the argument and extracts the text of your users name from the password file from the passwd struct that it returns.
So it's been a while since I did a library that preloads in custom functions to replace the standard ones and I had a go at it. this is the result and it works great. Ive only tested this under Solaris though so I'm not sure if it will run on Linux but im sure it can be made to work ok with some mods to adapt to the linux runtime linker.
heres the source to fakeuser.c you can compile it with cc -O -KPIC -G -o fakeuser.so fakeuser.c
if you have the Forte C compiler (Sun Studio) not sure what the gcc syntax is but its whatever syntax is needed to make gcc compile a shared library.
#include <stdio.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include <assert.h>
#include <stdlib.h>
#include <pwd.h>
static struct passwd *(*real_getpwuid)(uid_t);
/* Look up the real getpwuid() symbol at start-up. */
#pragma init (startup)
void startup(void) {
real_getpwuid = (struct passwd *(*)(uid_t)) dlsym(RTLD_NEXT, "getpwuid");
assert(real_getpwuid != 0);
}
struct passwd *getpwuid(uid_t uid) {
struct passwd *pwd;
char *fakeuser = getenv("IRCUSER");
pwd = real_getpwuid(uid);
if (fakeuser != NULL)
pwd->pw_name = fakeuser;
return pwd;
}
Once you have fakeuser.so you just set the IRCUSER environment variable to the username you want and and make sure you set LD_PRELOAD to the full path to fakeuser.so like for example export LD_PRELOAD=$HOME/fakeuser.so
then just execute ircII or if you just want a quick test just run the id command to see it report the fake username instead of your real one.
