|
Description
|
[From Mike S, 1/30/2008]
libsmb should look for an interposition library that replaces the three smb_pwd_* routines. This is how it would work:
In libsmb.so.1 do this:
struct {
int (*smb_pwd_getpasswd)( ... );
int (*smb_pwd_setcntl)( ... );
int (*smb_pwd_setpasswd)( ... );
} smb_pwd_ops;
void *smb_pwd_hdl;
#pragma init (smb_init)
void
smb_init(void)
{
smb_pwd_hdl = dlopen("/usr/lib/smb/libsmb_pwd.so", RTLD_LOCAL);
if (smb_pwd_hdl == NULL)
return; /* interposition library not found */
smb_pwd_ops.smb_pwd_getpasswd =
(int (*)())dlsym(smb_pwd_hdl, "smb_pwd_getpasswd");
smb_pwd_ops.smb_pwd_getpasswd =
(int (*)())dlsym(smb_pwd_hdl, "smb_pwd_setcntl");
smb_pwd_ops.smb_pwd_getpasswd =
(int (*)())dlsym(smb_pwd_hdl, "smb_pwd_setpasswd");
}
and then you change each function to be hooked as you suggested, e.g.
int
smb_pwd_getpasswd( ... )
{
if (smb_pwd_ops.smb_pwd_getpasswd != NULL)
return (smb_pwd_ops.smb_pwd_getpasswd( ... ));
... do existing code
}
This isn't particularly hard either. The key is that since multiple things depend on libsmb, we can't force them to call some registration function: the registration has to be done automatically when libsmb is loaded, by seeing that our interposition binary is on the filesystem.
|