You are not logged in.

#1 2010-02-10 03:24:55

twek
Member
Registered: 2009-07-24
Posts: 15

[SOLVED] help with squid mysql authentication!

Hello! i was wondering...
how do i make squid authenticate against mysql?
i edited my config file as per the squid wiki,
and installed mysql,
and set up the squid database

but i dont no how to compile squid with the --enable-basic-auth-helpers=DB option,
well, i downloaded the tarball and make'd it and make install'd it but it doesnt make an rc.d script and im lost from there,
but when i install it from yaourt (or pacman) i dont no how to make it compile with the --enable-basic-auth-helpers=DB option

help?

Last edited by twek (2010-02-10 23:21:57)

Offline

#2 2010-02-10 23:18:46

twek
Member
Registered: 2009-07-24
Posts: 15

Re: [SOLVED] help with squid mysql authentication!

Well i gave up using the built in auth program, and wrote my own.
its in c++ so if anyone else wants to use it here u go

#include <mysql++.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <mystring.h>

using namespace std;
using namespace mysqlpp;
int main()
{
        string userName;
    string userPass;
        String db_user; //use mysqlpp:String so it works with mysqlpp
    String db_pass; //use mysqlpp::String so it works with mysqlpp
    String db_enabled; //use mysqlpp::String so it works with mysqlpp
    string db_query = "select * from passwd where user=\"";

    cin >> userName;
    cin.ignore(256,' ');
    cin >> userPass;
    
    db_query.append(userName);    
    db_query.append("\"");

    Connection dbCon(false);
    if(dbCon.connect("squid","localhost","root","mysqlpassword"))
    {
        Query dbQuery =dbCon.query(db_query);
        
        if(StoreQueryResult dbRes = dbQuery.store())
        {
            for(int i = 0; i < dbRes.num_rows();i++)
            {
                db_user = dbRes[i]["user"];
                db_pass = dbRes[i]["password"];
                db_enabled = dbRes[i]["enabled"];
            }
        }
    }
    if(!userName.compare(db_user)&&!userPass.compare(db_pass)&&!db_enabled.compare("1"))
    {    
        cout << "OK"<<endl;
    }
    else
    {
        cout << "ERR"<<endl;
    }
    return 0;
}

make sure you have the mysqlpp library installed,
download this tarball
https://aur.archlinux.org/packages.php?ID=37118
extract it

tar xzfv <path to tar.gz>

then cd into it and

makepkg -s

and

pacman -U <path to tar.xz file>

once it is installed compile your auth.c program with this command

g++ -o auth auth.c -I/usr/include/mysql++/ -I/usr/include/mysql -lmysqlpp -lmysqlclient

then use this squid.conf file

 auth_param basic program ./auth
auth_param basic children 20
auth_param basic realm Username and password
auth_param basic credentialsttl 5 hours

acl all src all
acl AuthenticatedUsers proxy_auth REQUIRED

http_access allow AuthenticatedUsers

icp_access deny all

and make a mysql database named squid, and run

CREATE TABLE `passwd` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`user` VARCHAR( 64 ) NOT NULL ,
`password` VARCHAR( 64 ) NOT NULL ,
`enabled` INT NOT NULL ,
`admin` INT NOT NULL
) ENGINE = MYISAM ;

then

INSERT INTO `passwd` ( `id` , `user` , `password` , `enabled` , `admin` )
VALUES (
NULL , 'username', 'password', '1', '1'
);

to create your enabled admin account, (please note username and password in the VALUES() should be your username and password
if you need more help with this please feel free to email me at tweak.servermaster@gmail.com

Last edited by twek (2010-10-28 10:03:44)

Offline

#3 2010-03-09 12:14:55

linuxloonie
Member
Registered: 2010-03-09
Posts: 1

Re: [SOLVED] help with squid mysql authentication!

Am also trying to do the same thing, I was able to achieve authentication with the help of "mysql_auth" external auth program for squid but it has a major drawback in that it is allowing simultaneous use of the username/password.Can you please write a step-by-step tutorial on how you achieved this feat and also how to use your authentication program.It'll be really use full for all of us.

Offline

#4 2010-10-28 09:46:25

twek
Member
Registered: 2009-07-24
Posts: 15

Re: [SOLVED] help with squid mysql authentication!

linuxloonie, sorry i dont check this very often but i updated my post to be pretty step by step, i hope it helps

Offline

Board footer

Powered by FluxBB