1996-05-04 11:50:46 +04:00
/*
Unix SMB / Netbios implementation .
Version 1.9 .
Username handling
1998-01-22 16:27:43 +03:00
Copyright ( C ) Andrew Tridgell 1992 - 1998
1996-05-04 11:50:46 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
1998-06-10 23:45:13 +04:00
/* internal functions */
1998-04-13 23:24:06 +04:00
static struct passwd * uname_string_combinations ( char * s , struct passwd * ( * fn ) ( char * ) , int N ) ;
static struct passwd * uname_string_combinations2 ( char * s , int offset , struct passwd * ( * fn ) ( char * ) , int N ) ;
1996-05-04 11:50:46 +04:00
1999-05-06 22:05:45 +04:00
/****************************************************************************
1999-12-13 16:27:58 +03:00
Get a users home directory .
1999-05-06 22:05:45 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
char * get_user_home_dir ( char * user )
1999-05-06 22:05:45 +04:00
{
1999-12-13 16:27:58 +03:00
static struct passwd * pass ;
1999-05-06 22:05:45 +04:00
1999-12-13 16:27:58 +03:00
pass = Get_Pwnam ( user , False ) ;
1999-05-06 22:05:45 +04:00
1999-12-13 16:27:58 +03:00
if ( ! pass ) return ( NULL ) ;
return ( pass - > pw_dir ) ;
1999-05-06 22:05:45 +04:00
}
/*******************************************************************
1999-12-13 16:27:58 +03:00
Map a username from a dos name to a unix name by looking in the username
map . Note that this modifies the name in place .
This is the main function that should be called * once * on
any incoming or new username - in order to canonicalize the name .
This is being done to de - couple the case conversions from the user mapping
function . Previously , the map_username was being called
every time Get_Pwnam was called .
Returns True if username was changed , false otherwise .
1999-05-06 22:05:45 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1996-05-04 11:50:46 +04:00
1998-06-12 07:08:23 +04:00
BOOL map_username ( char * user )
1996-05-04 11:50:46 +04:00
{
static BOOL initialised = False ;
static fstring last_from , last_to ;
2001-09-10 16:46:42 +04:00
XFILE * f ;
1996-05-04 11:50:46 +04:00
char * mapfile = lp_username_map ( ) ;
1998-06-12 07:08:23 +04:00
char * s ;
pstring buf ;
1998-07-07 20:58:29 +04:00
BOOL mapped_user = False ;
1996-05-04 11:50:46 +04:00
1998-06-12 07:08:23 +04:00
if ( ! * user )
return False ;
1996-05-04 11:50:46 +04:00
1998-06-12 07:08:23 +04:00
if ( ! * mapfile )
return False ;
1998-06-10 23:45:13 +04:00
1996-05-04 11:50:46 +04:00
if ( ! initialised ) {
* last_from = * last_to = 0 ;
initialised = True ;
}
1998-06-10 23:45:13 +04:00
if ( strequal ( user , last_to ) )
1998-06-12 07:08:23 +04:00
return False ;
1996-05-04 11:50:46 +04:00
if ( strequal ( user , last_from ) ) {
DEBUG ( 3 , ( " Mapped user %s to %s \n " , user , last_to ) ) ;
1997-09-26 22:55:29 +04:00
fstrcpy ( user , last_to ) ;
1998-06-12 07:08:23 +04:00
return True ;
1996-05-04 11:50:46 +04:00
}
2001-09-10 16:46:42 +04:00
f = x_fopen ( mapfile , O_RDONLY , 0 ) ;
1996-05-04 11:50:46 +04:00
if ( ! f ) {
2001-04-06 21:13:16 +04:00
DEBUG ( 0 , ( " can't open username map %s. Error %s \n " , mapfile , strerror ( errno ) ) ) ;
1998-06-12 07:08:23 +04:00
return False ;
1996-05-04 11:50:46 +04:00
}
DEBUG ( 4 , ( " Scanning username map %s \n " , mapfile ) ) ;
1998-06-12 07:08:23 +04:00
while ( ( s = fgets_slash ( buf , sizeof ( buf ) , f ) ) ! = NULL ) {
1996-05-04 11:50:46 +04:00
char * unixname = s ;
2001-07-04 11:36:09 +04:00
char * dosname = strchr_m ( unixname , ' = ' ) ;
2001-07-25 00:02:48 +04:00
char * * dosuserlist ;
1998-06-10 23:45:13 +04:00
BOOL return_if_mapped = False ;
1996-05-04 11:50:46 +04:00
1998-06-12 07:08:23 +04:00
if ( ! dosname )
continue ;
1996-05-04 11:50:46 +04:00
* dosname + + = 0 ;
1998-06-12 07:08:23 +04:00
while ( isspace ( * unixname ) )
unixname + + ;
1998-06-10 23:45:13 +04:00
if ( ' ! ' = = * unixname ) {
return_if_mapped = True ;
1997-12-03 07:20:39 +03:00
unixname + + ;
1998-06-12 07:08:23 +04:00
while ( * unixname & & isspace ( * unixname ) )
unixname + + ;
1997-12-03 07:20:39 +03:00
}
2001-07-04 11:36:09 +04:00
if ( ! * unixname | | strchr_m ( " #; " , * unixname ) )
1998-06-12 07:08:23 +04:00
continue ;
1996-05-04 11:50:46 +04:00
{
int l = strlen ( unixname ) ;
while ( l & & isspace ( unixname [ l - 1 ] ) ) {
1998-06-10 23:45:13 +04:00
unixname [ l - 1 ] = 0 ;
l - - ;
1996-05-04 11:50:46 +04:00
}
}
2001-07-25 00:02:48 +04:00
dosuserlist = lp_list_make ( dosname ) ;
if ( ! dosuserlist ) {
DEBUG ( 0 , ( " Unable to build user list \n " ) ) ;
return False ;
}
if ( strchr_m ( dosname , ' * ' ) | | user_in_list ( user , dosuserlist ) ) {
1996-05-04 11:50:46 +04:00
DEBUG ( 3 , ( " Mapped user %s to %s \n " , user , unixname ) ) ;
1998-07-07 20:58:29 +04:00
mapped_user = True ;
1998-06-10 23:45:13 +04:00
fstrcpy ( last_from , user ) ;
1996-05-04 11:50:46 +04:00
sscanf ( unixname , " %s " , user ) ;
1998-06-10 23:45:13 +04:00
fstrcpy ( last_to , user ) ;
2001-07-25 00:02:48 +04:00
if ( return_if_mapped ) {
lp_list_free ( & dosuserlist ) ;
2001-09-10 16:46:42 +04:00
x_fclose ( f ) ;
1998-06-12 07:08:23 +04:00
return True ;
1997-12-03 07:20:39 +03:00
}
1996-05-04 11:50:46 +04:00
}
2001-07-25 00:02:48 +04:00
lp_list_free ( & dosuserlist ) ;
1996-05-04 11:50:46 +04:00
}
2001-09-10 16:46:42 +04:00
x_fclose ( f ) ;
1998-06-12 07:08:23 +04:00
/*
1998-07-07 20:58:29 +04:00
* Setup the last_from and last_to as an optimization so
* that we don ' t scan the file again for the same user .
1998-06-12 07:08:23 +04:00
*/
fstrcpy ( last_from , user ) ;
fstrcpy ( last_to , user ) ;
1998-07-07 20:58:29 +04:00
return mapped_user ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
1999-07-07 02:08:55 +04:00
Get_Pwnam wrapper
1996-05-04 11:50:46 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
1996-05-04 11:50:46 +04:00
static struct passwd * _Get_Pwnam ( char * s )
{
1999-12-13 16:27:58 +03:00
struct passwd * ret ;
1999-06-13 08:14:24 +04:00
1999-12-13 16:27:58 +03:00
ret = sys_getpwnam ( s ) ;
if ( ret ) {
1998-07-31 07:33:25 +04:00
# ifdef HAVE_GETPWANAM
1999-12-13 16:27:58 +03:00
struct passwd_adjunct * pwret ;
pwret = getpwanam ( s ) ;
if ( pwret & & pwret - > pwa_passwd ) {
pstrcpy ( ret - > pw_passwd , pwret - > pwa_passwd ) ;
}
1996-05-04 11:50:46 +04:00
# endif
1999-12-13 16:27:58 +03:00
}
1996-05-04 11:50:46 +04:00
1999-12-13 16:27:58 +03:00
return ( ret ) ;
1996-05-04 11:50:46 +04:00
}
1999-12-13 16:27:58 +03:00
2001-01-18 01:33:07 +03:00
/*
* A wrapper for getpwnam ( ) . The following variations are tried :
* - as transmitted
* - in all lower case if this differs from transmitted
* - in all upper case if this differs from transmitted
* - using lp_usernamelevel ( ) for permutations .
* NOTE : This can potentially modify ' user ' depending on value of
* allow_change !
*/
1999-12-13 16:27:58 +03:00
struct passwd * Get_Pwnam ( char * user , BOOL allow_change )
1996-05-04 11:50:46 +04:00
{
2001-01-18 01:33:07 +03:00
fstring user2 ;
struct passwd * ret = NULL ;
2000-12-11 20:48:26 +03:00
if ( ! user | | ! ( * user ) )
return ( NULL ) ;
2001-01-18 01:33:07 +03:00
fstrcpy ( user2 , user ) ;
2000-12-11 20:48:26 +03:00
2001-01-18 01:33:07 +03:00
/* Try in all lower case first as this is the most
2000-12-11 20:48:26 +03:00
common case on UNIX systems */
2001-01-18 01:33:07 +03:00
strlower ( user2 ) ;
DEBUG ( 5 , ( " Trying _Get_Pwnam(), username as lowercase is %s \n " , user2 ) ) ;
ret = _Get_Pwnam ( user2 ) ;
if ( ret )
goto done ;
/* Try as given, if username wasn't originally lowercase */
if ( strcmp ( user , user2 ) ! = 0 ) {
2001-01-24 18:41:07 +03:00
DEBUG ( 5 , ( " Trying _Get_Pwnam(), username as given is %s \n " , user ) ) ;
ret = _Get_Pwnam ( user ) ;
2001-01-18 01:33:07 +03:00
if ( ret )
goto done ;
}
/* Try as uppercase, if username wasn't originally uppercase */
strupper ( user2 ) ;
if ( strcmp ( user , user2 ) ! = 0 ) {
DEBUG ( 5 , ( " Trying _Get_Pwnam(), username as uppercase is %s \n " , user2 ) ) ;
ret = _Get_Pwnam ( user2 ) ;
if ( ret )
goto done ;
2000-12-11 20:48:26 +03:00
}
2001-01-18 01:33:07 +03:00
/* Try all combinations up to usernamelevel */
strlower ( user2 ) ;
DEBUG ( 5 , ( " Checking combinations of %d uppercase letters in %s \n " , lp_usernamelevel ( ) , user2 ) ) ;
ret = uname_string_combinations ( user2 , _Get_Pwnam , lp_usernamelevel ( ) ) ;
2000-12-11 20:48:26 +03:00
2001-01-18 01:33:07 +03:00
done :
DEBUG ( 5 , ( " Get_Pwnam %s find a valid username! \n " , ret ? " did " : " didn't " ) ) ;
/* If caller wants the modified username, ensure they get it */
if ( allow_change )
fstrcpy ( user , user2 ) ;
2000-12-11 20:48:26 +03:00
2001-01-18 01:33:07 +03:00
/* We can safely assume ret is NULL if none of the above succeed */
return ( ret ) ;
1996-05-04 11:50:46 +04:00
}
/****************************************************************************
1999-12-13 16:27:58 +03:00
Check if a user is in a netgroup user list .
1998-06-13 07:04:00 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
1998-06-13 07:04:00 +04:00
static BOOL user_in_netgroup_list ( char * user , char * ngname )
{
1998-07-29 07:08:05 +04:00
# ifdef HAVE_NETGROUP
1998-06-13 07:04:00 +04:00
static char * mydomain = NULL ;
if ( mydomain = = NULL )
yp_get_default_domain ( & mydomain ) ;
1999-12-13 16:27:58 +03:00
if ( mydomain = = NULL ) {
1998-06-13 07:04:00 +04:00
DEBUG ( 5 , ( " Unable to get default yp domain \n " ) ) ;
1999-12-13 16:27:58 +03:00
} else {
1998-06-13 07:04:00 +04:00
DEBUG ( 5 , ( " looking for user %s of domain %s in netgroup %s \n " ,
user , mydomain , ngname ) ) ;
DEBUG ( 5 , ( " innetgr is %s \n " ,
innetgr ( ngname , NULL , user , mydomain )
? " TRUE " : " FALSE " ) ) ;
if ( innetgr ( ngname , NULL , user , mydomain ) )
return ( True ) ;
}
1998-07-29 07:08:05 +04:00
# endif /* HAVE_NETGROUP */
1998-06-13 07:04:00 +04:00
return False ;
}
/****************************************************************************
2000-10-13 05:59:14 +04:00
Check if a user is in a winbind group .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static BOOL user_in_winbind_group_list ( char * user , char * gname , BOOL * winbind_answered )
{
int num_groups ;
int i ;
gid_t * groups = NULL ;
gid_t gid ;
BOOL ret = False ;
* winbind_answered = False ;
/*
* Get the gid ' s that this user belongs to .
*/
if ( ( num_groups = winbind_getgroups ( user , 0 , NULL ) ) = = - 1 )
return False ;
if ( num_groups = = 0 ) {
* winbind_answered = True ;
return False ;
}
if ( ( groups = ( gid_t * ) malloc ( sizeof ( gid_t ) * num_groups ) ) = = NULL ) {
DEBUG ( 0 , ( " user_in_winbind_group_list: malloc fail. \n " ) ) ;
goto err ;
}
if ( ( num_groups = winbind_getgroups ( user , num_groups , groups ) ) = = - 1 ) {
DEBUG ( 0 , ( " user_in_winbind_group_list: second winbind_getgroups call \
failed with error % s \ n " , strerror(errno) ));
goto err ;
}
/*
* Now we have the gid list for this user - convert the gname
2000-10-26 03:32:12 +04:00
* to a gid_t via either winbind or the local UNIX lookup and do the comparison .
2000-10-13 05:59:14 +04:00
*/
2000-10-26 03:32:12 +04:00
if ( ( gid = nametogid ( gname ) ) = = ( gid_t ) - 1 ) {
2000-10-13 05:59:14 +04:00
DEBUG ( 0 , ( " user_in_winbind_group_list: winbind_lookup_name for group %s failed. \n " ,
gname ) ) ;
goto err ;
}
for ( i = 0 ; i < num_groups ; i + + ) {
if ( gid = = groups [ i ] ) {
ret = True ;
break ;
}
}
* winbind_answered = True ;
2001-09-17 06:19:44 +04:00
SAFE_FREE ( groups ) ;
2000-10-13 05:59:14 +04:00
return ret ;
err :
* winbind_answered = False ;
2001-09-17 06:19:44 +04:00
SAFE_FREE ( groups ) ;
2000-10-13 05:59:14 +04:00
return False ;
}
/****************************************************************************
Check if a user is in a UNIX group .
1998-06-13 07:04:00 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
2000-10-13 05:59:14 +04:00
static BOOL user_in_unix_group_list ( char * user , char * gname )
1998-06-13 07:04:00 +04:00
{
1999-12-13 16:27:58 +03:00
struct group * gptr ;
char * * member ;
2000-10-12 02:38:38 +04:00
struct passwd * pass = Get_Pwnam ( user , False ) ;
2000-10-13 05:59:14 +04:00
DEBUG ( 10 , ( " user_in_unix_group_list: checking user %s in group %s \n " , user , gname ) ) ;
/*
* We need to check the users primary group as this
* group is implicit and often not listed in the group database .
*/
if ( pass ) {
gptr = getgrgid ( pass - > pw_gid ) ;
if ( gptr & & strequal ( gptr - > gr_name , gname ) ) {
DEBUG ( 10 , ( " user_in_unix_group_list: group %s is primary group. \n " , gname ) ) ;
return True ;
}
}
if ( ( gptr = ( struct group * ) getgrnam ( gname ) ) = = NULL ) {
DEBUG ( 10 , ( " user_in_unix_group_list: no such group %s \n " , gname ) ) ;
return False ;
}
member = gptr - > gr_mem ;
while ( member & & * member ) {
DEBUG ( 10 , ( " user_in_unix_group_list: checking user %s against member %s \n " , user , * member ) ) ;
if ( strequal ( * member , user ) ) {
return ( True ) ;
}
2000-10-11 07:46:14 +04:00
member + + ;
1999-12-13 16:27:58 +03:00
}
return False ;
1998-06-13 07:04:00 +04:00
}
2000-10-13 05:59:14 +04:00
/****************************************************************************
Check if a user is in a group list . Ask winbind first , then use UNIX .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL user_in_group_list ( char * user , char * gname )
{
BOOL winbind_answered = False ;
BOOL ret = user_in_winbind_group_list ( user , gname , & winbind_answered ) ;
if ( winbind_answered )
return ret ;
return user_in_unix_group_list ( user , gname ) ;
}
1999-12-06 03:44:32 +03:00
/****************************************************************************
1999-12-13 16:27:58 +03:00
Check if a user is in a user list - can check combinations of UNIX
and netgroup lists .
1999-12-06 03:44:32 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-07-25 00:02:48 +04:00
BOOL user_in_list ( char * user , char * * list )
1996-05-04 11:50:46 +04:00
{
2001-07-25 00:02:48 +04:00
if ( ! list | | ! * list ) return False ;
DEBUG ( 10 , ( " user_in_list: checking user %s in list \n " , user ) ) ;
2000-10-13 05:59:14 +04:00
2001-07-25 00:02:48 +04:00
while ( * list ) {
1998-06-13 07:04:00 +04:00
/*
* Check raw username .
*/
2001-07-25 00:02:48 +04:00
if ( strequal ( user , * list ) )
1998-06-13 07:04:00 +04:00
return ( True ) ;
1996-05-04 11:50:46 +04:00
1998-06-13 07:04:00 +04:00
/*
* Now check to see if any combination
* of UNIX and netgroups has been specified .
*/
1996-05-04 11:50:46 +04:00
2001-07-25 00:02:48 +04:00
if ( * * list = = ' @ ' ) {
1998-06-13 07:04:00 +04:00
/*
* Old behaviour . Check netgroup list
* followed by UNIX list .
*/
2001-07-25 00:02:48 +04:00
if ( user_in_netgroup_list ( user , * list + 1 ) )
1998-06-13 07:04:00 +04:00
return True ;
2001-07-25 00:02:48 +04:00
if ( user_in_group_list ( user , * list + 1 ) )
1998-06-13 07:04:00 +04:00
return True ;
2001-07-25 00:02:48 +04:00
} else if ( * * list = = ' + ' ) {
1999-12-13 16:27:58 +03:00
2001-07-25 00:02:48 +04:00
if ( ( * ( * list + 1 ) ) = = ' & ' ) {
1998-06-13 07:04:00 +04:00
/*
* Search UNIX list followed by netgroup .
*/
2001-07-25 00:02:48 +04:00
if ( user_in_group_list ( user , * list + 2 ) )
1998-06-13 07:04:00 +04:00
return True ;
2001-07-25 00:02:48 +04:00
if ( user_in_netgroup_list ( user , * list + 2 ) )
1998-06-13 07:04:00 +04:00
return True ;
1999-12-13 16:27:58 +03:00
} else {
1998-06-13 07:04:00 +04:00
/*
* Just search UNIX list .
*/
1999-12-13 16:27:58 +03:00
2001-07-25 00:02:48 +04:00
if ( user_in_group_list ( user , * list + 1 ) )
1998-06-13 07:04:00 +04:00
return True ;
}
1999-12-13 16:27:58 +03:00
2001-07-25 00:02:48 +04:00
} else if ( * * list = = ' & ' ) {
1999-12-13 16:27:58 +03:00
2001-07-25 00:02:48 +04:00
if ( * ( * list + 1 ) = = ' + ' ) {
1998-06-13 07:04:00 +04:00
/*
* Search netgroup list followed by UNIX list .
*/
2001-07-25 00:02:48 +04:00
if ( user_in_netgroup_list ( user , * list + 2 ) )
1998-06-13 07:04:00 +04:00
return True ;
2001-07-25 00:02:48 +04:00
if ( user_in_group_list ( user , * list + 2 ) )
1998-06-13 07:04:00 +04:00
return True ;
1999-12-13 16:27:58 +03:00
} else {
1998-06-13 07:04:00 +04:00
/*
* Just search netgroup list .
*/
2001-07-25 00:02:48 +04:00
if ( user_in_netgroup_list ( user , * list + 1 ) )
1998-06-13 07:04:00 +04:00
return True ;
}
1996-05-04 11:50:46 +04:00
}
2001-07-25 00:02:48 +04:00
list + + ;
1998-06-13 07:04:00 +04:00
}
1996-05-04 11:50:46 +04:00
return ( False ) ;
}
1997-09-19 21:12:08 +04:00
/* The functions below have been taken from password.c and slightly modified */
/****************************************************************************
1999-12-13 16:27:58 +03:00
Apply a function to upper / lower case combinations
of a string and return true if one of them returns true .
Try all combinations with N uppercase letters .
offset is the first char to try and change ( start with 0 )
it assumes the string starts lowercased
1997-09-19 21:12:08 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
1998-04-13 23:24:06 +04:00
static struct passwd * uname_string_combinations2 ( char * s , int offset , struct passwd * ( * fn ) ( char * ) , int N )
1997-09-19 21:12:08 +04:00
{
1999-12-13 16:27:58 +03:00
ssize_t len = ( ssize_t ) strlen ( s ) ;
1997-09-19 21:12:08 +04:00
int i ;
struct passwd * ret ;
# ifdef PASSWORD_LENGTH
len = MIN ( len , PASSWORD_LENGTH ) ;
# endif
if ( N < = 0 | | offset > = len )
return ( fn ( s ) ) ;
1999-12-13 16:27:58 +03:00
for ( i = offset ; i < ( len - ( N - 1 ) ) ; i + + ) {
char c = s [ i ] ;
if ( ! islower ( c ) )
continue ;
s [ i ] = toupper ( c ) ;
ret = uname_string_combinations2 ( s , i + 1 , fn , N - 1 ) ;
if ( ret )
return ( ret ) ;
s [ i ] = c ;
}
1997-09-19 21:12:08 +04:00
return ( NULL ) ;
}
/****************************************************************************
1999-12-13 16:27:58 +03:00
Apply a function to upper / lower case combinations
of a string and return true if one of them returns true .
Try all combinations with up to N uppercase letters .
offset is the first char to try and change ( start with 0 )
it assumes the string starts lowercased
1997-09-19 21:12:08 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
1998-04-13 23:24:06 +04:00
static struct passwd * uname_string_combinations ( char * s , struct passwd * ( * fn ) ( char * ) , int N )
1997-09-19 21:12:08 +04:00
{
int n ;
struct passwd * ret ;
1999-12-13 16:27:58 +03:00
for ( n = 1 ; n < = N ; n + + ) {
1997-09-19 21:12:08 +04:00
ret = uname_string_combinations2 ( s , 0 , fn , n ) ;
1999-12-13 16:27:58 +03:00
if ( ret )
return ( ret ) ;
1997-09-19 21:12:08 +04:00
}
return ( NULL ) ;
}
2000-05-04 20:01:47 +04:00
/****************************************************************************
these wrappers allow appliance mode to work . In appliance mode the username
takes the form DOMAIN / user
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2000-05-10 18:48:33 +04:00
struct passwd * smb_getpwnam ( char * user , BOOL allow_change )
2000-05-04 20:01:47 +04:00
{
struct passwd * pw ;
2000-05-10 18:48:33 +04:00
char * p ;
2000-05-29 05:08:18 +04:00
char * sep ;
extern pstring global_myname ;
2000-05-04 20:01:47 +04:00
pw = Get_Pwnam ( user , allow_change ) ;
2000-05-10 18:48:33 +04:00
if ( pw ) return pw ;
2000-05-04 20:01:47 +04:00
2000-05-29 05:08:18 +04:00
/* if it is a domain qualified name and it isn't in our password
database but the domain portion matches our local machine name then
lookup just the username portion locally */
sep = lp_winbind_separator ( ) ;
if ( ! sep | | ! * sep ) sep = " \\ " ;
2001-07-04 11:36:09 +04:00
p = strchr_m ( user , * sep ) ;
2000-05-29 05:08:18 +04:00
if ( p & &
strncasecmp ( global_myname , user , strlen ( global_myname ) ) = = 0 ) {
return Get_Pwnam ( p + 1 , allow_change ) ;
}
2000-05-04 20:01:47 +04:00
2000-05-10 18:48:33 +04:00
return NULL ;
2000-05-04 20:01:47 +04:00
}