Changeset 1227d46e2e899fdfcbfdd42812374171f137adc8
- Timestamp:
- 27/01/05 16:44:34 (4 years ago)
- git-parent:
- Files:
-
- configure.ac (modified) (1 diff)
- modules/access/smb.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
configure.ac
r0e27492 r1227d46 978 978 VLC_ADD_PLUGINS([screensaver]) 979 979 else 980 VLC_ADD_PLUGINS([ntservice]) 981 VLC_ADD_PLUGINS([dmo]) 980 VLC_ADD_PLUGINS([ntservice smb dmo]) 982 981 VLC_ADD_LDFLAGS([dmo],[-lole32]) 983 982 fi modules/access/smb.c
r0e27492 r1227d46 30 30 #include <vlc/input.h> 31 31 32 #include <libsmbclient.h> 33 #define USE_CTX 1 32 #ifdef WIN32 33 #ifdef HAVE_FCNTL_H 34 # include <fcntl.h> 35 #endif 36 # ifdef HAVE_SYS_STAT_H 37 # include <sys/stat.h> 38 # endif 39 # include <io.h> 40 # define smbc_open(a,b,c) open(a,b,c) 41 # define stat _stati64 42 # define smbc_fstat(a,b) _fstati64(a,b) 43 # define smbc_read read 44 # define smbc_lseek _lseeki64 45 # define smbc_close close 46 #else 47 # include <libsmbclient.h> 48 # define USE_CTX 1 49 #endif 34 50 35 51 /***************************************************************************** … … 88 104 }; 89 105 106 #ifdef WIN32 107 static void Win32AddConnection( access_t *, char *, char *, char *, char * ); 108 #endif 109 90 110 void smb_auth( const char *srv, const char *shr, char *wg, int wglen, 91 111 char *un, int unlen, char *pw, int pwlen ) … … 102 122 access_sys_t *p_sys; 103 123 struct stat filestat; 104 char *psz_uri, *psz_user, *psz_pwd, *psz_domain; 124 char *psz_path, *psz_uri; 125 char *psz_user = 0, *psz_pwd = 0, *psz_domain = 0; 105 126 int i_ret; 106 127 … … 112 133 #endif 113 134 135 /* Parse input URI 136 * [[[domain;]user[:password@]]server[/share[/path[/file]]]] */ 137 138 psz_path = strchr( p_access->psz_path, '/' ); 139 if( !psz_path ) 140 { 141 msg_Err( p_access, "invalid SMB URI: smb://%s", psz_path ); 142 return VLC_EGENERIC; 143 } 144 else 145 { 146 char *psz_tmp = strdup( p_access->psz_path ); 147 char *psz_parser; 148 149 psz_tmp[ psz_path - p_access->psz_path ] = 0; 150 psz_path = p_access->psz_path; 151 psz_parser = strchr( psz_tmp, '@' ); 152 if( psz_parser ) 153 { 154 /* User info is there */ 155 *psz_parser = 0; 156 psz_path = p_access->psz_path + (psz_parser - psz_tmp) + 1; 157 158 psz_parser = strchr( psz_tmp, ':' ); 159 if( psz_parser ) 160 { 161 /* Password found */ 162 psz_pwd = strdup( psz_parser+1 ); 163 *psz_parser = 0; 164 } 165 166 psz_parser = strchr( psz_tmp, ';' ); 167 if( psz_parser ) 168 { 169 /* Domain found */ 170 *psz_parser = 0; psz_parser++; 171 psz_domain = strdup( psz_tmp ); 172 } 173 else psz_parser = psz_tmp; 174 175 psz_user = strdup( psz_parser ); 176 } 177 178 free( psz_tmp ); 179 } 180 114 181 /* Build an SMB URI 115 182 * smb://[[[domain;]user[:password@]]server[/share[/path[/file]]]] */ 116 183 117 psz_user = var_CreateGetString( p_access, "smb-user" );184 if( !psz_user ) psz_user = var_CreateGetString( p_access, "smb-user" ); 118 185 if( psz_user && !*psz_user ) { free( psz_user ); psz_user = 0; } 119 psz_pwd = var_CreateGetString( p_access, "smb-pwd" );186 if( !psz_pwd ) psz_pwd = var_CreateGetString( p_access, "smb-pwd" ); 120 187 if( psz_pwd && !*psz_pwd ) { free( psz_pwd ); psz_pwd = 0; } 121 psz_domain = var_CreateGetString( p_access, "smb-domain" );188 if(!psz_domain) psz_domain = var_CreateGetString( p_access, "smb-domain" ); 122 189 if( psz_domain && !*psz_domain ) { free( psz_domain ); psz_domain = 0; } 123 190 124 /* FIXME: will need to parse the URI so we don't override credentials 125 * if there are already present. */ 191 #ifdef WIN32 192 if( psz_user ) 193 Win32AddConnection( p_access, psz_path, psz_user, psz_pwd, psz_domain); 194 asprintf( &psz_uri, "//%s", psz_path ); 195 #else 126 196 if( psz_user ) 127 197 asprintf( &psz_uri, "smb://%s%s%s%s%s@%s", 128 198 psz_domain ? psz_domain : "", psz_domain ? ";" : "", 129 199 psz_user, psz_pwd ? ":" : "", 130 psz_pwd ? psz_pwd : "", p _access->psz_path );200 psz_pwd ? psz_pwd : "", psz_path ); 131 201 else 132 asprintf( &psz_uri, "smb://%s", p_access->psz_path ); 202 asprintf( &psz_uri, "smb://%s", psz_path ); 203 #endif 133 204 134 205 if( psz_user ) free( psz_user ); … … 169 240 170 241 #else 242 243 #ifndef WIN32 171 244 if( smbc_init( smb_auth, 1 ) ) 172 245 { … … 174 247 return VLC_EGENERIC; 175 248 } 249 #endif 176 250 177 251 if( (i_smb = smbc_open( psz_uri, O_RDONLY, 0 )) < 0 ) … … 347 421 return VLC_SUCCESS; 348 422 } 423 424 #ifdef WIN32 425 static void Win32AddConnection( access_t *p_access, char *psz_path, 426 char *psz_user, char *psz_pwd, 427 char *psz_domain ) 428 { 429 DWORD (*OurWNetAddConnection2)( LPNETRESOURCE, LPCTSTR, LPCTSTR, DWORD ); 430 char psz_remote[MAX_PATH], psz_server[MAX_PATH], psz_share[MAX_PATH]; 431 NETRESOURCE net_resource; 432 DWORD i_result; 433 char *psz_parser; 434 435 HINSTANCE hdll = LoadLibrary(_T("MPR.DLL")); 436 if( !hdll ) 437 { 438 msg_Warn( p_access, "couldn't load mpr.dll" ); 439 return; 440 } 441 442 OurWNetAddConnection2 = 443 (void *)GetProcAddress( hdll, _T("WNetAddConnection2A") ); 444 if( !OurWNetAddConnection2 ) 445 { 446 msg_Warn( p_access, "couldn't find WNetAddConnection2 in mpr.dll" ); 447 return; 448 } 449 450 memset( &net_resource, 0, sizeof(net_resource) ); 451 net_resource.dwType = RESOURCETYPE_DISK; 452 453 /* Find out server and share names */ 454 psz_server[0] = psz_share[0] = 0; 455 psz_parser = strchr( psz_path, '/' ); 456 if( psz_parser ) 457 { 458 char *psz_parser2; 459 strncat( psz_server, psz_path, psz_parser - psz_path ); 460 psz_parser2 = strchr( psz_parser+1, '/' ); 461 if( psz_parser2 ) 462 strncat( psz_share, psz_parser+1, psz_parser2 - psz_parser -1 ); 463 } 464 else strncat( psz_server, psz_path, MAX_PATH ); 465 466 sprintf( psz_remote, "\\\\%s\\%s", psz_server, psz_share ); 467 net_resource.lpRemoteName = psz_remote; 468 469 i_result = OurWNetAddConnection2( &net_resource, psz_pwd, psz_user, 0 ); 470 471 if( i_result != NO_ERROR ) 472 { 473 msg_Dbg( p_access, "connected to %s", psz_remote ); 474 } 475 else if( i_result != ERROR_ALREADY_ASSIGNED && 476 i_result != ERROR_DEVICE_ALREADY_REMEMBERED ) 477 { 478 msg_Dbg( p_access, "already connected to %s", psz_remote ); 479 } 480 else 481 { 482 msg_Dbg( p_access, "failed to connect to %s", psz_remote ); 483 } 484 485 FreeLibrary( hdll ); 486 } 487 #endif // WIN32
