Option for setting SASL FQDN

Hi,
I am using GSSAPI authentiction for ejabberd 1.1.2 (by applying the cyrus_gssapi patch). Currently, as per my understanding, the FQDN is resolved by performing a reverse DNS lookup on the IP (using the entires defined in /etc/ejabberd/inetrc). Is there anyway I can hard-code this FQDN in the ejabberd server (by editing one of the configuration files or by some other workaround)? For ex., something similar to the "sasl-host" option in slapd.conf?

Regards,
Rahul.

amaramrahul wrote: Is there

amaramrahul wrote:

Is there anyway I can hard-code this FQDN in the ejabberd server (by editing one of the configuration files or by some other workaround)?

The FQDN seems to be obtained calling this function in the file ejabberd_net.erl:

gethostname(Socket) ->
    ?INFO_MSG("gethostname ~p~n", [Socket]),
%%     {ok, "skinner.hem.za.org"}.

    {ok, {Addr, Port}} = inet:sockname(Socket),
    case inet:gethostbyaddr(Addr) of
        {ok, HostEnt} when is_record(HostEnt, hostent) ->
            {ok, HostEnt#hostent.h_name};
	{error, What} ->
            error
    end.

You can hardcode the result, replacing all that code with just, for example:

gethostname(Socket) ->
    ?INFO_MSG("gethostname ~p~n", [Socket]),
    {ok, "skinner.hem.za.org"}.

Of course it can be implemented in a more elegant way in the future.

BTW; I updated the GSSAPI patch to ejabberd 2.0.1. The link is posted in the other forum thread you opened.

That was really helpful

That was really helpful badlop. Thanks a ton. The problem is that I don't know erlang. So I cannot make any changes to the code. Reg. the above thing I was thinking let us have an option sasl_fqdn in ejabberd.cfg. Then I think that option can be accessed using ejabberd_config:get_local_option({sasl_fqdn, Host}). So we can check if this option exists and if it does not exist we can call the regular code. I would really appreciate it if you could write this snippet of code and post it here.

maybe something like

maybe something like this:

%%%----------------------------------------------------------------------
%%% File    : ejabberd_net.erl
%%% Author  : Mikael Magnusson <mikma@users.sourceforge.net>
%%% Purpose : Serve C2S connection
%%% Created : 6 June 2007 by Mikael Magnusson <mikma@users.sourceforge.net>
%%% Id      : $Id: $
%%%----------------------------------------------------------------------

-module(ejabberd_net).
-author('mikma@users.sourceforge.net').

-export([gethostname/1]).

-include("ejabberd.hrl").
-include_lib("kernel/include/inet.hrl").

%% It is possible to force name resolutions in ejabberd.cfg for example:
%% {{sasl_fqdn, "127.0.0.1"}, "localhost"}.
%% {{sasl_fqdn, "123.45.67.89"}, "example.org"}.
gethostname(Socket) ->
    ?INFO_MSG("gethostname ~p~n", [Socket]),
    {ok, {Addr, _Port}} = inet:sockname(Socket),
    case ejabberd_config:get_local_option({{sasl_fqdn, Addr}, ?MYNAME}) of
undefined ->
    gethostname_byaddr(Addr);
Host ->
    {ok, Host}
    end.

gethostname_byaddr(Addr) ->
    case inet:gethostbyaddr(Addr) of
        {ok, HostEnt} when is_record(HostEnt, hostent) ->
            {ok, HostEnt#hostent.h_name};
{error, _What} ->
            error
    end.

Thanks for the response

Thanks for the response badlop. I've tried this but it doesn't seem to be working. One thing I could confirm is that as you have analyzed it is gethostbyname() which is being used to fetch the FQDN (so we are on the right track). Also I am looking to set the option as below in ejabberd.cfg:

{sasl_fqdn, "xyz.example.org"}.

How do I modify the line ejabberd_config:get_local_option({{sasl_fqdn, Addr}, ?MYNAME}) to fetch the value in this case?

Fixed

Hi badlop,
Taking the help of an erlang developer, I have been able to get the function to work.

%%%----------------------------------------------------------------------
%%% File    : ejabberd_net.erl
%%% Author  : Mikael Magnusson <mikma@users.sourceforge.net>
%%% Purpose : Serve C2S connection
%%% Created : 6 June 2007 by Mikael Magnusson <mikma@users.sourceforge.net>
%%% Id      : $Id: $
%%%----------------------------------------------------------------------

-module(ejabberd_net).
-author('mikma@users.sourceforge.net').
%% -update_info({update, 0}).

-export([gethostname/2]).

-include("ejabberd.hrl").
-include_lib("kernel/include/inet.hrl").

%%
%% gethostname(SockMod, Socket)
%%
gethostname(SockMod, Socket) ->
    ?INFO_MSG("gethostname ~p~n", [Socket]),
%%     {ok, "skinner.hem.za.org"}.

    case ejabberd_config:get_local_option({sasl_fqdn, ?MYNAME}) of
      undefined ->
        {ok, {Addr, Port}} = case SockMod of
                               gen_tcp -> inet:sockname(Socket);
                               _ -> SockMod:sockname(Socket)
                             end,
        case inet:gethostbyaddr(Addr) of
            {ok, HostEnt} when is_record(HostEnt, hostent) ->
                {ok, HostEnt#hostent.h_name};
            {error, What} ->
                error
        end;
      F -> {ok, F}
    end.

After modifying the code, I compiled, installed and started ejabberd. Initially I did not have any sasl_fqdn option set in ejabberd.cfg and therefore it set the FQDN by reverse lookup of the IP (as expected).

Now I set an option {sasl_fqdn, "abc.example.com"}. in ejabberd.cfg and restarted ejabberd. The FQDN was returned as "abc.example.com" (again as expected).

So the code seemed to be working. Except for that if I now remove the sasl_fqdn option from ejabberd.cfg and restart ejabberd, the FQDN returned is "abc.example.com" instead of that got by reverse lookup of the IP. Do you have any idea why this is happening? Perhaps using ?MYNAME in the code might be the cause of this?

Syndicate content