Directory listing in libsmbclient.so

Michael B. Allen mballen at erols.com
Wed Dec 27 06:49:06 GMT 2000


On Tue, Dec 26, 2000 at 10:46:12PM +1000, Richard Sharpe wrote:
> Does anyone have any comments on this ...

At one time thought about this for jcifs, although we do not support it
yet, is if the path points to a file it is resolved. If the path is to
a directory(or share) do a TRANS2_FIND_FIRST2/NEXT2. If the path does
not include the share do a NetShareEnum. If only smb:// is specified
list names of servers from the master browser(or perhaps broadcast a
node status but that might be rather rude).

Also, jcifs uses the following syntax to specify a resource as a URL:

smb://domain\user:password@host:port/share/dir/file

but someone suggested that a domain is different from a
workgroup? Programmatically maybe but in practice is it profitable to
differentiate the two?

This is the parsing routine. It's Java but this kind of stuff translates
fairly well into c. Just thought this might help in some way.

Mike

    int port;
    String host, domain, user, password

    SmbURL( String url, String name, int start, int limit ) {
        int s = url.indexOf( '/', start + 2 );
        if( s == -1 ) {
            s = limit;
        }
        int a = url.lastIndexOf( '@', s ); // back from s incase @ in pw
        int p = url.lastIndexOf( ':', s );
        int h = Math.max( a + 1, start + 2 );

        if( p > h ) { 
            port = Integer.parseInt( url.substring( p + 1, s ));
        }
        host = url.substring( h, ( p > h ? p : s )); 

        if( a != -1 ) {
            int c = url.indexOf( ':', start + 3 );
            if( c != -1 ) {
                password = url.substring( c + 1, a ); 
                a = c;
            }
            int b = url.indexOf( '\\', start + 3 );
            if( b != -1 && b < a ) { 
                domain = url.substring( start + 2, b ); 
            } else {
                b = start + 1;
            }
            if( a > b ) { 
                username = url.substring( b + 1, a ); 
            }
        }


-- 
signature pending




More information about the samba-technical mailing list