fnord-1.8 and AUTH problem. user name and password not accepted.

rajram1 <[email protected]> Sun, 24 Oct 2004 21:19:42 -0700
Newsgroups gmane.comp.web.fnord
Message-ID <[email protected]>
--=-F9YAKCiCFOYhVGcRiQ7X
Content-Type: multipart/alternative; boundary="=-iv6kkoJ0F7J+040JKOSO"



--=-iv6kkoJ0F7J+040JKOSO
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit

Hi,

I have been using fnord as my web server for about a year now. I would
like to turn on authentication.
Here is my set up -
fnord-1.8 with AUTH defined.
.http-auth (file attached) for user "foo" and password "bar" as
described in http://www.fbunet.de/fnord.shtml

The above configuration does not work. That is, I am prompted for the
password but the password is not accepted.
Looking through the code (in the file httpd.c), I saw that the array
argv, that is passed to the script, contains script-name (.http-auth),
host, url, authorization and NULL (in that order). This made me think
that the .http-auth script should be -
[ x"$4" = x"Basic Zm9vOmJhcg==" ]
instead of -
[ x"$3" = x"Basic Zm9vOmJhcg==" ]

This, however, did not work either.

I then added "sleep 100" in the script before the above line and watched
the packets using "ethereal".
The following is what I saw...
A request for a page was received. This was followed by a 401 response.
The next HTTP message that the server received contained the
authorization code (it was Basic Zm9vOmJhcg==\r\n) which was correct. I
now expected the server to not immediately respond since the script had
a "sleep 100" line.
This was however not the case. The server immediately sent another 401
response (same as the first one).

I then looked through the code some more and my guess is that since the
401 response was sent back immediately, the code always goes through the
"else part" of the following if, else if, else code segment and passes
the test -
"if(!WIFEXITED(status) || WEXITSTATUS(status))".

---code segment---
if(child < 0) {
            badrequest(500, "Internal Server Error", "Server Resource
problem.");
         } else if(child == 0) {
            const char *argv[5] = { auth_script, host, url,
authorization, NULL };

            dup2(2, 1);
            execve(auth_script, argv, envp);
            _exit(1);
         } else {
            int status;
            pid_t childr;

            while((childr = waitpid(child, &status, 0)) < 0 && errno ==
EINTR);
            if(childr != child)
               badrequest(500, "Internal Server Error", "Server system
problem.");
            if(!WIFEXITED(status) || WEXITSTATUS(status)) {
               retcode = 401;
               dolog(0);
               buffer_puts(buffer_1,"HTTP/1.0 401 Authorization
Required\r\n"
                           "WWW-Authenticate: Basic realm=\"");
               buffer_puts(buffer_1, host);
               buffer_puts(buffer_1,"\"\r\nConnection: close\r\n\r\n"
                           "Access to this site is restricted.\r\n"
                           "Please provide credentials.\r\n");
               buffer_flush(buffer_1);
               exit(0);
            }
         }
---code segment---

I would really appreciate it if someone to help me set up authentication
on fnord. I really like this server for it security and size.

Thanks very much
br
rajeev

--=-iv6kkoJ0F7J+040JKOSO
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.0.10">
</HEAD>
<BODY>
Hi,<BR>
<BR>
I have been using fnord as my web server for about a year now. I would like to turn on authentication.<BR>
Here is my set up -<BR>
fnord-1.8 with AUTH defined.<BR>
.http-auth (file attached) for user &quot;foo&quot; and password &quot;bar&quot; as described in <A HREF="http://www.fbunet.de/fnord.shtml">http://www.fbunet.de/fnord.shtml</A><BR>
<BR>
The above configuration does not work. That is, I am prompted for the password but the password is not accepted.<BR>
Looking through the code (in the file httpd.c), I saw that the array argv, that is passed to the script, contains script-name (.http-auth), host, url, authorization and NULL (in that order). This made me think that the .http-auth script should be -<BR>
[ x&quot;$4&quot; = x&quot;Basic Zm9vOmJhcg==&quot; ]<BR>
instead of -<BR>
[ x&quot;$3&quot; = x&quot;Basic Zm9vOmJhcg==&quot; ]<BR>
<BR>
This, however, did not work either.<BR>
<BR>
I then added &quot;sleep 100&quot; in the script before the above line and watched the packets using &quot;ethereal&quot;.<BR>
The following is what I saw...<BR>
A request for a page was received. This was followed by a 401 response.<BR>
The next HTTP message that the server received contained the authorization code (it was Basic Zm9vOmJhcg==\r\n) which was correct. I now expected the server to not immediately respond since the script had a &quot;sleep 100&quot; line.<BR>
This was however not the case. The server immediately sent another 401 response (same as the first one).<BR>
<BR>
I then looked through the code some more and my guess is that since the 401 response was sent back immediately, the code always goes through the &quot;else part&quot; of the following if, else if, else code segment and passes the test -<BR>
&quot;if(!WIFEXITED(status) || WEXITSTATUS(status))&quot;.<BR>
<BR>
---code segment---<BR>
if(child &lt; 0) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; badrequest(500, &quot;Internal Server Error&quot;, &quot;Server Resource problem.&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if(child == 0) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char *argv[5] = { auth_script, host, url, authorization, NULL };<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dup2(2, 1);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; execve(auth_script, argv, envp);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _exit(1);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int status;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pid_t childr;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while((childr = waitpid(child, &amp;status, 0)) &lt; 0 &amp;&amp; errno == EINTR);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(childr != child)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; badrequest(500, &quot;Internal Server Error&quot;, &quot;Server system problem.&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(!WIFEXITED(status) || WEXITSTATUS(status)) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retcode = 401;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dolog(0);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer_puts(buffer_1,&quot;HTTP/1.0 401 Authorization Required\r\n&quot;<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; &quot;WWW-Authenticate: Basic realm=\&quot;&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer_puts(buffer_1, host);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer_puts(buffer_1,&quot;\&quot;\r\nConnection: close\r\n\r\n&quot;<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; &quot;Access to this site is restricted.\r\n&quot;<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; &quot;Please provide credentials.\r\n&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer_flush(buffer_1);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(0);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
---code segment---<BR>
<BR>
I would really appreciate it if someone to help me set up authentication on fnord. I really like this server for it security and size.<BR>
<BR>
Thanks very much<BR>
br<BR>
rajeev
</BODY>
</HTML>

--=-iv6kkoJ0F7J+040JKOSO--

--=-F9YAKCiCFOYhVGcRiQ7X
Content-Disposition: attachment; filename=.http-auth
Content-Type: application/x-shellscript; name=.http-auth
Content-Transfer-Encoding: 7bit

#!/bin/sh
[ x"$3" = x"Basic Zm9vOmJhcg==" ]

--=-F9YAKCiCFOYhVGcRiQ7X--