1996-05-04 11:50:46 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2002-04-11 06:20:56 +04:00
Name mangling interface
Copyright ( C ) Andrew Tridgell 2002
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"
2002-04-11 06:20:56 +04:00
static struct mangle_fns * mangle_fns ;
1996-05-04 11:50:46 +04:00
2002-04-11 06:20:56 +04:00
/* this allows us to add more mangling backends */
2003-01-03 11:28:12 +03:00
static const struct {
const char * name ;
2002-04-11 06:20:56 +04:00
struct mangle_fns * ( * init_fn ) ( void ) ;
} mangle_backends [ ] = {
{ " hash " , mangle_hash_init } ,
2002-04-11 13:56:38 +04:00
{ " hash2 " , mangle_hash2_init } ,
2005-06-23 01:20:41 +04:00
{ " posix " , posix_mangle_init } ,
2002-07-15 14:35:28 +04:00
/*{ "tdb", mangle_tdb_init }, */
2002-04-11 06:20:56 +04:00
{ NULL , NULL }
} ;
2001-09-25 13:57:06 +04:00
2002-04-11 06:20:56 +04:00
/*
initialise the mangling subsystem
*/
static void mangle_init ( void )
2002-04-08 05:58:44 +04:00
{
2002-04-11 06:20:56 +04:00
int i ;
2005-06-23 01:20:41 +04:00
const char * method ;
2001-09-25 13:57:06 +04:00
2002-07-15 14:35:28 +04:00
if ( mangle_fns )
return ;
2001-10-07 18:53:40 +04:00
2002-04-11 06:20:56 +04:00
method = lp_mangling_method ( ) ;
2001-10-07 18:53:40 +04:00
2002-07-15 14:35:28 +04:00
/* find the first mangling method that manages to initialise and
2002-04-11 06:20:56 +04:00
matches the " mangling method " parameter */
for ( i = 0 ; mangle_backends [ i ] . name & & ! mangle_fns ; i + + ) {
if ( ! method | | ! * method | | strcmp ( method , mangle_backends [ i ] . name ) = = 0 ) {
mangle_fns = mangle_backends [ i ] . init_fn ( ) ;
2001-09-27 16:41:38 +04:00
}
2001-09-25 13:57:06 +04:00
}
2001-11-04 21:26:53 +03:00
2002-04-11 06:20:56 +04:00
if ( ! mangle_fns ) {
DEBUG ( 0 , ( " Failed to initialise mangling system '%s' \n " , method ) ) ;
exit_server ( " mangling init failed " ) ;
2001-11-04 21:26:53 +03:00
}
}
2001-10-13 16:47:59 +04:00
2002-04-11 06:20:56 +04:00
/*
reset the cache . This is called when smb . conf has been reloaded
*/
void mangle_reset_cache ( void )
{
mangle_init ( ) ;
2002-04-11 18:59:27 +04:00
mangle_fns - > reset ( ) ;
2001-10-13 16:47:59 +04:00
}
2005-06-23 01:20:41 +04:00
void mangle_change_to_posix ( void )
{
mangle_fns = NULL ;
lp_set_mangling_method ( " posix " ) ;
mangle_reset_cache ( ) ;
}
2002-04-11 06:20:56 +04:00
/*
see if a filename has come out of our mangling code
*/
2006-07-11 22:01:26 +04:00
BOOL mangle_is_mangled ( const char * s , const struct share_params * p )
2001-10-13 16:47:59 +04:00
{
2006-07-11 22:01:26 +04:00
return mangle_fns - > is_mangled ( s , p ) ;
2001-10-13 16:47:59 +04:00
}
2002-04-11 06:20:56 +04:00
/*
see if a filename matches the rules of a 8.3 filename
*/
2006-07-11 22:01:26 +04:00
BOOL mangle_is_8_3 ( const char * fname , BOOL check_case ,
const struct share_params * p )
2001-09-29 20:16:38 +04:00
{
2006-07-11 22:01:26 +04:00
return mangle_fns - > is_8_3 ( fname , check_case , False , p ) ;
2002-07-15 14:35:28 +04:00
}
2006-07-11 22:01:26 +04:00
BOOL mangle_is_8_3_wildcards ( const char * fname , BOOL check_case ,
const struct share_params * p )
2002-07-15 14:35:28 +04:00
{
2006-07-11 22:01:26 +04:00
return mangle_fns - > is_8_3 ( fname , check_case , True , p ) ;
2002-04-11 06:20:56 +04:00
}
2002-04-08 05:58:44 +04:00
2002-04-11 06:20:56 +04:00
/*
try to reverse map a 8.3 name to the original filename . This doesn ' t have to
always succeed , as the directory handling code in smbd will scan the directory
looking for a matching name if it doesn ' t . It should succeed most of the time
or there will be a huge performance penalty
*/
2006-07-11 22:01:26 +04:00
BOOL mangle_check_cache ( char * s , size_t maxlen ,
const struct share_params * p )
2002-04-11 06:20:56 +04:00
{
2006-07-11 22:01:26 +04:00
return mangle_fns - > check_cache ( s , maxlen , p ) ;
2002-04-11 06:20:56 +04:00
}
2002-04-08 05:58:44 +04:00
2002-04-11 06:20:56 +04:00
/*
map a long filename to a 8.3 name .
2002-04-08 05:58:44 +04:00
*/
2002-07-15 14:35:28 +04:00
2006-07-11 22:01:26 +04:00
void mangle_map ( pstring OutName , BOOL need83 , BOOL cache83 ,
const struct share_params * p )
2002-04-08 05:58:44 +04:00
{
2002-04-11 06:20:56 +04:00
/* name mangling can be disabled for speed, in which case
we just truncate the string */
2006-07-11 22:01:26 +04:00
if ( ! lp_manglednames ( p ) ) {
2002-04-11 06:20:56 +04:00
if ( need83 ) {
string_truncate ( OutName , 12 ) ;
2002-04-08 05:58:44 +04:00
}
2002-07-15 14:35:28 +04:00
return ;
2001-09-29 20:16:38 +04:00
}
2002-04-11 06:20:56 +04:00
/* invoke the inane "mangled map" code */
2006-07-11 22:01:26 +04:00
mangle_map_filename ( OutName , p ) ;
mangle_fns - > name_map ( OutName , need83 , cache83 , lp_defaultcase ( p - > service ) , p ) ;
2002-04-11 06:20:56 +04:00
}