mysql_auth.c   一段C代码

/*

*  *  mysql_auth.c

*   *

*    *  Copyright 1998 Frank Liu ([email protected])

*     *  Distributed under the GPL

*      *

*       *  26 Sep 1999, version 2:

*        *    1. fixed a bug where A_TABLE is defined but never used.

*         *       (thanks to [email protected])

*          *    2. now you can choose to use either clear text password or

*           *       encrypted password in the MySQL table.

*            *  13 Nov 1998, version 1:

*             *    initial release

*              *  Needs to be compiled/linked with MySQL libs.

*               *  Assuming MySQL header files are installed in /usr/local/mysql/include

*                *  and MySQL libs in /usr/local/mysql/lib

*                 *

*                  *

*                   * gcc -O2 -Wall -o mysql_auth mysql_auth.c -L /usr/lib/mysql -lmysqlclient

*                    *

*                     *  Dec, 2002.

*                      *  Modfied by Jiang.

*                       *  Add support for crypt password.

*                        */

#include "/usr/include/mysql/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 "squid"

#define DB "mysql_auth"

#define DBPASSWORD "squid"

/* table for the user database for the squid authentication,

*    column names for auth username and auth password */

#define A_TABLE  "test"

#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);

}

时间: 2024-08-03 00:18:51

mysql_auth.c   一段C代码的相关文章

BSS段、数据段、代码段、堆与栈

BSS段:BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域. BSS是英文Block Started by Symbol的简称.BSS段属于静态内存分配. 数据段:数据段(data segment)通常是指用来存放程序中已初始化的全局变量的一块内存区域. 数据段属于静态内存分配. 代码段:代码段(code segment/text segment)通常是指用来存放程序执行代码的一块内存区 域.这部分区域的大小在程序运行前就已经确定,并且内存区域通常属于只读

Supermap iClient 空间查询关联外表表查询多表字段示例代码

原创文章,转载请注明出处!http://blog.csdn.net/songhfu 空间查询关联属性表,并查询空间表和关联表字段示例代码如下: /* * 关联测试成功代码 * */ var joinItem=new SuperMap.REST.JoinItem({ foreignTableName: "V_ENABLEVIEW_LAND", joinFilter: "BBS_PARCEL.CADASTRALNO = V_ENABLEVIEW_LAND.CADASTRALNO

程序中的bss段,data段,代码段,堆,栈

程序中的bss段,data段,代码段(.text),堆(heap),栈(stack) .bss段:程序中未初始化的和已经初始化为0的全局变量和已经初始化为0的静态局部变量(static) .data段:程序中已经初始化的非零的全局变量和已经初始化的非零的静态局部变量(static) 代码段:用来存放代码的地方(.text段),不可修改,存放在只读区域内. 堆:程序员自己申请的内存区域,也就是用malloc()函数申请的内存区域,用free()函数来释放的区域. 栈:存放局部变量的区域,函数中的局

因一段JavaScript代码引发的闲扯

前两天,一朋友给我发了一段JavaScript代码: function f1(){ var n=999; nAdd=function(){ n+=1 }; function f2(){ alert(n); } return f2; } var result1=f1(); var result2=f1(); result1(); // 999 result2();//999 nAdd(); result1(); // 是999而不是1000,这是为何呢? result2();//1000 问题的原

可执行程序包括BSS段、数据段、代码段

可执行程序包括BSS段.数据段.代码段(也称文本段). 一.BSS BSS(Block Started by Symbol)通常是指用来存放程序中未初始化的全局变量和静态变量的一块内存区域.特点是:可读写的,在程序执行之前BSS段会自动清0.所以,未初始的全局变量在程序执行之前已经成0了. 注意和数据段的区别,BSS存放的是未初始化的全局变量和静态变量,数据段存放的是初始化后的全局变量和静态变量. UNIX下可使用size命令查看可执行文件的段大小信息.如size a.out. 二.数据段 在采

一段C++代码想到的问题

今天在学习<Unix环境高级编程>,第七章进程环境给出了一个进程的内存分布示意图,从下往上依次为“正文段->初始化数据->未初始化数据(默认初始化为0)->堆(从低地址到高地址)->栈(从高地址到低地址)->命令行参数和环境变量”.其中的正文段也叫代码段,是可共享的,只读的. 这个时候我就想到上次做的腾讯的一个题目,其实很简单,大概意思如下所示代码所示.大概意思是,先创建了一个类的对象a,再将a内存清0,然后直接调用两个的一个是虚函数一个是非虚函数,看看能否正确访

自己写的一段重试代码

public class TestRetry { public static void main(String[] args) { retry(5); } private static void retry(int maxCount) { int count = 0; boolean result = false; do { count++; System.out.println("count="+count); /* if(count==2) { result = true; }*/

(转)Linux下数据段的区别(数据段、代码段、堆栈段、BSS段)

进程(执行的程序)会占用一定数量的内存,它或是用来存放从磁盘载入的程序代码,或是存放取自用户输入的数据等等.不过进程对这些内存的管理方式因内存用途 不一而不尽相同,有些内存是事先静态分配和统一回收的,而有些却是按需要动态分配和回收的.对任何一个普通进程来讲,它都会涉及到5种不同的数据段. Linux进程的五个段 下面我们来简单归纳一下进程对应的内存空间中所包含的5种不同的数据区都是干什么的. BSS段:BSS段(bss segment)通常是指用来存放程序中未初始化的全局变量的一块内存区域.BS

Javascript中最常用的61段经典代码

1. oncontextmenu="window.event.returnValue=false" 将彻底屏蔽鼠标右键 <table border oncontextmenu=return(false)><td>no</table> 可用于Table 2. <body onselectstart="return false"> 取消选取.防止复制 3. onpaste="return false"