ejabberd - Comments for "Stupid question... about auth_odbc, auth_ldap.. etc.." https://www.ejabberd.im/node/3137 en To finalize this topic :) https://www.ejabberd.im/node/3137#comment-53481 <p>Unfortunately, my "cool idea" to authenticate with external sript, failed...</p> <p>As I wrote in previous message, I think, this idea is not good, because of unreliability (I have no idea, how many processes/scripts will run on quite heavy loaded server), how to kill time to time these scripts..</p> <p>Also, I repeat, I found, that auth script will called at EVERY message (maybe only when destination user is offline)... and I think it's unacceptable on heavy deployments.</p> <p>Maybe I'm wrong... But... I decided to go "another way"...</p> <p>However... I think my idea may interested someone... also, I saw in older topics, someone asked about "temparary passwords", ans so on... Maybe someone find here something useful.</p> <p>So... Imagine, You have a website. User should login... after that, user redirects to page with some content and flash-jabber client (have You patched Your ejabberd with flash- and policy- hacks? :).</p> <p>There is a problem. User should enter his password twice to connect to ejabberd with flashclient (it's sucks :)<br /> OR - webmaster should call flashclient with paramters, where is jabber login and password (it's insecure :)<br /> OR - flashclient can load login and password at very start, using, for example, "loadvars" or "loadVariables" flash object.</p> <p>Regretfully, it is also insecure - because some webbrowsers with some flash client stores loaded (with loadvars) html-data in local file, even loaded html has full set of "nocache" headers and "POST" method used.</p> <p>So... solution (not good solution, I reject it) - is following:</p> <p>Suppose user enter login and password with HTML form. PHP script than checks the data, and if OK, stores some flag in $_SESSION variable - i.e. $_SESSION['user_id'].</p> <p>After that flash-jabber client is called with two params - login and PHPSESSID - !<br /> And last one, PHPSESSID will be used to connect to jabber server!</p> <p>And our ejabberd server configured to use external auth script.<br /> Script as simple as -</p> <div class="codeblock"><code>#!/usr/bin/php<br />&lt;?php<br />ini_set (&#039;session.use_cookies&#039;, &#039;0&#039;);<br />ini_set (&#039;session.save_path&#039;, &#039;/tmp/&#039;);<br />// it&#039;s command-line script, in many installations session save path is different in webserver and cli.<br />// We must shure, that this path is the same in both. <p>ini_set (&#039;display_errors&#039;, &#039;0&#039;);<br />define (&#039;SERVERNAME&#039;, &#039;coolserver&#039;);</p> <p>function authOK()&nbsp; {&nbsp; fwrite(STDOUT, &quot;\0\2\0\1&quot;); }</p> <p>function authFail()&nbsp; { fwrite(STDOUT, &quot;\0\2\0\0&quot;); }</p> <p>// according to docs, we must provide ONLY two cases - OK or not OK :)</p> <p>while(1)<br />{<br />$iHeader=fgets(STDIN,3);<br />$aLength=unpack(&#039;n&#039;, $iHeader);<br />$iLength=$aLength[&#039;1&#039;];</p> <p>if ($iLength &gt; 9) // minimum length of user and password.<br />{<br />$sData=fgets(STDIN, $iLength+1);<br />list($Command,$User,$Server,$Password)=explode(&quot;:&quot;,$sData);</p> <p>if ($Command==&#039;auth&#039; &amp;&amp; $Server==SERVERNAME)<br />{</p> <p>session_id($Password); // force session with given temporary PHPSESSID as password<br />session_start();<br />$uid=$_SESSION[&#039;id&#039;];<br />session_write_close();</p> <p>if ($uid &amp;&amp; $uid==substr($User,1)) authOK(); else authFail();</p> <p>}<br />else authFail();<br />}<br />else authFail();</p> <p>}</p></code></div> <p>So... maybe I miss something, but something like that works ok for me with test cases...</p> <p>Despite, as I said, I decided not use it... it can be useful to someone, I think...<br /> Or, maybe, will lead to better solution...</p> Wed, 13 Aug 2008 17:01:03 +0000 philipj comment 53481 at https://www.ejabberd.im Yes, dear badlop https://www.ejabberd.im/node/3137#comment-53436 <p>You're right, "isuser" is not called to login....</p> <p>I accept Your allusion, that I should first check the source code before asking a question.</p> <p>But... I'm novice in erlang, at last weekend I started to learn it, but.. I'm not very young, I feel it more and more, and new conceptions is not easly comes to me, I feel that my head is almost full of info of different kind...</p> <p>But it's irrelevent...</p> <p>Yes, I should as least write my own auth script and log request... but I done it now...</p> <p>And I discover, that "isuser" is not called to login, You're right, but... it seems, that "isuser" is sent in every case, that user want to send a message to another user, or chat.</p> <p>And now it's looks also strange for me... Imagine, for example, I wrote script to authenticate with my DB... So, if I get request at every user login, it would be OK, but, if my script get "isuser" command at every message, and has to ask DB.... it's very heavy load thing, I suppose...</p> <p>Why is need in external "isuser" request to script, isn't jabberd itself can serve it?</p> Tue, 15 Jul 2008 20:14:11 +0000 philipj comment 53436 at https://www.ejabberd.im Try register, Anonymous login and other usages https://www.ejabberd.im/node/3137#comment-53417 <div class="quote-msg"> <div class="quote-author"><em>philipj</em> wrote:</div> <p>Can You please tell, in wich case ejabberd sends "isuser" request to the external script? When user with jabber-client tries to login, ejabberd first checks, if user exist, and if it's true, makes a second, "auth" request with provided password?</p> <p>Is this true? If just "auth" request is not enough to login?</p></div> <p>It just takes some minutes to search in the source code:</p> <div class="quote-msg"> <div class="quote-author"><em>extauth.erl</em> wrote:</div> <p>is_user_exists(User, Server) -&gt;<br /> call_port(Server, ["isuser", User, Server]). </p></div> <div class="quote-msg"> <div class="quote-author"><em>ejabberd_auth.erl</em> wrote:</div> <p>%% We do not allow empty password:<br /> try_register(_User, _Server, "") -&gt;<br /> {error, not_allowed};<br /> try_register(User, Server, Password) -&gt;<br /> case is_user_exists(User,Server) of<br /> true -&gt;<br /> {atomic, exists};<br /> false -&gt;<br /> ... </p></div> <div class="quote-msg"> <div class="quote-author"><em>cyrsasl_anonymous.erl</em> wrote:</div> <p>mech_step(State, _ClientIn) -&gt;<br /> %% We generate a random username:<br /> User = lists:concat([randoms:get_string() | tuple_to_list(now())]),<br /> Server = State#state.server,</p> <p> %% Checks that the username is available<br /> case ejabberd_auth:is_user_exists(User, Server) of<br /> true -&gt; {error, "not-authorized"};<br /> false -&gt; {ok, [{username, User},<br /> {auth_module, ejabberd_auth_anonymous}]}<br /> end. </p></div> <p>It's also called in ejabberd_sm, mod_configure and mod_vcard_ldap.</p> <p>So I guess 'isuser' is not called to login an existing account.</p> Sat, 12 Jul 2008 08:51:04 +0000 mfoss comment 53417 at https://www.ejabberd.im Again https://www.ejabberd.im/node/3137#comment-53410 <p>Thanx for reply...</p> <p>BTW.. I still wonder, why the need in auth with external databases... if You use external auth, You should however create, delete entity of "user" in ejabberd, when You create or delete user in external DB...</p> <p>But!... It seems I find a cool and very usefull thing for web-clients... (details I'll write later, if it succeed)...</p> <p>And in my idea, main thing - is ability to auth ejabberd users with "external script"...</p> <p>I browsed in these scripts <a href="http://www.ejabberd.im/extauth" title="http://www.ejabberd.im/extauth">http://www.ejabberd.im/extauth</a><br /> And I found, that ejabberd can actually make a 3 types of requests to the external auth script:</p> <p>They are:</p> <p>1. "auth" ejabberd sends to script User:Server:Password - and check if a username/password pair is correct<br /> 2. "isuser" ejabberd sends "User:Server" and check if it’s a valid user<br /> 3. "setpass" - ejabbed tries to change user's password.</p> <p>I don't think is need in my purpose to provide an ability to change password with jabber-client (as I see, many scripts also denies such request)... so I not interested much in this..</p> <p>But... I'd like to kindly ask You... and my question is -</p> <p><strong>Can You please tell, in wich case ejabberd sends "isuser" request to the external script? When user with jabber-client tries to login, ejabberd first checks, if user exist, and if it's true, makes a second, "auth" request with provided password?</strong></p> <p>Is this true? If just "auth" request is not enough to login?</p> Thu, 10 Jul 2008 16:58:32 +0000 philipj comment 53410 at https://www.ejabberd.im Well, I guess https://www.ejabberd.im/node/3137#comment-53395 <p>When data is duplicated, there's a chance for inconsistency. When a duplicate changes, then that change must be spread to all the duplications.</p> <p>Imagine an organization that already has a LDAP server to store usernames and passwords of 10.000 humans. They used it for years to authenticate SMTP server, POP3 server, WebDAV and machine logins. Now they plan to deploy ejabberd for instant messaging. </p> <p>They could export the LDAP database to the format of ejabberd's 'passwd' table. Then import that data in ejabberd. And then setup a script that, everytime a new user is created in LDAP, or deleted, or changes his password; that change is replicated in ejabberd database.</p> <p>Or they can configure ejabberd to authenticate the users against a remote LDAP server.</p> Tue, 08 Jul 2008 23:08:51 +0000 mfoss comment 53395 at https://www.ejabberd.im