Reporting a bug on NtlmPasswordAuthentication when using Android

paulo louro <[email protected]>
Newsgroups gmane.network.samba.java
Message-ID <[email protected]>
Hello,
I hope this is the right way to report a bug, if not my apologies.
The problem is related with the implementation of the string.indexOf('@') method on Android API.

In the function NtlmPasswordAuthentication in the jcifs.smb.NtlmPasswordAuthentication.java class. when creating and authentication without the username or password ( = null) then the indexOf was generating the NullPointerException.
To solve the following issue i included a simple check on the username against null.

If im not mistaking this is needed when a GUEST connection is needed to the server.

/**
 * Create an <tt>NtlmPasswordAuthentication</tt> object from a
 * domain, username, and password. Parameters that are <tt>null</tt>
 * will be substituted with <tt>jcifs.smb.client.domain</tt>,
 * <tt>jcifs.smb.client.username</tt>, <tt>jcifs.smb.client.password</tt>
 * property values.
 */
    public NtlmPasswordAuthentication( String domain, String username, String password ) {
        int ci;

        if(username != null){
        	ci = username.indexOf('@');
        	if (ci > 0) {
        		domain = username.substring(ci + 1);
        		username = username.substring(0, ci);
        	} else {
        		ci = username.indexOf('\\');
        		if (ci > 0) {
        			domain = username.substring(0, ci);
        			username = username.substring(ci + 1);
        		}
        	}
        }
        	
        this.domain = domain;
        this.username = username;
        this.password = password;

        initDefaults();

        if( domain == null ) this.domain = DEFAULT_DOMAIN;
        if( username == null ) this.username = DEFAULT_USERNAME;
        if( password == null ) this.password = DEFAULT_PASSWORD;
    }

--Paulo Louro
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.