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

由 gary9912 在 04-12-2003 23:32 发表:

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

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

数据库路径、用户名、密码、数据库、表、字段全都没错!

mysql_auth.c 文件内容是

#include

  1<stdio.h>   
  2  
  3#include <stdlib.h>   
  4  
  5#include <string.h>   
  6  
  7#include "mysql.h"   
  8  
  9  
 10  
 11/* comment out next line if you use clear text password in MySQL DB */   
 12  
 13#define ENCRYPTED_PASS   
 14  
 15  
 16  
 17/* can use NULL for localhost, current user, or no password */   
 18  
 19#define DBHOST "localhost"   
 20  
 21#define DBUSER "squiduser"   
 22  
 23#define DB "http"   
 24  
 25#define DBPASSWORD "squidpass"   
 26  
 27  
 28  
 29/* table for the user database for the squid authentication,   
 30  
 31column names for auth username and auth password */   
 32  
 33#define A_TABLE "http"   
 34  
 35#define A_USERNAME "username"   
 36  
 37#define A_PASSWORD "passwd"   
 38  
 39  
 40  
 41#define BUFSIZE 256   
 42  
 43  
 44  
 45void main(int argc, char *argv[])   
 46  
 47{   
 48  
 49char buf[BUFSIZE], qbuf[BUFSIZE];   
 50  
 51char *p;   
 52  
 53MYSQL mysql,*sock;   
 54  
 55MYSQL_RES *res;   
 56  
 57  
 58  
 59/* make standard output line buffered */   
 60  
 61if (setvbuf(stdout, NULL, _IOLBF, 0) != 0)   
 62  
 63return;   
 64  
 65  
 66  
 67while (1) {   
 68  
 69if (fgets(buf, BUFSIZE, stdin) == NULL)   
 70  
 71break;   
 72  
 73if ((p = strchr(buf, '\n')) != NULL)   
 74  
 75*p = '\0'; /* strip \n */   
 76  
 77if ((p = strchr(buf, ' ')) == NULL) {   
 78  
 79(void) printf("ERR\n");   
 80  
 81continue;   
 82  
 83}   
 84  
 85*p = '\0';   
 86  
 87  
 88  
 89/* buf is username and p is password now */   
 90  
 91  
 92  
 93if (!(sock = mysql_connect(&amp;mysql, DBHOST, DBUSER, DBPASSWORD)))   
 94  
 95{   
 96  
 97/* couldn't connect to database server */   
 98  
 99(void) printf("ERR\n");   
100  
101continue;   
102  
103}   
104  
105if (mysql_select_db(sock, DB))   
106  
107{   
108  
109/* couldn't use the database */   
110  
111(void) printf("ERR\n");   
112  
113mysql_close(sock);   
114  
115continue;   
116  
117}   
118  
119sprintf(qbuf, "select " A_USERNAME " from " A_TABLE " where "   
120  
121A_USERNAME "='%s' and " A_PASSWORD   
122  
123  
124  
125#ifdef ENCRYPTED_PASS   
126  
127"=password('%s')", buf, p);   
128  
129#else   
130  
131"='%s'", buf, p);   
132  
133#endif</string.h></stdlib.h></stdio.h>
Published At
Categories with 服务器类
Tagged with
comments powered by Disqus