2
2
* smb.c: SMB input module
3
3
*****************************************************************************
4
4
* Copyright (C) 2001-2004 the VideoLAN team
5
* $Id: 1a39e0645f8fa3dfd82a714fff31586268cbcd40 $
7
7
* Authors: Gildas Bazin <gbazin@videolan.org>
73
78
vlc_module_begin();
74
79
set_shortname( "SMB" );
75
set_description( _("SMB input") );
76
set_capability( "access2", 0 );
80
set_description( N_("SMB input") );
81
set_capability( "access", 0 );
77
82
set_category( CAT_INPUT );
78
83
set_subcategory( SUBCAT_INPUT_ACCESS );
79
84
add_integer( "smb-caching", 2 * DEFAULT_PTS_DELAY / 1000, NULL,
80
CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
85
CACHING_TEXT, CACHING_LONGTEXT, true );
81
86
add_string( "smb-user", NULL, NULL, USER_TEXT, USER_LONGTEXT,
83
88
add_string( "smb-pwd", NULL, NULL, PASS_TEXT,
84
PASS_LONGTEXT, VLC_FALSE );
89
PASS_LONGTEXT, false );
85
90
add_string( "smb-domain", NULL, NULL, DOMAIN_TEXT,
86
DOMAIN_LONGTEXT, VLC_FALSE );
91
DOMAIN_LONGTEXT, false );
87
92
add_shortcut( "smb" );
88
93
set_callbacks( Open, Close );
91
96
/*****************************************************************************
93
98
*****************************************************************************/
94
static int Read( access_t *, uint8_t *, int );
99
static ssize_t Read( access_t *, uint8_t *, size_t );
95
100
static int Seek( access_t *, int64_t );
96
101
static int Control( access_t *, int, va_list );
109
114
static void Win32AddConnection( access_t *, char *, char *, char *, char * );
112
void smb_auth( const char *srv, const char *shr, char *wg, int wglen,
113
char *un, int unlen, char *pw, int pwlen )
116
static void smb_auth( const char *srv, const char *shr, char *wg, int wglen,
117
char *un, int unlen, char *pw, int pwlen )
115
119
//wglen = unlen = pwlen = 0;
118
123
/****************************************************************************
119
124
* Open: connect to smb server and ask for file
187
192
if( psz_user && !*psz_user ) { free( psz_user ); psz_user = 0; }
188
193
if( !psz_pwd ) psz_pwd = var_CreateGetString( p_access, "smb-pwd" );
189
194
if( psz_pwd && !*psz_pwd ) { free( psz_pwd ); psz_pwd = 0; }
190
if(!psz_domain) psz_domain = var_CreateGetString( p_access, "smb-domain" );
195
if( !psz_domain ) psz_domain = var_CreateGetString( p_access, "smb-domain" );
191
196
if( psz_domain && !*psz_domain ) { free( psz_domain ); psz_domain = 0; }
195
200
Win32AddConnection( p_access, psz_path, psz_user, psz_pwd, psz_domain);
196
asprintf( &psz_uri, "//%s", psz_path );
201
i_ret = asprintf( &psz_uri, "//%s", psz_path );
199
asprintf( &psz_uri, "smb://%s%s%s%s%s@%s",
200
psz_domain ? psz_domain : "", psz_domain ? ";" : "",
201
psz_user, psz_pwd ? ":" : "",
202
psz_pwd ? psz_pwd : "", psz_path );
204
i_ret = asprintf( &psz_uri, "smb://%s%s%s%s%s@%s",
205
psz_domain ? psz_domain : "", psz_domain ? ";" : "",
206
psz_user, psz_pwd ? ":" : "",
207
psz_pwd ? psz_pwd : "", psz_path );
204
asprintf( &psz_uri, "smb://%s", psz_path );
209
i_ret = asprintf( &psz_uri, "smb://%s", psz_path );
207
if( psz_user ) free( psz_user );
208
if( psz_pwd ) free( psz_pwd );
209
if( psz_domain ) free( psz_domain );
212
220
if( !(p_smb = smbc_new_context()) )
214
msg_Err( p_access, "out of memory" );
216
223
return VLC_ENOMEM;
221
228
if( !smbc_init_context( p_smb ) )
223
msg_Err( p_access, "cannot initialize context (%s)", strerror(errno) );
230
msg_Err( p_access, "cannot initialize context (%m)" );
224
231
smbc_free_context( p_smb, 1 );
226
233
return VLC_EGENERIC;
229
236
if( !(p_file = (p_smb->open)( p_smb, psz_uri, O_RDONLY, 0 )) )
231
msg_Err( p_access, "open failed for '%s' (%s)",
232
p_access->psz_path, strerror(errno) );
238
msg_Err( p_access, "open failed for '%s' (%m)",
239
p_access->psz_path );
233
240
smbc_free_context( p_smb, 1 );
235
242
return VLC_EGENERIC;
238
p_access->info.i_size = 0;
246
STANDARD_READ_ACCESS_INIT;
239
248
i_ret = p_smb->fstat( p_smb, p_file, &filestat );
240
if( i_ret ) msg_Err( p_access, "stat failed (%s)", strerror(errno) );
249
if( i_ret ) msg_Err( p_access, "stat failed (%m)" );
241
250
else p_access->info.i_size = filestat.st_size;
261
269
if( (i_smb = smbc_open( psz_uri, O_RDONLY, 0 )) < 0 )
263
msg_Err( p_access, "open failed for '%s' (%s)",
264
p_access->psz_path, strerror(errno) );
271
msg_Err( p_access, "open failed for '%s' (%m)",
272
p_access->psz_path );
266
274
return VLC_EGENERIC;
269
p_access->info.i_size = 0;
278
STANDARD_READ_ACCESS_INIT;
270
280
i_ret = smbc_fstat( i_smb, &filestat );
271
if( i_ret ) msg_Err( p_access, "stat failed (%s)", strerror(i_ret) );
284
msg_Err( p_access, "stat failed (%m)" );
272
286
else p_access->info.i_size = filestat.st_size;
278
p_access->pf_read = Read;
279
p_access->pf_block = NULL;
280
p_access->pf_seek = Seek;
281
p_access->pf_control = Control;
282
p_access->info.i_update = 0;
283
p_access->info.i_pos = 0;
284
p_access->info.b_eof = VLC_FALSE;
285
p_access->info.i_title = 0;
286
p_access->info.i_seekpoint = 0;
287
p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
288
memset( p_sys, 0, sizeof( access_sys_t ) );
291
292
p_sys->p_smb = p_smb;
292
293
p_sys->p_file = p_file;
333
334
if( i_pos < 0 ) return VLC_EGENERIC;
335
msg_Dbg( p_access, "seeking to "I64Fd, i_pos );
336
msg_Dbg( p_access, "seeking to %"PRId64, i_pos );
338
339
i_ret = p_sys->p_smb->lseek(p_sys->p_smb, p_sys->p_file, i_pos, SEEK_SET);
342
343
if( i_ret == -1 )
344
msg_Err( p_access, "seek failed (%s)", strerror(errno) );
345
msg_Err( p_access, "seek failed (%m)" );
345
346
return VLC_EGENERIC;
348
p_access->info.b_eof = VLC_FALSE;
349
p_access->info.b_eof = false;
349
350
p_access->info.i_pos = i_ret;
351
352
return VLC_SUCCESS;
354
355
/*****************************************************************************
356
357
*****************************************************************************/
357
static int Read( access_t *p_access, uint8_t *p_buffer, int i_len )
358
static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
359
360
access_sys_t *p_sys = p_access->p_sys;
371
msg_Err( p_access, "read failed (%s)", strerror(errno) );
372
msg_Err( p_access, "read failed (%m)" );
375
if( i_read == 0 ) p_access->info.b_eof = VLC_TRUE;
376
if( i_read == 0 ) p_access->info.b_eof = true;
376
377
else if( i_read > 0 ) p_access->info.i_pos += i_read;
383
384
*****************************************************************************/
384
385
static int Control( access_t *p_access, int i_query, va_list args )
390
391
switch( i_query )
392
393
case ACCESS_CAN_SEEK:
393
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
394
pb_bool = (bool*)va_arg( args, bool* );
396
397
case ACCESS_CAN_FASTSEEK:
397
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
398
pb_bool = (bool*)va_arg( args, bool* );
400
401
case ACCESS_CAN_PAUSE:
401
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
402
pb_bool = (bool*)va_arg( args, bool* );
404
405
case ACCESS_CAN_CONTROL_PACE:
405
pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
406
pb_bool = (bool*)va_arg( args, bool* );
409
410
case ACCESS_GET_MTU:
485
488
msg_Dbg( p_access, "connected to %s", psz_remote );
487
else if( i_result != ERROR_ALREADY_ASSIGNED &&
490
else if( i_result != ERROR_ALREADY_ASSIGNED &&
488
491
i_result != ERROR_DEVICE_ALREADY_REMEMBERED )
490
493
msg_Dbg( p_access, "already connected to %s", psz_remote );