LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1051|回复: 0

Linux下架设代理服务器的squid基于mysql的用户认证 提问?

[复制链接]
发表于 2003-4-12 23:32:25 | 显示全部楼层 |阅读模式
Linux下架设代理服务器的squid基于mysql的用户认证

数据库路径、用户名、密码、数据库、表、字段全都没错!
mysql_auth.c 文件内容是

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mysql.h"

/* comment out next line if you use clear text password in MySQL DB */
#define ENCRYPTED_PASS

/* can use NULL for localhost, current user, or no password */
#define DBHOST "localhost"
#define DBUSER "squiduser"
#define DB "http"
#define DBPASSWORD "squidpass"

/* table for the user database for the squid authentication,
   column names for auth username and auth password */
#define A_TABLE  "http"
#define A_USERNAME "username"
#define A_PASSWORD "passwd"

#define BUFSIZE         256

void main(int argc, char *argv[])
{
    char buf[BUFSIZE], qbuf[BUFSIZE];
    char *p;
    MYSQL mysql,*sock;
    MYSQL_RES *res;

    /* make standard output line buffered */
    if (setvbuf(stdout, NULL, _IOLBF, 0) != 0)
        return;

    while (1) {
        if (fgets(buf, BUFSIZE, stdin) == NULL)
            break;
        if ((p = strchr(buf, '\n')) != NULL)
            *p = '\0';          /* strip \n */
        if ((p = strchr(buf, ' ')) == NULL) {
            (void) printf("ERR\n");
            continue;
        }
        *p   = '\0';

        /* buf is username and p is password now */

        if (!(sock = mysql_connect(&mysql, DBHOST, DBUSER, DBPASSWORD)))
        {
            /* couldn't connect to database server */
            (void) printf("ERR\n");
            continue;
        }
        if (mysql_select_db(sock, DB))
        {
            /* couldn't use the database */
            (void) printf("ERR\n");
            mysql_close(sock);
            continue;
        }
        sprintf(qbuf, "select " A_USERNAME " from " A_TABLE " where "
                       A_USERNAME "='%s' and " A_PASSWORD

#ifdef ENCRYPTED_PASS
                      "=password('%s')", buf, p);
#else
                      "='%s'", buf, p);
#endif
        if(mysql_query(sock,qbuf) || !(res=mysql_store_result(sock)))
        {
            /* query failed */
            (void) printf("ERR\n");
            mysql_close(sock);
            continue;
        }
        if ( res->row_count !=0 )
            (void) printf("OK\n");
        else
            (void) printf("ERR\n");
        mysql_free_result(res);
        mysql_close(sock);
    }
    exit(0);
}


编译时用
  c   -I /usr/include/mysql -O -o mysql_auth mysql_auth.c \
       -L /usr/lib/mysql -lmysqlclient -lm

后出错:
mysql_auth.c: In function `int main(...)':
mysql_auth.c:63: `return' with no value, in function returning non-void


怎么解决??
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表