2007-09-08 00:57:01 +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
2007-09-08 00:57:01 +04:00
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
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1996-05-04 11:50:46 +04:00
( at your option ) any later version .
2007-09-08 00:57:01 +04:00
1996-05-04 11:50:46 +04:00
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 .
2007-09-08 00:57:01 +04:00
1996-05-04 11:50:46 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1996-05-04 11:50:46 +04:00
*/
# 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
*/
2007-10-19 04:40:25 +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
*/
2007-10-19 04:40:25 +04:00
bool mangle_is_8_3 ( const char * fname , bool check_case ,
2006-07-11 22:01:26 +04:00
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
}
2007-10-19 04:40:25 +04:00
bool mangle_is_8_3_wildcards ( const char * fname , bool check_case ,
2006-07-11 22:01:26 +04:00
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
2007-10-19 04:40:25 +04:00
bool mangle_must_mangle ( const char * fname ,
2007-09-08 00:57:01 +04:00
const struct share_params * p )
{
if ( ! lp_manglednames ( p ) ) {
return False ;
}
return mangle_fns - > must_mangle ( fname , p ) ;
}
2002-04-11 06:20:56 +04:00
/*
2007-09-08 00:57:01 +04:00
try to reverse map a 8.3 name to the original filename . This doesn ' t have to
2002-04-11 06:20:56 +04:00
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
*/
2007-10-19 04:40:25 +04:00
bool mangle_lookup_name_from_8_3 ( TALLOC_CTX * ctx ,
2007-09-08 00:57:01 +04:00
const char * in ,
char * * out , /* talloced on the given context. */
2006-07-11 22:01:26 +04:00
const struct share_params * p )
2002-04-11 06:20:56 +04:00
{
2007-09-08 00:57:01 +04:00
return mangle_fns - > lookup_name_from_8_3 ( ctx , in , out , p ) ;
2007-07-12 02:39:11 +04:00
}
2007-09-08 00:57:01 +04:00
/*
mangle a long filename to a 8.3 name .
Return True if we did mangle the name ( ie . out is filled in ) .
False on error .
JRA .
2002-04-08 05:58:44 +04:00
*/
2002-07-15 14:35:28 +04:00
2007-10-19 04:40:25 +04:00
bool name_to_8_3 ( const char * in ,
2007-09-08 00:57:01 +04:00
char out [ 13 ] ,
2007-10-19 04:40:25 +04:00
bool cache83 ,
2006-07-11 22:01:26 +04:00
const struct share_params * p )
2002-04-08 05:58:44 +04:00
{
2007-09-13 01:48:20 +04:00
memset ( out , ' \0 ' , 13 ) ;
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 ) ) {
2007-09-08 00:57:01 +04:00
safe_strcpy ( out , in , 12 ) ;
return True ;
2001-09-29 20:16:38 +04:00
}
2007-09-08 00:57:01 +04:00
return mangle_fns - > name_to_8_3 ( in ,
out ,
cache83 ,
lp_defaultcase ( p - > service ) ,
p ) ;
2002-04-11 06:20:56 +04:00
}