#ifdef HAVE_LIMITS_H
#include <limits.h>;
#endif
/**************/
/* 引入md5头文件 */
#include<md5.h>;
/**************/
/* Uncomment the following define to allow OpenSSL hashed password checking;
* you'll also need to link with OpenSSL's crypto library ( -lcrypto )
*/
/* #define HAVE_OPENSSL */
/* default minimum id / default uid / default gid info.
* uids and gids less than MOD_SQL_MIN_USER_UID and
* MOD_SQL_MIN_USER_GID, respectively, get automatically
* mapped to the defaults, below. These can be
* overridden using directives
*/
#define MOD_SQL_MIN_USER_UID 999
#define MOD_SQL_MIN_USER_GID 999
#define MOD_SQL_DEF_UID 65533
#define MOD_SQL_DEF_GID 65533
#define SQL_GROUPS (cmap.authmask & SQL_AUTH_GROUPS)
#define SQL_USERS (cmap.authmask & SQL_AUTH_USERS)
#define SQL_GROUPSET (cmap.authmask & SQL_AUTH_GROUPSET)
#define SQL_USERSET (cmap.authmask & SQL_AUTH_USERSET)
#define SQL_FASTGROUPS (cmap.authmask & SQL_FAST_GROUPSET)
#define SQL_FASTUSERS (cmap.authmask & SQL_FAST_USERSET)
#define SQL_GROUPGOD (cmap.authmask & SQL_AUTH_GROUPS_DEFINITIVE)
#define SQL_USERGOD (cmap.authmask & SQL_AUTH_USERS_DEFINITIVE)
/*
* externs, function signatures.. whatever necessary to make
* the compiler happy..
*/
extern pr_response_t *resp_list,*resp_err_list;
static char *_sql_where(pool *p, int cnt, ...);
MODRET cmd_getgrent(cmd_rec *);
MODRET cmd_setgrent(cmd_rec *);
/* this struct holds invariant information for the current session */
static struct
{
/*
* info valid after getpwnam
*/
char *authuser; /* current authorized user */
struct passwd *authpasswd; /* and their passwd struct */
/*
* generic status information
*/
int status; /* is mod_sql on? */
int authmask; /* authentication mask.
* see set_sqlauthenticate for info */
/*
* user table and field information
*/
char *usrtable; /* user info table name */
char *usrfield; /* user name field */
char *pwdfield; /* user password field */
char *uidfield; /* user uid field */
char *gidfield; /* user gid field */
char *homedirfield; /* user homedir field */
char *shellfield; /* user login shell field */
char *userwhere; /* users where clause */
/*
* group table and field information
*/
char *grptable; /* group info table name */
char *grpfield; /* group name field */
char *grpgidfield; /* group gid field */
char *grpmembersfield; /* group members field */
char *groupwhere; /* groups where clause */
/*
* other information
*/
array_header *authlist; /* auth handler list */
char *defaulthomedir; /* default homedir if no field specified */
int buildhomedir; /* create homedir if it doesn't exist? */
uid_t minid; /* users UID must be this or greater */
uid_t minuseruid; /* users UID must be this or greater */
gid_t minusergid; /* users UID must be this or greater */
uid_t defaultuid; /* default UID if none in database */
gid_t defaultgid; /* default GID if none in database */
cache_entry_t *curr_group; /* next group in group array for getgrent */
cache_entry_t *curr_passwd; /* next passwd in passwd array for getpwent */
int group_cache_filled;
int passwd_cache_filled;
unsigned char negative_cache; /* cache negative as well as positive lookups */
/*
* mod_ratio data -- someday this needs to be removed from mod_sql
*/
char *sql_fstor; /* fstor int(11) NOT NULL DEFAULT '0', */
char *sql_fretr; /* fretr int(11) NOT NULL DEFAULT '0', */
char *sql_bstor; /* bstor int(11) NOT NULL DEFAULT '0', */
char *sql_bretr; /* bretr int(11) NOT NULL DEFAULT '0', */
char *sql_frate; /* frate int(11) NOT NULL DEFAULT '5', */
char *sql_fcred; /* fcred int(2) NOT NULL DEFAULT '15', */
char *sql_brate; /* brate int(11) NOT NULL DEFAULT '5', */
char *sql_bcred; /* bcred int(2) NOT NULL DEFAULT '150000', */
char *digestname; /* ptr to name of the digest function */
char *hashvalue; /* ptr to hashed value we're comparing to */
char *copyhash; /* temporary copy of the c_hash string */
if (c_hash[0] != '{') {
return ERROR_INT(cmd, PR_AUTH_BADPWD);
}
/*
* we need a copy of c_hash
*/
copyhash = pstrdup(cmd->;tmp_pool, c_hash);
digestname = copyhash + 1;
hashvalue = (char *) strchr(copyhash, '}');
if (hashvalue == NULL) {
return ERROR_INT(cmd, PR_AUTH_BADPWD);
}
*hashvalue = '\0';
hashvalue++;
OpenSSL_add_all_digests();
md = EVP_get_digestbyname(digestname);
if (!md) {
return ERROR_INT(cmd, PR_AUTH_BADPWD);
}