anchor.diff:  	    UserAttribute = sipserver:get_env(ldap_userattribute, "sipAuthenticationUser"),
   	    AddressAttribute = sipserver:get_env(ldap_addressattribute, "sipLocalAddress"),
   	    case get_addresses_for_users_list(Server, UserAttribute, AddressAttribute, UserList) of
  -		Res when list(Res) ->
  +		Res when is_list(Res) ->
   		    SortedRes = lists:usort(Res),
   		    logger:log(debug, "userdb-ldap: Found address(es) ~p for user(s) ~p", [SortedRes, UserList]),
   		    SortedRes;
  -		Res ->
  -		    Res
  -	    end
  -    end.
  -
  -get_addresses_for_users_list(Server, UserAttribute, AddressAttribute, []) ->
  +		error ->
  +		    error
  +	    end
  +    end.
  +
  +%% internal function - part of get_addresses_for_users/1
  +get_addresses_for_users_list(_Server, _UserAttribute, _AddressAttribute, []) ->
       [];
   get_addresses_for_users_list(Server, UserAttribute, AddressAttribute, [User | Rest]) ->
       Res = directory:ldapsearch_simple(Server, UserAttribute, User, AddressAttribute),
  
positive.code: 	    UserAttribute = sipserver:get_env(ldap_userattribute, "sipAuthenticationUser"),
  	    AddressAttribute = sipserver:get_env(ldap_addressattribute, "sipLocalAddress"),
  	    case get_users_for_AOR_list(Server, UserAttribute, AddressAttribute, AddressList) of
  		Res when list(Res) ->
  		    SortedRes = lists:usort(Res),
  		    logger:log(debug, "userdb-ldap: Found user(s) ~p for address(es) ~p", [SortedRes, AddressList]),
  		    SortedRes;
  
negative.code: 	    error;
  	none ->
  	    get_addresses_for_users_list(Server, UserAttribute, AddressAttribute, Rest);
  	Addresses when is_list(Addresses) ->
  	    lists:append(Addresses, get_addresses_for_users_list(Server, UserAttribute, AddressAttribute, Rest))
      end.
  
  %%--------------------------------------------------------------------
  %% Function: get_users_for_url(URL)
  %%           URL = sipurl record()
  %% Descrip.: Given an URL that is typically the Request-URI of an
  %%           incoming request, make a list of implicit user
  %%           addresses and return a list of all users matching any
  %%           of these addresses. This is located in here since
  %%           user database backends can have their own way of
  %%           deriving addresses from a Request-URI.
  %% Returns : Usernames, list() of string()
  %%--------------------------------------------------------------------
  get_users_for_url(URL) when is_record(URL, sipurl) ->
      Addresses = local:lookup_url_to_addresses(sipuserdb_ldap, URL),
      logger:log(debug, "userdb-ldap: Looking for users matching address(es) ~p derived from URL ~p",
  	       [Addresses, sipurl:print(URL)]),
      get_users_for_addresses_of_record(Addresses).
  
  
  %% Attribute fetching functions :
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  %%--------------------------------------------------------------------
  %% Function: get_password_for_user(Username)
  %%           Username = string()
  %% Descrip.: Returns the password for a user.
  %% Returns : Password |
  %%           nomatch  |
  %%           error
  %%           Password = string()
  %%--------------------------------------------------------------------
  get_password_for_user(User) when is_list(User) ->
      case sipserver:get_env(ldap_server, none) of
  	none ->
  	    nomatch;
  