Creating a Custom Authenticator

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating a Custom Authenticator

Mahesh Govindappa
Hello Everyone

I am new to Squid and Development.
but i have sufficient Knowledge to Configure Squid and understand the
architecture of the same.

i am trying to create a custom authenticator for Squid.
as the builtin authenticator programs do not solve my problem .

1.My requirement is to allow a user with in a day a specified amount
of time to browse, it can be any time within that day.
2. or Based on download and upload the user done, like we can specify
datasize Quota for a user.

i wrote a simple program just for checking purpose.

#include <stdio.h>
#include <string.h>

int main()
{
char buf[8192];
fgets(buf, 256, stdin);
FILE  *fp;
fp=fopen("/etc/test.txt", "w");
fprintf(fp,"%s", buf);
fclose(fp);
printf("OK\n");
}

made it executable and run it and specified

auth_param basic program path/myprogram

This is to Check what does Squid Give to me and write it to a File.
and Send OK for every request to Squid.
But Squid Keeps on asking username and password and nothing is written
in the file /etc/test.txt.
can u please explain what is the problem and how can it be solved.
i actually wanted to be a active member of the squid with my active
partition of development and ideas, but as i am a starter just 1 month
new to Squid.


Best regards,
Mahesh G
Reply | Threaded
Open this post in threaded view
|

Re: Creating a Custom Authenticator

Adrian Chadd
On Wed, May 23, 2007, Mahesh Govindappa wrote:

> i wrote a simple program just for checking purpose.
>
> #include <stdio.h>
> #include <string.h>
>
> int main()
> {
> char buf[8192];
> fgets(buf, 256, stdin);
> FILE  *fp;
> fp=fopen("/etc/test.txt", "w");
> fprintf(fp,"%s", buf);
> fclose(fp);
> printf("OK\n");
> }
>
> made it executable and run it and specified

Its not enough; it needs to be in a loop.
Something like:

int main()
{
        /* Be explicit about the buffering semantics for stdin/stdout as Squid requires it to be line buffered */
        setlinebuf(stdin);
        setlinebuf(stdout);

        fp = fopen("/etc/test.txt, "w");
        if (!fp)
                perror("Couldn't open /etc/test.txt for writing\n");
        /* This isn't needed, but it makes debugging easier as you'll immediately see the lines as they're authenticated */
        if (fp)
                setlinebuf(fp);
        while (! feof(stdin)) {
                if (fgets(buf, 256, stdin) == NULL)
                        break;
               
                printf("OK\n");
                if (fp)
                        fprintf(fp, "%s", buf);
        }
        close(fp);
}

Might do it.



Adrian

Reply | Threaded
Open this post in threaded view
|

Re: Creating a Custom Authenticator

Mahesh Govindappa
hi Adrian Chadd
Thanks for your reply
when i execute file from terminal
./first
its working perfect
when i am executing from the Squid its writing nothing into a txt file
i am attaching squid.conf file for your reference.
waiting for your reply

Best regards,
Mahesh G

On 5/25/07, Adrian Chadd <[hidden email]> wrote:

> On Wed, May 23, 2007, Mahesh Govindappa wrote:
>
> > i wrote a simple program just for checking purpose.
> >
> > #include <stdio.h>
> > #include <string.h>
> >
> > int main()
> > {
> > char buf[8192];
> > fgets(buf, 256, stdin);
> > FILE  *fp;
> > fp=fopen("/etc/test.txt", "w");
> > fprintf(fp,"%s", buf);
> > fclose(fp);
> > printf("OK\n");
> > }
> >
> > made it executable and run it and specified
>
> Its not enough; it needs to be in a loop.
> Something like:
>
> int main()
> {
>         /* Be explicit about the buffering semantics for stdin/stdout as Squid requires it to be line buffered */
>         setlinebuf(stdin);
>         setlinebuf(stdout);
>
>         fp = fopen("/etc/test.txt, "w");
>         if (!fp)
>                 perror("Couldn't open /etc/test.txt for writing\n");
>         /* This isn't needed, but it makes debugging easier as you'll immediately see the lines as they're authenticated */
>         if (fp)
>                 setlinebuf(fp);
>         while (! feof(stdin)) {
>                 if (fgets(buf, 256, stdin) == NULL)
>                         break;
>
>                 printf("OK\n");
>                 if (fp)
>                         fprintf(fp, "%s", buf);
>         }
>         close(fp);
> }
>
> Might do it.
>
>
>
> Adrian
>
>

--
Best regards,
Mahesh.G

squid.conf (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Creating a Custom Authenticator

Adrian Chadd
On Sun, May 27, 2007, Mahesh Govindappa wrote:
> hi Adrian Chadd
> Thanks for your reply
> when i execute file from terminal
> ./first
> its working perfect
> when i am executing from the Squid its writing nothing into a txt file
> i am attaching squid.conf file for your reference.
> waiting for your reply

I bet it doesn't have permissions for /etc/test.txt, try /tmp/something ..

>
> Best regards,
> Mahesh G
>
> On 5/25/07, Adrian Chadd <[hidden email]> wrote:
> >On Wed, May 23, 2007, Mahesh Govindappa wrote:
> >
> >> i wrote a simple program just for checking purpose.
> >>
> >> #include <stdio.h>
> >> #include <string.h>
> >>
> >> int main()
> >> {
> >> char buf[8192];
> >> fgets(buf, 256, stdin);
> >> FILE  *fp;
> >> fp=fopen("/etc/test.txt", "w");
> >> fprintf(fp,"%s", buf);
> >> fclose(fp);
> >> printf("OK\n");
> >> }
> >>
> >> made it executable and run it and specified
> >
> >Its not enough; it needs to be in a loop.
> >Something like:
> >
> >int main()
> >{
> >        /* Be explicit about the buffering semantics for stdin/stdout as
> >        Squid requires it to be line buffered */
> >        setlinebuf(stdin);
> >        setlinebuf(stdout);
> >
> >        fp = fopen("/etc/test.txt, "w");
> >        if (!fp)
> >                perror("Couldn't open /etc/test.txt for writing\n");
> >        /* This isn't needed, but it makes debugging easier as you'll
> >        immediately see the lines as they're authenticated */
> >        if (fp)
> >                setlinebuf(fp);
> >        while (! feof(stdin)) {
> >                if (fgets(buf, 256, stdin) == NULL)
> >                        break;
> >
> >                printf("OK\n");
> >                if (fp)
> >                        fprintf(fp, "%s", buf);
> >        }
> >        close(fp);
> >}
> >
> >Might do it.
> >
> >
> >
> >Adrian
> >
> >
>
>
> --
> Best regards,
> Mahesh.G



--
- Xenion - http://www.xenion.com.au/ - VPS Hosting - Commercial Squid Support -
- $25/pm entry-level bandwidth-capped VPSes available in WA -
Reply | Threaded
Open this post in threaded view
|

Re: Creating a Custom Authenticator

Mahesh Govindappa
Hi Adrian
i really appriciate you interest.
I have Provided "Read and write" Rights to Others and Squid to the
file test.txt.
I even tried by changing the path to /tmp/test.txt.
but its wirting nothing into that file :(
i am attaching the screenshot of the permission tab of the test.txt file.
waiting for your reply :) .

best regards,
mahesh g

On 5/27/07, Adrian Chadd <[hidden email]> wrote:

> On Sun, May 27, 2007, Mahesh Govindappa wrote:
> > hi Adrian Chadd
> > Thanks for your reply
> > when i execute file from terminal
> > ./first
> > its working perfect
> > when i am executing from the Squid its writing nothing into a txt file
> > i am attaching squid.conf file for your reference.
> > waiting for your reply
>
> I bet it doesn't have permissions for /etc/test.txt, try /tmp/something ..
>
> >
> > Best regards,
> > Mahesh G
> >
> > On 5/25/07, Adrian Chadd <[hidden email]> wrote:
> > >On Wed, May 23, 2007, Mahesh Govindappa wrote:
> > >
> > >> i wrote a simple program just for checking purpose.
> > >>
> > >> #include <stdio.h>
> > >> #include <string.h>
> > >>
> > >> int main()
> > >> {
> > >> char buf[8192];
> > >> fgets(buf, 256, stdin);
> > >> FILE  *fp;
> > >> fp=fopen("/etc/test.txt", "w");
> > >> fprintf(fp,"%s", buf);
> > >> fclose(fp);
> > >> printf("OK\n");
> > >> }
> > >>
> > >> made it executable and run it and specified
> > >
> > >Its not enough; it needs to be in a loop.
> > >Something like:
> > >
> > >int main()
> > >{
> > >        /* Be explicit about the buffering semantics for stdin/stdout as
> > >        Squid requires it to be line buffered */
> > >        setlinebuf(stdin);
> > >        setlinebuf(stdout);
> > >
> > >        fp = fopen("/etc/test.txt, "w");
> > >        if (!fp)
> > >                perror("Couldn't open /etc/test.txt for writing\n");
> > >        /* This isn't needed, but it makes debugging easier as you'll
> > >        immediately see the lines as they're authenticated */
> > >        if (fp)
> > >                setlinebuf(fp);
> > >        while (! feof(stdin)) {
> > >                if (fgets(buf, 256, stdin) == NULL)
> > >                        break;
> > >
> > >                printf("OK\n");
> > >                if (fp)
> > >                        fprintf(fp, "%s", buf);
> > >        }
> > >        close(fp);
> > >}
> > >
> > >Might do it.
> > >
> > >
> > >
> > >Adrian
> > >
> > >
> >
> >
> > --
> > Best regards,
> > Mahesh.G
>
>
>
> --
> - Xenion - http://www.xenion.com.au/ - VPS Hosting - Commercial Squid Support -
> - $25/pm entry-level bandwidth-capped VPSes available in WA -
>

--
Best regards,
Mahesh.G

Screenshot-1.png (243K) Download Attachment