1998-01-06 01:56:29 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1999-12-13 16:27:58 +03:00
SMBFS mount program
Copyright ( C ) Andrew Tridgell 1999
1998-01-06 01:56:29 +03: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
1998-01-06 01:56:29 +03:00
( 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
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-01-06 01:56:29 +03:00
*/
# include "includes.h"
1998-09-28 23:18:21 +04:00
1999-02-15 02:15:54 +03:00
# include <mntent.h>
1998-09-28 23:18:21 +04:00
# include <asm/types.h>
1998-01-06 01:56:29 +03:00
# include <linux/smb_fs.h>
2007-10-19 04:40:25 +04:00
extern bool in_client ;
2006-12-12 20:38:42 +03:00
extern char * optarg ;
extern int optind ;
1998-01-06 01:56:29 +03:00
2007-12-06 01:55:08 +03:00
static char * credentials ;
static fstring my_netbios_name ;
static char * password ;
static char * username ;
static fstring workgroup ;
static char * mpoint ;
static char * service ;
static char * options ;
1999-12-13 16:27:58 +03:00
2007-10-27 23:15:07 +04:00
static struct sockaddr_storage dest_ip ;
2007-10-19 04:40:25 +04:00
static bool have_ip ;
2001-08-25 00:11:09 +04:00
static int smb_port = 0 ;
2007-10-19 04:40:25 +04:00
static bool got_user ;
static bool got_pass ;
1999-12-13 16:27:58 +03:00
static uid_t mount_uid ;
static gid_t mount_gid ;
static int mount_ro ;
static unsigned mount_fmask ;
static unsigned mount_dmask ;
2007-10-19 04:40:25 +04:00
static bool use_kerberos ;
2003-02-24 06:28:37 +03:00
/* TODO: Add code to detect smbfs version in kernel */
2007-10-19 04:40:25 +04:00
static bool status32_smbfs = False ;
static bool smbfs_has_unicode = False ;
static bool smbfs_has_lfs = False ;
1999-12-13 16:27:58 +03:00
static void usage ( void ) ;
static void exit_parent ( int sig )
1999-02-01 00:28:55 +03:00
{
/* parent simply exits when child says go... */
exit ( 0 ) ;
}
1999-12-13 16:27:58 +03:00
static void daemonize ( void )
1998-01-06 01:56:29 +03:00
{
1999-02-01 00:28:55 +03:00
int j , status ;
pid_t child_pid ;
signal ( SIGTERM , exit_parent ) ;
2000-05-02 06:23:41 +04:00
if ( ( child_pid = sys_fork ( ) ) < 0 ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " could not fork \n " ) ) ;
1998-01-06 01:56:29 +03:00
}
1999-12-13 16:27:58 +03:00
if ( child_pid > 0 ) {
1999-02-01 00:28:55 +03:00
while ( 1 ) {
j = waitpid ( child_pid , & status , 0 ) ;
if ( j < 0 ) {
if ( EINTR = = errno ) {
continue ;
}
status = errno ;
}
break ;
}
2003-01-15 21:57:41 +03:00
1999-02-01 00:28:55 +03:00
/* If we get here - the child exited with some error status */
2003-01-16 02:11:57 +03:00
if ( WIFSIGNALED ( status ) )
2003-01-15 21:57:41 +03:00
exit ( 128 + WTERMSIG ( status ) ) ;
else
exit ( WEXITSTATUS ( status ) ) ;
1998-01-06 01:56:29 +03:00
}
1999-02-01 00:28:55 +03:00
signal ( SIGTERM , SIG_DFL ) ;
1998-01-06 01:56:29 +03:00
chdir ( " / " ) ;
}
1999-12-13 16:27:58 +03:00
static void close_our_files ( int client_fd )
1998-01-06 01:56:29 +03:00
{
int i ;
2001-04-22 07:16:04 +04:00
struct rlimit limits ;
2001-04-14 22:39:32 +04:00
getrlimit ( RLIMIT_NOFILE , & limits ) ;
2001-04-22 07:16:04 +04:00
for ( i = 0 ; i < limits . rlim_max ; i + + ) {
if ( i = = client_fd )
continue ;
1998-01-06 01:56:29 +03:00
close ( i ) ;
}
}
1999-12-13 16:27:58 +03:00
static void usr1_handler ( int x )
1998-01-06 01:56:29 +03:00
{
return ;
}
1999-12-13 16:27:58 +03:00
/*****************************************************
return a connection to a server
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2001-11-26 04:59:33 +03:00
static struct cli_state * do_connection ( char * the_service )
1998-01-06 01:56:29 +03:00
{
1999-12-13 16:27:58 +03:00
struct cli_state * c ;
struct nmb_name called , calling ;
char * server_n ;
2007-10-27 23:15:07 +04:00
struct sockaddr_storage ip ;
2007-12-06 01:55:08 +03:00
char * server ;
1999-12-13 16:27:58 +03:00
char * share ;
2007-12-06 01:55:08 +03:00
const char * c_username ;
const char * c_password ;
TALLOC_CTX * ctx = talloc_tos ( ) ;
1999-12-13 16:27:58 +03:00
2001-11-26 04:59:33 +03:00
if ( the_service [ 0 ] ! = ' \\ ' | | the_service [ 1 ] ! = ' \\ ' ) {
1999-12-13 16:27:58 +03:00
usage ( ) ;
exit ( 1 ) ;
}
2007-12-06 01:55:08 +03:00
server = talloc_strdup ( ctx , the_service + 2 ) ;
if ( ! server ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
2001-07-04 11:36:09 +04:00
share = strchr_m ( server , ' \\ ' ) ;
1999-12-13 16:27:58 +03:00
if ( ! share ) {
usage ( ) ;
exit ( 1 ) ;
}
* share = 0 ;
share + + ;
server_n = server ;
2000-01-07 09:55:36 +03:00
make_nmb_name ( & calling , my_netbios_name , 0x0 ) ;
make_nmb_name ( & called , server , 0x20 ) ;
1999-12-13 16:27:58 +03:00
again :
2007-10-28 06:29:36 +03:00
zero_addr ( & ip ) ;
1999-12-13 16:27:58 +03:00
if ( have_ip ) ip = dest_ip ;
/* have to open a new connection */
2006-07-11 22:01:26 +04:00
if ( ! ( c = cli_initialise ( ) ) | | ( cli_set_port ( c , smb_port ) ! = smb_port ) | |
2007-06-21 18:30:40 +04:00
! NT_STATUS_IS_OK ( cli_connect ( c , server_n , & ip ) ) ) {
2002-03-14 04:53:04 +03:00
DEBUG ( 0 , ( " %d: Connection to %s failed \n " , sys_getpid ( ) , server_n ) ) ;
2001-03-10 02:48:58 +03:00
if ( c ) {
cli_shutdown ( c ) ;
}
1999-12-13 16:27:58 +03:00
return NULL ;
}
2002-01-05 06:45:50 +03:00
/* SPNEGO doesn't work till we get NTSTATUS error support */
2003-02-24 06:28:37 +03:00
/* But it is REQUIRED for kerberos authentication */
if ( ! use_kerberos ) c - > use_spnego = False ;
/* The kernel doesn't yet know how to sign it's packets */
c - > sign_info . allow_smb_signing = False ;
/* Use kerberos authentication if specified */
c - > use_kerberos = use_kerberos ;
2002-01-05 06:45:50 +03:00
1999-12-13 16:27:58 +03:00
if ( ! cli_session_request ( c , & calling , & called ) ) {
2001-03-10 02:48:58 +03:00
char * p ;
DEBUG ( 0 , ( " %d: session request to %s failed (%s) \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , called . name , cli_errstr ( c ) ) ) ;
1999-12-13 16:27:58 +03:00
cli_shutdown ( c ) ;
2001-07-04 11:36:09 +04:00
if ( ( p = strchr_m ( called . name , ' . ' ) ) ) {
2001-03-10 02:48:58 +03:00
* p = 0 ;
goto again ;
}
1999-12-13 16:27:58 +03:00
if ( strcmp ( called . name , " *SMBSERVER " ) ) {
2000-01-07 09:55:36 +03:00
make_nmb_name ( & called , " *SMBSERVER " , 0x20 ) ;
1999-12-13 16:27:58 +03:00
goto again ;
}
return NULL ;
}
2002-03-14 04:53:04 +03:00
DEBUG ( 4 , ( " %d: session request ok \n " , sys_getpid ( ) ) ) ;
1999-12-13 16:27:58 +03:00
if ( ! cli_negprot ( c ) ) {
2002-03-14 04:53:04 +03:00
DEBUG ( 0 , ( " %d: protocol negotiation failed \n " , sys_getpid ( ) ) ) ;
1999-12-13 16:27:58 +03:00
cli_shutdown ( c ) ;
return NULL ;
}
if ( ! got_pass ) {
char * pass = getpass ( " Password: " ) ;
if ( pass ) {
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( talloc_tos ( ) , pass ) ;
if ( ! password ) {
return NULL ;
}
1999-12-13 16:27:58 +03:00
}
}
2001-12-19 06:14:54 +03:00
/* This should be right for current smbfs. Future versions will support
large files as well as unicode and oplocks . */
2003-04-08 19:38:38 +04:00
c - > capabilities & = ~ ( CAP_NT_SMBS | CAP_NT_FIND | CAP_LEVEL_II_OPLOCKS ) ;
if ( ! smbfs_has_lfs )
c - > capabilities & = ~ CAP_LARGE_FILES ;
if ( ! smbfs_has_unicode )
c - > capabilities & = ~ CAP_UNICODE ;
if ( ! status32_smbfs ) {
c - > capabilities & = ~ CAP_STATUS32 ;
c - > force_dos_errors = True ;
2003-02-24 06:28:37 +03:00
}
2007-12-06 01:55:08 +03:00
c_password = password ? password : " " ;
c_username = username ? username : " " ;
if ( ! NT_STATUS_IS_OK ( cli_session_setup ( c ,
c_username ,
c_password , strlen ( c_password ) ,
c_password , strlen ( c_password ) ,
workgroup ) ) ) {
2001-09-21 01:06:02 +04:00
/* if a password was not supplied then try again with a
null username */
2007-12-06 01:55:08 +03:00
if ( c_password [ 0 ] | | ! c_username [ 0 ] | |
2006-08-16 21:33:47 +04:00
! NT_STATUS_IS_OK ( cli_session_setup ( c , " " , " " , 0 , " " , 0 , workgroup ) ) ) {
2001-09-21 01:06:02 +04:00
DEBUG ( 0 , ( " %d: session setup failed: %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , cli_errstr ( c ) ) ) ;
2001-09-21 01:06:02 +04:00
cli_shutdown ( c ) ;
return NULL ;
}
DEBUG ( 0 , ( " Anonymous login successful \n " ) ) ;
1999-12-13 16:27:58 +03:00
}
2002-03-14 04:53:04 +03:00
DEBUG ( 4 , ( " %d: session setup ok \n " , sys_getpid ( ) ) ) ;
1999-12-13 16:27:58 +03:00
if ( ! cli_send_tconX ( c , share , " ????? " ,
2007-12-06 01:55:08 +03:00
c_password , strlen ( c_password ) + 1 ) ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " %d: tree connect failed: %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , cli_errstr ( c ) ) ) ;
1999-12-13 16:27:58 +03:00
cli_shutdown ( c ) ;
return NULL ;
}
2002-03-14 04:53:04 +03:00
DEBUG ( 4 , ( " %d: tconx ok \n " , sys_getpid ( ) ) ) ;
1999-12-13 16:27:58 +03:00
got_pass = True ;
1999-02-15 02:15:54 +03:00
1999-12-13 16:27:58 +03:00
return c ;
1998-01-06 01:56:29 +03:00
}
1999-02-15 02:15:54 +03:00
/****************************************************************************
unmount smbfs ( this is a bailout routine to clean up if a reconnect fails )
Code blatently stolen from smbumount . c
- mhw -
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
static void smb_umount ( char * mount_point )
1999-02-15 02:15:54 +03:00
{
int fd ;
struct mntent * mnt ;
FILE * mtab ;
FILE * new_mtab ;
/* Programmers Note:
This routine only gets called to the scene of a disaster
to shoot the survivors . . . A connection that was working
has now apparently failed . We have an active mount point
( presumably ) that we need to dump . If we get errors along
the way - make some noise , but we are already turning out
the lights to exit anyways . . .
*/
if ( umount ( mount_point ) ! = 0 ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " %d: Could not umount %s: %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , mount_point , strerror ( errno ) ) ) ;
1999-02-15 02:15:54 +03:00
return ;
}
1999-12-13 16:27:58 +03:00
if ( ( fd = open ( MOUNTED " ~ " , O_RDWR | O_CREAT | O_EXCL , 0600 ) ) = = - 1 ) {
2002-03-14 04:53:04 +03:00
DEBUG ( 0 , ( " %d: Can't get " MOUNTED " ~ lock file " , sys_getpid ( ) ) ) ;
1999-02-15 02:15:54 +03:00
return ;
}
1999-12-13 16:27:58 +03:00
1999-02-15 02:15:54 +03:00
close ( fd ) ;
if ( ( mtab = setmntent ( MOUNTED , " r " ) ) = = NULL ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " %d: Can't open " MOUNTED " : %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , strerror ( errno ) ) ) ;
1999-02-15 02:15:54 +03:00
return ;
}
# define MOUNTED_TMP MOUNTED".tmp"
if ( ( new_mtab = setmntent ( MOUNTED_TMP , " w " ) ) = = NULL ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " %d: Can't open " MOUNTED_TMP " : %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , strerror ( errno ) ) ) ;
1999-02-15 02:15:54 +03:00
endmntent ( mtab ) ;
return ;
}
while ( ( mnt = getmntent ( mtab ) ) ! = NULL ) {
if ( strcmp ( mnt - > mnt_dir , mount_point ) ! = 0 ) {
addmntent ( new_mtab , mnt ) ;
}
}
endmntent ( mtab ) ;
if ( fchmod ( fileno ( new_mtab ) , S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ) < 0 ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " %d: Error changing mode of %s: %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , MOUNTED_TMP , strerror ( errno ) ) ) ;
1999-02-15 02:15:54 +03:00
return ;
}
endmntent ( new_mtab ) ;
if ( rename ( MOUNTED_TMP , MOUNTED ) < 0 ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " %d: Cannot rename %s to %s: %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , MOUNTED , MOUNTED_TMP , strerror ( errno ) ) ) ;
1999-02-15 02:15:54 +03:00
return ;
}
1999-12-13 16:27:58 +03:00
if ( unlink ( MOUNTED " ~ " ) = = - 1 ) {
2002-03-14 04:53:04 +03:00
DEBUG ( 0 , ( " %d: Can't remove " MOUNTED " ~ " , sys_getpid ( ) ) ) ;
1999-02-15 02:15:54 +03:00
return ;
}
}
1998-01-06 01:56:29 +03:00
/*
* Call the smbfs ioctl to install a connection socket ,
* then wait for a signal to reconnect . Note that we do
* not exit after open_sockets ( ) or send_login ( ) errors ,
* as the smbfs mount would then have no way to recover .
*/
2001-11-26 04:59:33 +03:00
static void send_fs_socket ( char * the_service , char * mount_point , struct cli_state * c )
1998-01-06 01:56:29 +03:00
{
int fd , closed = 0 , res = 1 ;
1999-02-01 00:28:55 +03:00
pid_t parentpid = getppid ( ) ;
1999-12-13 16:27:58 +03:00
struct smb_conn_opt conn_options ;
memset ( & conn_options , 0 , sizeof ( conn_options ) ) ;
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
while ( 1 ) {
if ( ( fd = open ( mount_point , O_RDONLY ) ) < 0 ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " mount.smbfs[%d]: can't open %s \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , mount_point ) ) ;
1998-01-06 01:56:29 +03:00
break ;
2001-03-10 02:48:58 +03:00
}
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
conn_options . fd = c - > fd ;
conn_options . protocol = c - > protocol ;
conn_options . case_handling = SMB_CASE_DEFAULT ;
conn_options . max_xmit = c - > max_xmit ;
conn_options . server_uid = c - > vuid ;
conn_options . tid = c - > cnum ;
conn_options . secmode = c - > sec_mode ;
conn_options . rawmode = 0 ;
conn_options . sesskey = c - > sesskey ;
conn_options . maxraw = 0 ;
conn_options . capabilities = c - > capabilities ;
conn_options . serverzone = c - > serverzone / 60 ;
1998-01-06 01:56:29 +03:00
res = ioctl ( fd , SMB_IOC_NEWCONN , & conn_options ) ;
1999-12-13 16:27:58 +03:00
if ( res ! = 0 ) {
2001-03-10 02:48:58 +03:00
DEBUG ( 0 , ( " mount.smbfs[%d]: ioctl failed, res=%d \n " ,
2002-03-14 04:53:04 +03:00
sys_getpid ( ) , res ) ) ;
2001-03-10 02:48:58 +03:00
close ( fd ) ;
1999-12-13 16:27:58 +03:00
break ;
1998-01-06 01:56:29 +03:00
}
1999-12-13 16:27:58 +03:00
if ( parentpid ) {
1999-02-01 00:28:55 +03:00
/* Ok... We are going to kill the parent. Now
is the time to break the process group . . . */
setsid ( ) ;
/* Send a signal to the parent to terminate */
1999-12-13 16:27:58 +03:00
kill ( parentpid , SIGTERM ) ;
1999-02-01 00:28:55 +03:00
parentpid = 0 ;
}
1998-01-06 01:56:29 +03:00
close ( fd ) ;
1999-12-13 16:27:58 +03:00
2001-03-10 02:48:58 +03:00
/* This looks wierd but we are only closing the userspace
side , the connection has already been passed to smbfs and
it has increased the usage count on the socket .
If we don ' t do this we will " leak " sockets and memory on
each reconnection we have to make . */
2007-11-05 05:14:16 +03:00
c - > smb_rw_error = SMB_DO_NOT_DO_TDIS ;
2001-03-10 02:48:58 +03:00
cli_shutdown ( c ) ;
2001-12-19 06:14:54 +03:00
c = NULL ;
2001-03-10 02:48:58 +03:00
1999-12-13 16:27:58 +03:00
if ( ! closed ) {
2006-01-13 21:45:30 +03:00
/* close the name cache so that close_our_files() doesn't steal its FD */
namecache_shutdown ( ) ;
2001-03-10 02:48:58 +03:00
/* redirect stdout & stderr since we can't know that
the library functions we use are using DEBUG . */
if ( ( fd = open ( " /dev/null " , O_WRONLY ) ) < 0 )
DEBUG ( 2 , ( " mount.smbfs: can't open /dev/null \n " ) ) ;
close_our_files ( fd ) ;
if ( fd > = 0 ) {
dup2 ( fd , STDOUT_FILENO ) ;
dup2 ( fd , STDERR_FILENO ) ;
close ( fd ) ;
}
/* here we are no longer interactive */
2003-03-18 12:52:55 +03:00
set_remote_machine_name ( " smbmount " , False ) ; /* sneaky ... */
2001-03-10 02:48:58 +03:00
setup_logging ( " mount.smbfs " , False ) ;
reopen_logs ( ) ;
2002-03-14 04:53:04 +03:00
DEBUG ( 0 , ( " mount.smbfs: entering daemon mode for service %s, pid=%d \n " , the_service , sys_getpid ( ) ) ) ;
2001-03-10 02:48:58 +03:00
1998-01-06 01:56:29 +03:00
closed = 1 ;
}
2001-03-10 02:48:58 +03:00
/* Wait for a signal from smbfs ... but don't continue
until we actually get a new connection . */
while ( ! c ) {
CatchSignal ( SIGUSR1 , & usr1_handler ) ;
pause ( ) ;
2002-03-14 04:53:04 +03:00
DEBUG ( 2 , ( " mount.smbfs[%d]: got signal, getting new socket \n " , sys_getpid ( ) ) ) ;
2001-11-26 04:59:33 +03:00
c = do_connection ( the_service ) ;
2001-03-10 02:48:58 +03:00
}
1999-12-13 16:27:58 +03:00
}
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
smb_umount ( mount_point ) ;
2002-03-14 04:53:04 +03:00
DEBUG ( 2 , ( " mount.smbfs[%d]: exit \n " , sys_getpid ( ) ) ) ;
1999-12-13 16:27:58 +03:00
exit ( 1 ) ;
}
1998-01-22 06:47:48 +03:00
1999-12-13 16:27:58 +03:00
2001-11-19 05:49:53 +03:00
/**
* Mount a smbfs
* */
2007-12-06 01:55:08 +03:00
# define NUM_ARGS 20
1999-12-13 16:27:58 +03:00
static void init_mount ( void )
1998-01-06 01:56:29 +03:00
{
2003-08-06 23:30:42 +04:00
char mount_point [ PATH_MAX + 1 ] ;
2007-12-06 01:55:08 +03:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
char * svc2 ;
1999-12-13 16:27:58 +03:00
struct cli_state * c ;
2007-12-06 01:55:08 +03:00
const char * args [ NUM_ARGS ] ;
1999-12-13 16:27:58 +03:00
int i , status ;
if ( realpath ( mpoint , mount_point ) = = NULL ) {
fprintf ( stderr , " Could not resolve mount point %s \n " , mpoint ) ;
1998-01-06 01:56:29 +03:00
return ;
}
1999-12-13 16:27:58 +03:00
c = do_connection ( service ) ;
if ( ! c ) {
fprintf ( stderr , " SMB connection failed \n " ) ;
exit ( 1 ) ;
1998-01-06 01:56:29 +03:00
}
1999-02-01 00:28:55 +03:00
/*
Set up to return as a daemon child and wait in the parent
until the child say it ' s ready . . .
*/
daemonize ( ) ;
2007-12-06 01:55:08 +03:00
svc2 = talloc_strdup ( ctx , service ) ;
if ( ! svc2 ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
string_replace ( svc2 , ' \\ ' , ' / ' ) ;
string_replace ( svc2 , ' ' , ' _ ' ) ;
2007-12-06 01:55:08 +03:00
memset ( args , 0 , sizeof ( args [ 0 ] ) * NUM_ARGS ) ;
1999-12-13 16:27:58 +03:00
i = 0 ;
args [ i + + ] = " smbmnt " ;
args [ i + + ] = mount_point ;
args [ i + + ] = " -s " ;
args [ i + + ] = svc2 ;
2007-12-06 01:55:08 +03:00
if ( mount_ro & & i < NUM_ARGS - 2 ) {
1999-12-13 16:27:58 +03:00
args [ i + + ] = " -r " ;
}
2007-12-06 01:55:08 +03:00
if ( mount_uid & & i < NUM_ARGS - 3 ) {
1999-12-13 16:27:58 +03:00
args [ i + + ] = " -u " ;
2007-12-06 01:55:08 +03:00
args [ i ] = talloc_asprintf ( ctx , " %d " , mount_uid ) ;
if ( ! args [ i ] ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
i + + ;
1999-12-13 16:27:58 +03:00
}
2007-12-06 01:55:08 +03:00
if ( mount_gid & & i < NUM_ARGS - 3 ) {
1999-12-13 16:27:58 +03:00
args [ i + + ] = " -g " ;
2007-12-06 01:55:08 +03:00
args [ i ] = talloc_asprintf ( ctx , " %d " , mount_gid ) ;
if ( ! args [ i ] ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
i + + ;
1999-12-13 16:27:58 +03:00
}
2007-12-06 01:55:08 +03:00
if ( mount_fmask & & i < NUM_ARGS - 3 ) {
1999-12-13 16:27:58 +03:00
args [ i + + ] = " -f " ;
2007-12-06 01:55:08 +03:00
args [ i ] = talloc_asprintf ( ctx , " 0%o " , mount_fmask ) ;
if ( ! args [ i ] ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
i + + ;
1999-12-13 16:27:58 +03:00
}
2007-12-06 01:55:08 +03:00
if ( mount_dmask & & i < NUM_ARGS - 3 ) {
1999-12-13 16:27:58 +03:00
args [ i + + ] = " -d " ;
2007-12-06 01:55:08 +03:00
args [ i ] = talloc_asprintf ( ctx , " 0%o " , mount_dmask ) ;
if ( ! args [ i ] ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
i + + ;
1999-12-13 16:27:58 +03:00
}
2007-12-06 01:55:08 +03:00
if ( options & & i < NUM_ARGS - 3 ) {
2001-03-10 02:48:58 +03:00
args [ i + + ] = " -o " ;
args [ i + + ] = options ;
}
1999-12-13 16:27:58 +03:00
2000-05-02 06:23:41 +04:00
if ( sys_fork ( ) = = 0 ) {
2001-11-19 05:49:53 +03:00
char * smbmnt_path ;
2007-12-10 22:30:37 +03:00
asprintf ( & smbmnt_path , " %s/smbmnt " , get_dyn_BINDIR ( ) ) ;
2007-12-06 01:55:08 +03:00
2001-11-19 05:49:53 +03:00
if ( file_exist ( smbmnt_path , NULL ) ) {
2007-10-15 03:16:01 +04:00
execv ( smbmnt_path , ( char * const * ) args ) ;
2001-11-19 05:49:53 +03:00
fprintf ( stderr ,
" smbfs/init_mount: execv of %s failed. Error was %s. " ,
smbmnt_path , strerror ( errno ) ) ;
1999-12-13 16:27:58 +03:00
} else {
2007-10-15 03:16:01 +04:00
execvp ( " smbmnt " , ( char * const * ) args ) ;
2001-11-19 05:49:53 +03:00
fprintf ( stderr ,
" smbfs/init_mount: execv of %s failed. Error was %s. " ,
" smbmnt " , strerror ( errno ) ) ;
1999-12-13 16:27:58 +03:00
}
2001-11-19 05:49:53 +03:00
free ( smbmnt_path ) ;
1999-12-13 16:27:58 +03:00
exit ( 1 ) ;
}
if ( waitpid ( - 1 , & status , 0 ) = = - 1 ) {
fprintf ( stderr , " waitpid failed: Error was %s " , strerror ( errno ) ) ;
/* FIXME: do some proper error handling */
1998-01-06 01:56:29 +03:00
exit ( 1 ) ;
2001-03-10 02:48:58 +03:00
}
1999-12-13 16:27:58 +03:00
if ( WIFEXITED ( status ) & & WEXITSTATUS ( status ) ! = 0 ) {
fprintf ( stderr , " smbmnt failed: %d \n " , WEXITSTATUS ( status ) ) ;
2001-03-10 02:48:58 +03:00
/* FIXME: do some proper error handling */
exit ( 1 ) ;
2003-02-24 06:28:37 +03:00
} else if ( WIFSIGNALED ( status ) ) {
fprintf ( stderr , " smbmnt killed by signal %d \n " , WTERMSIG ( status ) ) ;
exit ( 1 ) ;
1998-01-06 01:56:29 +03:00
}
1998-11-13 23:32:22 +03:00
1999-02-15 02:15:54 +03:00
/* Ok... This is the rubicon for that mount point... At any point
after this , if the connections fail and can not be reconstructed
for any reason , we will have to unmount the mount point . There
is no exit from the next call . . .
*/
1999-12-13 16:27:58 +03:00
send_fs_socket ( service , mount_point , c ) ;
1999-02-15 02:15:54 +03:00
}
1998-01-06 01:56:29 +03:00
2001-03-10 02:48:58 +03:00
/****************************************************************************
get a password from a a file or file descriptor
exit on failure ( from smbclient , move to libsmb or shared . c file ? )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-06 01:55:08 +03:00
2001-03-10 02:48:58 +03:00
static void get_password_file ( void )
{
int fd = - 1 ;
char * p ;
2007-10-19 04:40:25 +04:00
bool close_it = False ;
2007-12-10 22:30:37 +03:00
char * spec = NULL ;
2007-12-06 01:55:08 +03:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
2001-03-10 02:48:58 +03:00
char pass [ 128 ] ;
if ( ( p = getenv ( " PASSWD_FD " ) ) ! = NULL ) {
2007-12-06 01:55:08 +03:00
spec = talloc_asprintf ( ctx ,
" descriptor %s " ,
p ) ;
if ( ! spec ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
fd = atoi ( p ) ;
2001-03-10 02:48:58 +03:00
close_it = False ;
} else if ( ( p = getenv ( " PASSWD_FILE " ) ) ! = NULL ) {
fd = sys_open ( p , O_RDONLY , 0 ) ;
2007-12-06 01:55:08 +03:00
spec = talloc_strdup ( ctx , p ) ;
if ( ! spec ) {
fprintf ( stderr , " Out of memory. \n " ) ;
exit ( ENOMEM ) ;
}
2001-03-10 02:48:58 +03:00
if ( fd < 0 ) {
fprintf ( stderr , " Error opening PASSWD_FILE %s: %s \n " ,
spec , strerror ( errno ) ) ;
exit ( 1 ) ;
}
close_it = True ;
}
for ( p = pass , * p = ' \0 ' ; /* ensure that pass is null-terminated */
p & & p - pass < sizeof ( pass ) ; ) {
switch ( read ( fd , p , 1 ) ) {
case 1 :
if ( * p ! = ' \n ' & & * p ! = ' \0 ' ) {
* + + p = ' \0 ' ; /* advance p, and null-terminate pass */
break ;
}
case 0 :
if ( p - pass ) {
* p = ' \0 ' ; /* null-terminate it, just in case... */
p = NULL ; /* then force the loop condition to become false */
break ;
} else {
fprintf ( stderr , " Error reading password from file %s: %s \n " ,
spec , " empty password \n " ) ;
exit ( 1 ) ;
}
default :
fprintf ( stderr , " Error reading password from file %s: %s \n " ,
spec , strerror ( errno ) ) ;
exit ( 1 ) ;
}
}
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( ctx , pass ) ;
2001-03-10 02:48:58 +03:00
if ( close_it )
close ( fd ) ;
}
/****************************************************************************
get username and password from a credentials file
exit on failure ( from smbclient , move to libsmb or shared . c file ? )
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-12-06 01:55:08 +03:00
static void read_credentials_file ( const char * filename )
2001-03-10 02:48:58 +03:00
{
FILE * auth ;
fstring buf ;
uint16 len = 0 ;
char * ptr , * val , * param ;
if ( ( auth = sys_fopen ( filename , " r " ) ) = = NULL )
{
/* fail if we can't open the credentials file */
DEBUG ( 0 , ( " ERROR: Unable to open credentials file! \n " ) ) ;
exit ( - 1 ) ;
}
while ( ! feof ( auth ) )
{
/* get a line from the file */
if ( ! fgets ( buf , sizeof ( buf ) , auth ) )
continue ;
len = strlen ( buf ) ;
if ( ( len ) & & ( buf [ len - 1 ] = = ' \n ' ) )
{
buf [ len - 1 ] = ' \0 ' ;
len - - ;
}
if ( len = = 0 )
continue ;
/* break up the line into parameter & value.
will need to eat a little whitespace possibly */
param = buf ;
if ( ! ( ptr = strchr ( buf , ' = ' ) ) )
continue ;
val = ptr + 1 ;
* ptr = ' \0 ' ;
/* eat leading white space */
while ( ( * val ! = ' \0 ' ) & & ( ( * val = = ' ' ) | | ( * val = = ' \t ' ) ) )
val + + ;
if ( strwicmp ( " password " , param ) = = 0 )
{
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( talloc_tos ( ) , val ) ;
2001-03-10 02:48:58 +03:00
got_pass = True ;
}
2003-02-24 06:28:37 +03:00
else if ( strwicmp ( " username " , param ) = = 0 ) {
2007-12-06 01:55:08 +03:00
username = talloc_strdup ( talloc_tos ( ) , val ) ;
2003-02-24 06:28:37 +03:00
}
2001-03-10 02:48:58 +03:00
memset ( buf , 0 , sizeof ( buf ) ) ;
}
fclose ( auth ) ;
}
1998-01-06 01:56:29 +03:00
/****************************************************************************
1999-12-13 16:27:58 +03:00
usage on the program
1998-01-06 01:56:29 +03:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1999-12-13 16:27:58 +03:00
static void usage ( void )
1998-01-06 01:56:29 +03:00
{
1999-12-13 16:27:58 +03:00
printf ( " Usage: mount.smbfs service mountpoint [-o options,...] \n " ) ;
2003-08-20 21:13:38 +04:00
printf ( " Version %s \n \n " , SAMBA_VERSION_STRING ) ;
1999-12-13 16:27:58 +03:00
2007-06-25 15:45:54 +04:00
printf ( " Please be aware that smbfs is deprecated in favor of "
" cifs \n \n " ) ;
1999-12-13 16:27:58 +03:00
printf (
2001-12-19 06:14:54 +03:00
" Options: \n \
username = < arg > SMB username \ n \
password = < arg > SMB password \ n \
credentials = < filename > file with username / password \ n \
2003-02-24 06:28:37 +03:00
krb use kerberos ( active directory ) \ n \
2001-12-19 06:14:54 +03:00
netbiosname = < arg > source NetBIOS name \ n \
uid = < arg > mount uid or username \ n \
gid = < arg > mount gid or groupname \ n \
port = < arg > remote SMB port number \ n \
fmask = < arg > file umask \ n \
dmask = < arg > directory umask \ n \
debug = < arg > debug level \ n \
ip = < arg > destination host or IP address \ n \
workgroup = < arg > workgroup on destination \ n \
sockopt = < arg > TCP socket options \ n \
scope = < arg > NetBIOS scope \ n \
iocharset = < arg > Linux charset ( iso8859 - 1 , utf8 ) \ n \
codepage = < arg > server codepage ( cp850 ) \ n \
2003-04-08 19:38:38 +04:00
unicode use unicode when communicating with server \ n \
lfs large file system support \ n \
2001-12-19 06:14:54 +03:00
ttl = < arg > dircache time to live \ n \
guest don ' t prompt for a password \ n \
ro mount read - only \ n \
rw mount read - write \ n \
\ n \
This command is designed to be run from within / bin / mount by giving \ n \
the option ' - t smbfs ' . For example : \ n \
mount - t smbfs - o username = tridge , password = foobar / / fjall / test / data / test \ n \
1999-12-13 16:27:58 +03:00
" );
1998-01-06 01:56:29 +03:00
}
/****************************************************************************
1999-12-13 16:27:58 +03:00
Argument parsing for mount . smbfs interface
mount will call us like this :
mount . smbfs device mountpoint - o < options >
< options > is never empty , containing at least rw or ro
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static void parse_mount_smb ( int argc , char * * argv )
1998-01-06 01:56:29 +03:00
{
1999-12-13 16:27:58 +03:00
int opt ;
char * opts ;
char * opteq ;
int val ;
2007-12-06 01:55:08 +03:00
TALLOC_CTX * ctx = talloc_tos ( ) ;
1999-12-13 16:27:58 +03:00
2003-02-24 06:28:37 +03:00
/* FIXME: This function can silently fail if the arguments are
* not in the expected order .
> The arguments syntax of smbmount 2.2 .3 a ( smbfs of Debian stable )
> requires that one gives " -o " before further options like username = . . .
> . Without - o , the username = . . setting is * silently * ignored . I ' ve
> spent about an hour trying to find out why I couldn ' t log in now . .
*/
1999-12-13 16:27:58 +03:00
if ( argc < 2 | | argv [ 1 ] [ 0 ] = = ' - ' ) {
usage ( ) ;
exit ( 1 ) ;
}
2007-12-06 01:55:08 +03:00
service = talloc_strdup ( ctx , argv [ 1 ] ) ;
if ( ! service ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
mpoint = talloc_strdup ( ctx , argv [ 2 ] ) ;
if ( ! mpoint ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
/* Convert any '/' characters in the service name to
' \ ' characters */
string_replace ( service , ' / ' , ' \\ ' ) ;
argc - = 2 ;
argv + = 2 ;
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
opt = getopt ( argc , argv , " o: " ) ;
if ( opt ! = ' o ' ) {
return ;
}
1998-01-06 01:56:29 +03:00
2007-12-06 01:55:08 +03:00
options = talloc_strdup ( ctx , " " ) ;
if ( ! options ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
2001-03-10 02:48:58 +03:00
1999-12-13 16:27:58 +03:00
/*
* option parsing from nfsmount . c ( util - linux - 2.9 u )
*/
for ( opts = strtok ( optarg , " , " ) ; opts ; opts = strtok ( NULL , " , " ) ) {
DEBUG ( 3 , ( " opts: %s \n " , opts ) ) ;
2001-07-04 11:36:09 +04:00
if ( ( opteq = strchr_m ( opts , ' = ' ) ) ) {
1999-12-13 16:27:58 +03:00
val = atoi ( opteq + 1 ) ;
* opteq = ' \0 ' ;
2007-12-06 01:55:08 +03:00
if ( ! strcmp ( opts , " username " ) | |
1999-12-13 16:27:58 +03:00
! strcmp ( opts , " logon " ) ) {
char * lp ;
2003-02-24 06:28:37 +03:00
got_user = True ;
2007-12-06 01:55:08 +03:00
username = talloc_strdup ( ctx , opteq + 1 ) ;
if ( ! username ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
2001-07-04 11:36:09 +04:00
if ( ( lp = strchr_m ( username , ' % ' ) ) ) {
1999-12-13 16:27:58 +03:00
* lp = 0 ;
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( ctx , lp + 1 ) ;
if ( ! password ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
got_pass = True ;
2001-07-04 11:36:09 +04:00
memset ( strchr_m ( opteq + 1 , ' % ' ) + 1 , ' X ' , strlen ( password ) ) ;
1999-12-13 16:27:58 +03:00
}
2001-07-04 11:36:09 +04:00
if ( ( lp = strchr_m ( username , ' / ' ) ) ) {
1999-12-13 16:27:58 +03:00
* lp = 0 ;
2007-12-06 01:55:08 +03:00
fstrcpy ( workgroup , lp + 1 ) ;
1999-12-13 16:27:58 +03:00
}
} else if ( ! strcmp ( opts , " passwd " ) | |
! strcmp ( opts , " password " ) ) {
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( ctx , opteq + 1 ) ;
if ( ! password ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
got_pass = True ;
memset ( opteq + 1 , ' X ' , strlen ( password ) ) ;
2001-03-10 02:48:58 +03:00
} else if ( ! strcmp ( opts , " credentials " ) ) {
2007-12-06 01:55:08 +03:00
credentials = talloc_strdup ( ctx , opteq + 1 ) ;
if ( ! credentials ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
} else if ( ! strcmp ( opts , " netbiosname " ) ) {
2007-12-06 01:55:08 +03:00
fstrcpy ( my_netbios_name , opteq + 1 ) ;
1999-12-13 16:27:58 +03:00
} else if ( ! strcmp ( opts , " uid " ) ) {
mount_uid = nametouid ( opteq + 1 ) ;
} else if ( ! strcmp ( opts , " gid " ) ) {
mount_gid = nametogid ( opteq + 1 ) ;
} else if ( ! strcmp ( opts , " port " ) ) {
smb_port = val ;
} else if ( ! strcmp ( opts , " fmask " ) ) {
mount_fmask = strtol ( opteq + 1 , NULL , 8 ) ;
} else if ( ! strcmp ( opts , " dmask " ) ) {
mount_dmask = strtol ( opteq + 1 , NULL , 8 ) ;
} else if ( ! strcmp ( opts , " debug " ) ) {
DEBUGLEVEL = val ;
} else if ( ! strcmp ( opts , " ip " ) ) {
2007-10-27 23:15:07 +04:00
if ( ! interpret_string_addr ( & dest_ip , opteq + 1 ,
0 ) ) {
1999-12-13 16:27:58 +03:00
fprintf ( stderr , " Can't resolve address %s \n " , opteq + 1 ) ;
exit ( 1 ) ;
}
have_ip = True ;
} else if ( ! strcmp ( opts , " workgroup " ) ) {
2007-12-06 01:55:08 +03:00
fstrcpy ( workgroup , opteq + 1 ) ;
1999-12-13 16:27:58 +03:00
} else if ( ! strcmp ( opts , " sockopt " ) ) {
2007-11-01 20:13:00 +03:00
lp_do_parameter ( - 1 , " socket options " , opteq + 1 ) ;
1999-12-13 16:27:58 +03:00
} else if ( ! strcmp ( opts , " scope " ) ) {
2002-11-13 05:22:39 +03:00
set_global_scope ( opteq + 1 ) ;
1999-12-13 16:27:58 +03:00
} else {
2007-12-06 01:55:08 +03:00
options = talloc_asprintf_append ( options ,
" %s=%s, " ,
opts , opteq + 1 ) ;
if ( ! options ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
}
} else {
val = 1 ;
if ( ! strcmp ( opts , " nocaps " ) ) {
fprintf ( stderr , " Unhandled option: %s \n " , opteq + 1 ) ;
exit ( 1 ) ;
} else if ( ! strcmp ( opts , " guest " ) ) {
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( talloc_tos ( ) , " " ) ;
if ( ! password ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
got_pass = True ;
2003-02-24 06:28:37 +03:00
} else if ( ! strcmp ( opts , " krb " ) ) {
# ifdef HAVE_KRB5
use_kerberos = True ;
if ( ! status32_smbfs )
fprintf ( stderr , " Warning: kerberos support will only work for samba servers \n " ) ;
# else
fprintf ( stderr , " No kerberos support compiled in \n " ) ;
exit ( 1 ) ;
# endif
1999-12-13 16:27:58 +03:00
} else if ( ! strcmp ( opts , " rw " ) ) {
mount_ro = 0 ;
} else if ( ! strcmp ( opts , " ro " ) ) {
mount_ro = 1 ;
2003-04-08 19:38:38 +04:00
} else if ( ! strcmp ( opts , " unicode " ) ) {
smbfs_has_unicode = True ;
} else if ( ! strcmp ( opts , " lfs " ) ) {
smbfs_has_lfs = True ;
2001-03-10 02:48:58 +03:00
} else {
2007-12-06 01:55:08 +03:00
options = talloc_asprintf_append ( options ,
" %s, " ,
opts ) ;
if ( ! options ) {
fprintf ( stderr , " Out of memory \n " ) ;
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
}
}
}
2007-12-06 01:55:08 +03:00
if ( ! service | | ! * service ) {
1999-12-13 16:27:58 +03:00
usage ( ) ;
exit ( 1 ) ;
}
2001-03-10 02:48:58 +03:00
2007-12-06 01:55:08 +03:00
if ( options & & * options & & options [ strlen ( options ) - 1 ] = = ' , ' ) {
options [ strlen ( options ) - 1 ] = ' \0 ' ; /* remove trailing , */
2001-03-10 02:48:58 +03:00
DEBUG ( 3 , ( " passthrough options '%s' \n " , options ) ) ;
}
1998-01-06 01:56:29 +03:00
}
/****************************************************************************
main program
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int main ( int argc , char * argv [ ] )
{
2007-11-21 04:54:01 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
1999-12-13 16:27:58 +03:00
char * p ;
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
DEBUGLEVEL = 1 ;
2001-03-10 02:48:58 +03:00
2006-02-13 07:58:13 +03:00
load_case_tables ( ) ;
2001-03-10 02:48:58 +03:00
/* here we are interactive, even if run from autofs */
1999-12-13 16:27:58 +03:00
setup_logging ( " mount.smbfs " , True ) ;
1998-01-06 01:56:29 +03:00
2001-12-19 06:14:54 +03:00
#if 0 /* JRA - Urban says not needed ? */
2001-09-21 01:06:02 +04:00
/* CLI_FORCE_ASCII=false makes smbmount negotiate unicode. The default
is to not announce any unicode capabilities as current smbfs does
not support it . */
p = getenv ( " CLI_FORCE_ASCII " ) ;
if ( p & & ! strcmp ( p , " false " ) )
unsetenv ( " CLI_FORCE_ASCII " ) ;
else
setenv ( " CLI_FORCE_ASCII " , " true " , 1 ) ;
2001-12-19 06:14:54 +03:00
# endif
2001-09-21 01:06:02 +04:00
1999-12-13 16:27:58 +03:00
in_client = True ; /* Make sure that we tell lp_load we are */
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
if ( getenv ( " USER " ) ) {
2007-12-06 01:55:08 +03:00
username = talloc_strdup ( frame , getenv ( " USER " ) ) ;
if ( ! username ) {
exit ( ENOMEM ) ;
}
1998-01-06 01:56:29 +03:00
2001-07-04 11:36:09 +04:00
if ( ( p = strchr_m ( username , ' % ' ) ) ) {
1999-12-13 16:27:58 +03:00
* p = 0 ;
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( frame , p + 1 ) ;
if ( ! password ) {
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
got_pass = True ;
2001-07-04 11:36:09 +04:00
memset ( strchr_m ( getenv ( " USER " ) , ' % ' ) + 1 , ' X ' , strlen ( password ) ) ;
1999-12-13 16:27:58 +03:00
}
2003-07-04 22:52:31 +04:00
strupper_m ( username ) ;
1999-12-13 16:27:58 +03:00
}
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
if ( getenv ( " PASSWD " ) ) {
2007-12-06 01:55:08 +03:00
password = talloc_strdup ( frame , getenv ( " PASSWD " ) ) ;
if ( ! password ) {
exit ( ENOMEM ) ;
}
2001-03-10 02:48:58 +03:00
got_pass = True ;
}
if ( getenv ( " PASSWD_FD " ) | | getenv ( " PASSWD_FILE " ) ) {
get_password_file ( ) ;
got_pass = True ;
1999-12-13 16:27:58 +03:00
}
1998-01-06 01:56:29 +03:00
2007-12-06 01:55:08 +03:00
if ( ( ! username | | * username = = 0 ) & & getenv ( " LOGNAME " ) ) {
username = talloc_strdup ( frame , getenv ( " LOGNAME " ) ) ;
if ( ! username ) {
exit ( ENOMEM ) ;
}
1999-12-13 16:27:58 +03:00
}
2007-12-10 22:30:37 +03:00
if ( ! lp_load ( get_dyn_CONFIGFILE ( ) , True , False , False , True ) ) {
1999-12-13 16:27:58 +03:00
fprintf ( stderr , " Can't load %s - run testparm to debug it \n " ,
2007-12-10 22:30:37 +03:00
get_dyn_CONFIGFILE ( ) ) ;
1999-12-13 16:27:58 +03:00
}
1998-01-06 01:56:29 +03:00
2001-03-10 02:48:58 +03:00
parse_mount_smb ( argc , argv ) ;
2003-02-24 06:28:37 +03:00
if ( use_kerberos & & ! got_user ) {
got_pass = True ;
}
2007-12-06 01:55:08 +03:00
if ( credentials & & * credentials ! = 0 ) {
2001-03-10 02:48:58 +03:00
read_credentials_file ( credentials ) ;
}
2003-08-20 21:13:38 +04:00
DEBUG ( 3 , ( " mount.smbfs started (version %s) \n " , SAMBA_VERSION_STRING ) ) ;
2001-03-10 02:48:58 +03:00
1999-12-13 16:27:58 +03:00
if ( * workgroup = = 0 ) {
2007-12-06 01:55:08 +03:00
fstrcpy ( workgroup , lp_workgroup ( ) ) ;
1999-12-13 16:27:58 +03:00
}
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
load_interfaces ( ) ;
if ( ! * my_netbios_name ) {
2007-12-06 01:55:08 +03:00
fstrcpy ( my_netbios_name , myhostname ( ) ) ;
1998-01-06 01:56:29 +03:00
}
2003-07-04 22:52:31 +04:00
strupper_m ( my_netbios_name ) ;
1998-01-06 01:56:29 +03:00
1999-12-13 16:27:58 +03:00
init_mount ( ) ;
2007-11-21 04:54:01 +03:00
TALLOC_FREE ( frame ) ;
1999-12-13 16:27:58 +03:00
return 0 ;
1998-01-06 01:56:29 +03:00
}