From coverity: createSaslServer may return null

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2257 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-03-17 22:48:35 +00:00
parent c8d0186079
commit 58f84bcd12
1 changed files with 12 additions and 14 deletions

View File

@ -576,6 +576,9 @@ public class LdapConnection extends AbstractConnection {
Map<String, String> properties = new HashMap<String, String>(); Map<String, String> properties = new HashMap<String, String>();
properties.put("javax.security.sasl.qop", "auth,auth-int"); properties.put("javax.security.sasl.qop", "auth,auth-int");
saslServer = Sasl.createSaslServer(mechanism, "ldap", client.getLocalAddress().getHostAddress(), properties, callbackHandler); saslServer = Sasl.createSaslServer(mechanism, "ldap", client.getLocalAddress().getHostAddress(), properties, callbackHandler);
if (saslServer == null) {
throw new IOException("Unable to create SASL server for mechanism "+mechanism);
}
serverResponse = saslServer.evaluateResponse(EMPTY_BYTE_ARRAY); serverResponse = saslServer.evaluateResponse(EMPTY_BYTE_ARRAY);
status = LDAP_SASL_BIND_IN_PROGRESS; status = LDAP_SASL_BIND_IN_PROGRESS;
} }
@ -827,8 +830,7 @@ public class LdapConnection extends AbstractConnection {
protected String getServiceInfo() throws UnknownHostException { protected String getServiceInfo() throws UnknownHostException {
if (serviceInfo == null) { if (serviceInfo == null) {
StringBuilder buffer = new StringBuilder(); serviceInfo = ("<?xml version='1.0' encoding='UTF-8'?>" +
buffer.append("<?xml version='1.0' encoding='UTF-8'?>" +
"<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>" + "<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>" +
"<plist version='1.0'>" + "<plist version='1.0'>" +
"<dict>" + "<dict>" +
@ -847,9 +849,7 @@ public class LdapConnection extends AbstractConnection {
"<key>enabled</key>" + "<key>enabled</key>" +
"<true/>" + "<true/>" +
"<key>port</key>" + "<key>port</key>" +
"<integer>"); "<integer>") + Settings.getProperty("davmail.caldavPort") + "</integer>" +
buffer.append(Settings.getProperty("davmail.caldavPort"));
buffer.append("</integer>" +
"</dict>" + "</dict>" +
"<key>https</key>" + "<key>https</key>" +
"<dict>" + "<dict>" +
@ -860,9 +860,7 @@ public class LdapConnection extends AbstractConnection {
"</dict>" + "</dict>" +
"</dict>" + "</dict>" +
"<key>hostname</key>" + "<key>hostname</key>" +
"<string>"); "<string>" + getCurrentHostName() + "</string>" +
buffer.append(getCurrentHostName());
buffer.append("</string>" +
"<key>serviceInfo</key>" + "<key>serviceInfo</key>" +
"<dict>" + "<dict>" +
"<key>calendar</key>" + "<key>calendar</key>" +
@ -889,8 +887,7 @@ public class LdapConnection extends AbstractConnection {
"</dict>" + "</dict>" +
"</dict>" + "</dict>" +
"</dict>" + "</dict>" +
"</plist>"); "</plist>";
serviceInfo = buffer.toString();
} }
return serviceInfo; return serviceInfo;
} }
@ -954,7 +951,7 @@ public class LdapConnection extends AbstractConnection {
if (values instanceof String) { if (values instanceof String) {
responseBer.encodeString((String) values, isLdapV3()); responseBer.encodeString((String) values, isLdapV3());
} else if (values instanceof List) { } else if (values instanceof List) {
for (Object value : (List) values) { for (Object value : (Iterable) values) {
responseBer.encodeString((String) value, isLdapV3()); responseBer.encodeString((String) value, isLdapV3());
} }
} else { } else {
@ -1286,7 +1283,7 @@ public class LdapConnection extends AbstractConnection {
} else if ((operator == LDAP_FILTER_EQUALITY) && personAttributeValue.equalsIgnoreCase(value)) { } else if ((operator == LDAP_FILTER_EQUALITY) && personAttributeValue.equalsIgnoreCase(value)) {
// Found an exact match // Found an exact match
return true; return true;
} else if ((operator == LDAP_FILTER_SUBSTRINGS) && (personAttributeValue.toLowerCase().indexOf(value.toLowerCase()) >= 0)) { } else if ((operator == LDAP_FILTER_SUBSTRINGS) && (personAttributeValue.toLowerCase().contains(value.toLowerCase()))) {
// Found a substring match // Found a substring match
return true; return true;
} }
@ -1421,14 +1418,14 @@ public class LdapConnection extends AbstractConnection {
DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_SEARCH", currentMessageId, dn, scope, sizeLimit, timelimit, ldapFilter.toString(), returningAttributes)); DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_SEARCH", currentMessageId, dn, scope, sizeLimit, timelimit, ldapFilter.toString(), returningAttributes));
if (scope == SCOPE_BASE_OBJECT) { if (scope == SCOPE_BASE_OBJECT) {
if ("".equals(dn)) { if (dn != null && dn.length() == 0) {
size = 1; size = 1;
sendRootDSE(currentMessageId); sendRootDSE(currentMessageId);
} else if (BASE_CONTEXT.equals(dn)) { } else if (BASE_CONTEXT.equals(dn)) {
size = 1; size = 1;
// root // root
sendBaseContext(currentMessageId); sendBaseContext(currentMessageId);
} else if (dn.startsWith("uid=") && dn.indexOf(',') > 0) { } else if (dn != null && dn.startsWith("uid=") && dn.indexOf(',') > 0) {
if (session != null) { if (session != null) {
// single user request // single user request
String uid = dn.substring("uid=".length(), dn.indexOf(',')); String uid = dn.substring("uid=".length(), dn.indexOf(','));
@ -1437,6 +1434,7 @@ public class LdapConnection extends AbstractConnection {
// first search in contact // first search in contact
try { try {
// check if this is a contact uid // check if this is a contact uid
//noinspection ResultOfMethodCallIgnored
Integer.parseInt(uid); Integer.parseInt(uid);
persons = contactFind(session.isEqualTo("imapUid", uid), returningAttributes, sizeLimit); persons = contactFind(session.isEqualTo("imapUid", uid), returningAttributes, sizeLimit);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {