Wright, Tim (ANTS)
2004-Feb-21 20:12 UTC
[Samba] Solaris interposer code for nsswitch.conf
Hi
there was a mail a while back on this list about using the LD_PRELOAD
feature on Solaris in order to override the location of nsswitch.conf for
smbd so only it would use winbindd. I did some digging and came up with the
code at the bottom of this mail ( I've overridden every file open call I
could find, but I think it's only the _open() call which is actually
necessary ). Initial testing seems to show it working ok - may be of use to
some people.
tim.
ps I'm not a C coder so this may not be the best in the world - if anyone
can do it better then please fix and post to the list.
/*
* Intercept open() call so that rather than using /etc/nsswitch.conf,
* a different file can be used. Build as follows:
* cc -o nsswitch_interposer.so -G -Jpic nsswitch_interposer.c
* setenv LD_PRELOAD $cwd/nsswitch_interposer.so
* run smbd
*
* Remove the printf statements in each function when using in earnest -
they are just there for debugging.
*/
#include <stdio.h>
#include <strings.h>
#include <dlfcn.h>
FILE* fopen(const char *fpath, const char *mode ){
static FILE * (*func)(const char*, const char *);
if(!func)
func = ( FILE * (*)(const char*, const char *))dlsym(RTLD_NEXT,
"fopen");
if(strcmp(fpath,"/etc/nsswitch.conf")==0)
fpath = "/etc/nsswitch_samba.conf";
printf(" calling fopen(%s, %s)\n", fpath, mode);
return(func(fpath, mode));
}
FILE* fopen64(const char *fpath, const char *mode ){
static FILE * (*func)(const char*, const char *);
if(!func)
func = ( FILE * (*)(const char*, const char *))dlsym(RTLD_NEXT,
"fopen64");
if(strcmp(fpath,"/etc/nsswitch.conf")==0)
fpath = "/etc/nsswitch_samba.conf";
printf(" calling fopen64(%s, %s)\n", fpath, mode);
return(func(fpath, mode));
}
int open(const char *path, int oflag ){
static int (*func)(const char*, int);
if(!func)
func = ( int (*)(const char*, int))dlsym(RTLD_NEXT, "open");
if(strcmp(path,"/etc/nsswitch.conf")==0)
path = "/etc/nsswitch_samba.conf";
printf(" calling open(%s, %d)\n", path, oflag);
return(func(path, oflag));
}
int _open(const char *path, int oflag ){
static int (*func)(const char*, int);
if(!func)
func = ( int (*)(const char*, int))dlsym(RTLD_NEXT, "_open");
if(strcmp(path,"/etc/nsswitch.conf")==0)
path = "/etc/nsswitch_samba.conf";
printf(" calling _open(%s, %d)\n", path, oflag);
return(func(path, oflag));
}
***************************************************************************
This communication (including any attachments) contains confidential
information. If you are not the intended recipient and you have received this
communication in error, you should destroy it without copying, disclosing or
otherwise using its contents. Please notify the sender immediately of the
error.
Internet communications are not necessarily secure and may be intercepted or
changed after they are sent. Abbey National Treasury Services plc does not
accept liability for any loss you may suffer as a result of interception or any
liability for such changes. If you wish to confirm the origin or content of
this communication, please contact the sender by using an alternative means of
communication.
This communication does not create or modify any contract and, unless otherwise
stated, is not intended to be contractually binding.
Abbey National Treasury Services plc. Registered Office: Abbey National House,
2 Triton Square, Regents Place, London NW1 3AN. Registered in England under
Company Registration Number: 2338548. Regulated by the Financial Services
Authority (FSA).
***************************************************************************
Seemingly Similar Threads
- problem with concatinating string while taking as a path of a file
- use object within rda file in for loop
- Huge write amplification with thin provisioned logical volumes
- JDK 1.0 port to FreeBSD
- [LLVMdev] SysUtils.c compile problem on Mac OSX 10.3 with llvm-1.4
