static int smb_connect( stream_t *p_access, const char *psz_login, const char *psz_password, const char *psz_domain) { access_sys_t *p_sys = p_access->p_sys; smb_session_set_creds( p_sys->p_session, psz_domain, psz_login, psz_password ); if( smb_session_login( p_sys->p_session ) == DSM_SUCCESS ) { if( p_sys->psz_share ) { /* Connect to the share */ if( smb_tree_connect( p_sys->p_session, p_sys->psz_share, &p_sys->i_tid ) != DSM_SUCCESS ) return VLC_EGENERIC; /* Let's finally ask a handle to the file we wanna read ! */ return smb_fopen( p_sys->p_session, p_sys->i_tid, p_sys->psz_path, SMB_MOD_RO, &p_sys->i_fd ) == DSM_SUCCESS ? VLC_SUCCESS : VLC_EGENERIC; } else return VLC_SUCCESS; } else return VLC_EGENERIC; }
static int smb_connect( access_t *p_access, const char *psz_login, const char *psz_password, const char *psz_domain ) { access_sys_t *p_sys = p_access->p_sys; smb_session_set_creds( p_sys->p_session, psz_domain, psz_login, psz_password ); if( smb_session_login( p_sys->p_session ) ) { if( p_sys->psz_share ) { /* Connect to the share */ p_sys->i_tid = smb_tree_connect( p_sys->p_session, p_sys->psz_share ); if( !p_sys->i_tid ) return VLC_EGENERIC; /* Let's finally ask a handle to the file we wanna read ! */ p_sys->i_fd = smb_fopen( p_sys->p_session, p_sys->i_tid, p_sys->psz_path, SMB_MOD_RO ); /* TODO: fix smb_fopen to return a specific error code in case of * wrong permissions */ return p_sys->i_fd > 0 ? VLC_SUCCESS : VLC_EGENERIC; } else return VLC_SUCCESS; } else return VLC_EGENERIC; }
int main() { struct in_addr addr; smb_session *session; smb_tid tid; smb_fd fd; session = smb_session_new(); if (session == NULL) exit(1); inet_aton("127.0.0.1", &addr.sin_addr); if (smb_session_connect(session, "MYNAME", addr.sin_addr.s_addr, SMB_TRANSPORT_TCP)) { printf("Unable to connect to host\n"); exit(2); } smb_session_set_creds(session, "MYNAME", "login", "password"); if (smb_session_login(session)) { if (session->guest) printf("Logged in as GUEST \n"); else printf("Successfully logged in\n"); } else { printf("Auth failed\n"); exit(3); } tid = smb_tree_connect(session, "MyShare"); if (!tid) { printf("Unable to connect to share\n"); exit(4); } fd = smb_fopen(session, tid, "\\My\\File"); if (!fd) { printf("Unable to open file\n"); exit(5); } char buffer[512]; smb_fread(session, fd, buffer, 512); /* Use data */ smb_fclose(session, fd); smb_tree_disconnect(session, tid); smb_session_destroy(session); return(0); }
static int smb_connect( access_t *p_access ) { access_sys_t *p_sys = p_access->p_sys; const char *psz_login = p_sys->creds.login ? p_sys->creds.login : "******"; const char *psz_password = p_sys->creds.password ? p_sys->creds.password : "******"; const char *psz_domain = p_sys->creds.domain ? p_sys->creds.domain : p_sys->netbios_name; smb_session_set_creds( p_sys->p_session, psz_domain, psz_login, psz_password ); if( smb_session_login( p_sys->p_session ) ) { if( p_sys->psz_share ) { /* Connect to the share */ p_sys->i_tid = smb_tree_connect( p_sys->p_session, p_sys->psz_share ); if( !p_sys->i_tid ) return VLC_EGENERIC; } return VLC_SUCCESS; } else return VLC_EGENERIC; }