ejabberd - Comments for "Option for setting SASL FQDN" https://www.ejabberd.im/node/3098 en Fixed https://www.ejabberd.im/node/3098#comment-53676 <p>Hi badlop,<br /> Taking the help of an erlang developer, I have been able to get the function to work.</p> <div class="codeblock"><code>%%%----------------------------------------------------------------------<br />%%% File&nbsp;&nbsp;&nbsp; : ejabberd_net.erl<br />%%% Author&nbsp; : Mikael Magnusson &lt;mikma@users.sourceforge.net&gt;<br />%%% Purpose : Serve C2S connection<br />%%% Created : 6 June 2007 by Mikael Magnusson &lt;mikma@users.sourceforge.net&gt;<br />%%% Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : $Id: $<br />%%%---------------------------------------------------------------------- <p>-module(ejabberd_net).<br />-author(&#039;mikma@users.sourceforge.net&#039;).<br />%% -update_info({update, 0}).</p> <p>-export([gethostname/2]).</p> <p>-include(&quot;ejabberd.hrl&quot;).<br />-include_lib(&quot;kernel/include/inet.hrl&quot;).</p> <p>%%<br />%% gethostname(SockMod, Socket)<br />%%<br />gethostname(SockMod, Socket) -&gt;<br />&nbsp;&nbsp;&nbsp; ?INFO_MSG(&quot;gethostname ~p~n&quot;, [Socket]),<br />%%&nbsp;&nbsp;&nbsp;&nbsp; {ok, &quot;skinner.hem.za.org&quot;}.</p> <p>&nbsp;&nbsp;&nbsp; case ejabberd_config:get_local_option({sasl_fqdn, ?MYNAME}) of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; undefined -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, {Addr, Port}} = case SockMod of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gen_tcp -&gt; inet:sockname(Socket);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ -&gt; SockMod:sockname(Socket)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case inet:gethostbyaddr(Addr) of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, HostEnt} when is_record(HostEnt, hostent) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, HostEnt#hostent.h_name};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {error, What} -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F -&gt; {ok, F}<br />&nbsp;&nbsp;&nbsp; end.</p></code></div> <p>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).</p> <p>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).</p> <p>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?</p> Wed, 22 Oct 2008 08:32:17 +0000 amaramrahul comment 53676 at https://www.ejabberd.im Thanks for the response https://www.ejabberd.im/node/3098#comment-53431 <p>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:</p> <p>{sasl_fqdn, "xyz.example.org"}.</p> <p>How do I modify the line ejabberd_config:get_local_option({{sasl_fqdn, Addr}, ?MYNAME}) to fetch the value in this case?</p> Mon, 14 Jul 2008 18:40:17 +0000 amaramrahul comment 53431 at https://www.ejabberd.im maybe something like https://www.ejabberd.im/node/3098#comment-53421 <p>maybe something like this:</p> <div class="codeblock"><code>%%%----------------------------------------------------------------------<br />%%% File&nbsp;&nbsp;&nbsp; : ejabberd_net.erl<br />%%% Author&nbsp; : Mikael Magnusson &lt;mikma@users.sourceforge.net&gt;<br />%%% Purpose : Serve C2S connection<br />%%% Created : 6 June 2007 by Mikael Magnusson &lt;mikma@users.sourceforge.net&gt;<br />%%% Id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : $Id: $<br />%%%---------------------------------------------------------------------- <p>-module(ejabberd_net).<br />-author(&#039;mikma@users.sourceforge.net&#039;).</p> <p>-export([gethostname/1]).</p> <p>-include(&quot;ejabberd.hrl&quot;).<br />-include_lib(&quot;kernel/include/inet.hrl&quot;).</p> <p>%% It is possible to force name resolutions in ejabberd.cfg for example:<br />%% {{sasl_fqdn, &quot;127.0.0.1&quot;}, &quot;localhost&quot;}.<br />%% {{sasl_fqdn, &quot;123.45.67.89&quot;}, &quot;example.org&quot;}.<br />gethostname(Socket) -&gt;<br />&nbsp;&nbsp;&nbsp; ?INFO_MSG(&quot;gethostname ~p~n&quot;, [Socket]),<br />&nbsp;&nbsp;&nbsp; {ok, {Addr, _Port}} = inet:sockname(Socket),<br />&nbsp;&nbsp;&nbsp; case ejabberd_config:get_local_option({{sasl_fqdn, Addr}, ?MYNAME}) of<br /> undefined -&gt;<br /> &nbsp;&nbsp;&nbsp; gethostname_byaddr(Addr);<br /> Host -&gt;<br /> &nbsp;&nbsp;&nbsp; {ok, Host}<br />&nbsp;&nbsp;&nbsp; end.</p> <p>gethostname_byaddr(Addr) -&gt;<br />&nbsp;&nbsp;&nbsp; case inet:gethostbyaddr(Addr) of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, HostEnt} when is_record(HostEnt, hostent) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {ok, HostEnt#hostent.h_name};<br /> {error, _What} -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; error<br />&nbsp;&nbsp;&nbsp; end.</p></code></div> Sat, 12 Jul 2008 14:24:24 +0000 mfoss comment 53421 at https://www.ejabberd.im That was really helpful https://www.ejabberd.im/node/3098#comment-53415 <p>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.</p> Fri, 11 Jul 2008 22:16:27 +0000 amaramrahul comment 53415 at https://www.ejabberd.im amaramrahul wrote: Is there https://www.ejabberd.im/node/3098#comment-53349 <div class="quote-msg"> <div class="quote-author"><em>amaramrahul</em> wrote:</div> <p>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)?</p></div> <p>The FQDN seems to be obtained calling this function in the file ejabberd_net.erl:</p> <pre> gethostname(Socket) -&gt; ?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) -&gt; {ok, HostEnt#hostent.h_name}; {error, What} -&gt; error end. </pre><p> You can hardcode the result, replacing all that code with just, for example:</p> <pre> gethostname(Socket) -&gt; ?INFO_MSG("gethostname ~p~n", [Socket]), {ok, "skinner.hem.za.org"}. </pre><p> Of course it can be implemented in a more elegant way in the future.</p> <p>BTW; I updated the GSSAPI patch to ejabberd 2.0.1. The link is posted in the other forum thread you opened.</p> Sat, 28 Jun 2008 19:01:09 +0000 mfoss comment 53349 at https://www.ejabberd.im