亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cache.c

?? radius服務器
?? C
字號:
/* * cache.c	Offers ability to cache /etc/group, /etc/passwd, * 		/etc/shadow, * * 		All users in the passwd/shadow files are stored in a hash table. * 		the hash lookup is VERY fast,  generally 1.0673 comparisons per * 		lookup.  For the unitiated, that's blazing.  You can't have less * 		than one comparison, for example. * * 		The /etc/group file is stored in a singly linked list, as that * 		appears to be fast enough.  It's generally a small enough file * 		that hashing is	unnecessary. * * Version: $Id: cache.c,v 1.25 2004/02/26 19:04:37 aland Exp $ * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Copyright 2000  The FreeRADIUS server project. * Copyright 1999  Jeff Carneal <jeff@apex.com>, Apex Internet Services, Inc. * Copyright 2000  Alan DeKok <aland@ox.org> */static const char rcsid[] = "$Id: cache.c,v 1.25 2004/02/26 19:04:37 aland Exp $";#include "autoconf.h"#include	"libradius.h"#include "config.h"#include <stdio.h>#include <string.h>#include <fcntl.h>#include <grp.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include <sys/stat.h>#include <sys/types.h>#ifdef HAVE_SHADOW_H#  include <shadow.h>#endif#include "radiusd.h"#include "cache.h"#include "compat.h"/* *  Static prototypes */static struct mypasswd *findHashUser(struct pwcache *cache, const char *user);static int storeHashUser(struct pwcache *cache, struct mypasswd *new, int idx);static int hashUserName(const char *s);/* Builds the hash table up by storing passwd/shadow fields * in memory.  Returns NULL on failure, pointer to the cache on success. */struct pwcache *unix_buildpwcache(const char *passwd_file,                                  const char *shadow_file,                                  const char *group_file){	FILE *passwd;#ifdef HAVE_SHADOW_H	FILE *shadow;#endif	FILE *group;	char buffer[BUFSIZE];	char idtmp[10];	char username[256];	char *ptr, *bufptr;	int len, hashindex, numread=0;	struct mypasswd *new, *cur;	int len2, idx;	struct group *grp;	struct mygroup *g_new;	char **member;        struct pwcache *cache;	if (!passwd_file) {		radlog(L_ERR, "rlm_unix:  You MUST specify a password file!");		return NULL;	}	if (!group_file) {		radlog(L_ERR, "rlm_unix:  You MUST specify a group file!");		return NULL;	}#ifdef HAVE_SHADOW_H	if (!shadow_file) {		radlog(L_ERR, "rlm_unix:  You MUST specify a shadow password file!");		return NULL;	}#endif	cache = rad_malloc(sizeof(*cache));	memset(username, 0, sizeof(username));	/* Init hash array */	memset(cache->hashtable, 0, sizeof cache->hashtable);	cache->grphead = NULL;	if ((passwd = fopen(passwd_file, "r")) == NULL) {		radlog(L_ERR, "rlm_unix:  Can't open file password file %s: %s",		    passwd_file, strerror(errno));		unix_freepwcache(cache);		return NULL;	}	while(fgets(buffer, BUFSIZE , passwd) != (char *)NULL) {		numread++;		bufptr = buffer;		/* Get usernames from password file */		for(ptr = bufptr; *ptr!=':'; ptr++);		len = ptr - bufptr;		if((len+1) > MAX_STRING_LEN) {			radlog(L_ERR, "rlm_unix:  Username too long in line: %s", buffer);		}		strncpy(username, buffer, len);		username[len] = '\0';		/* Hash the username */		hashindex = hashUserName(username);		/*printf("%s:%d\n", username, hashindex);*/		/* Allocate space for structure to go in hashtable */		new = (struct mypasswd *)rad_malloc(sizeof(struct mypasswd));		memset(new, 0, sizeof(struct mypasswd));		/* Put username into new structure */		new->pw_name = (char *)rad_malloc(strlen(username)+1);		strncpy(new->pw_name, username, strlen(username)+1);		/* Put passwords into array, if not shadowed */		/* Get passwords from password file (shadow comes later) */		ptr++;		bufptr = ptr;		while(*ptr!=':')			ptr++;#if !HAVE_SHADOW_H		/* Put passwords into new structure (*/		len = ptr - bufptr;		if (len > 0) {			new->pw_passwd = (char *)rad_malloc(len+1);			strncpy(new->pw_passwd, bufptr, len);			new->pw_passwd[len] = '\0';		} else {			new->pw_passwd = NULL;		}#endif /* !HAVE_SHADOW_H */		/*		 * Put uid into structure.  Not sure why, but		 * at least we'll have it later if we need it		 */		ptr++;		bufptr = ptr;		while(*ptr!=':')			ptr++;		len = ptr - bufptr;		strncpy(idtmp, bufptr, len);		idtmp[len] = '\0';		new->pw_uid = (uid_t)atoi(idtmp);		/*		 * Put gid into structure.		 */		ptr++;		bufptr = ptr;		while(*ptr!=':')			ptr++;		len = ptr - bufptr;		strncpy(idtmp, bufptr, len);		idtmp[len] = '\0';		new->pw_gid = (gid_t)atoi(idtmp);		/*		 * Put name into structure.		 */		ptr++;		bufptr = ptr;		while(*ptr!=':')			ptr++;		len = ptr - bufptr;		new->pw_gecos = (char *)rad_malloc(len+1);		strncpy(new->pw_gecos, bufptr, len);		new->pw_gecos[len] = '\0';		/*		 * We'll skip home dir and shell		 * as I can't think of any use for storing them		 */		/*printf("User:  %s, UID:  %d, GID:  %d\n", new->pw_name, new->pw_uid, new->pw_gid);*/		/* Store user in the hash */		storeHashUser(cache, new, hashindex);	}	/* End while(fgets(buffer, BUFSIZE , passwd) != (char *)NULL) */	fclose(passwd);#ifdef HAVE_SHADOW_H	/*	 *	FIXME: Check for password expiry!	 */	if ((shadow = fopen(shadow_file, "r")) == NULL) {		radlog(L_ERR, "HASH:  Can't open file %s: %s",		    shadow_file, strerror(errno));		unix_freepwcache(cache);		return NULL;	} else {		while(fgets(buffer, BUFSIZE , shadow) != (char *)NULL) {			bufptr = buffer;			/* Get usernames from shadow file */			for(ptr = bufptr; *ptr!=':'; ptr++);			len = ptr - bufptr;			if((len+1) > MAX_STRING_LEN) {				radlog(L_ERR, "HASH:  Username too long in line: %s", buffer);			}			strncpy(username, buffer, len);			username[len] = '\0';			if((new = findHashUser(cache, username)) == NULL) {				radlog(L_ERR, "HASH:  Username %s in shadow but not passwd??", username);				continue;			}			/*			 * In order to put passwd in correct structure, we have			 * to skip any struct that has a passwd already for that			 * user			 */			cur = new;			while(new && (strcmp(new->pw_name, username)<=0)						&& (new->pw_passwd == NULL)) {				cur = new;				new = new->next;			}			/* Go back one, we passed it in the above loop */			new = cur;			/*			 * When we get here, we should be at the last duplicate			 * user structure in this hash bucket			 */			/* Put passwords into struct from shadow file */			ptr++;			bufptr = ptr;			while(*ptr!=':')				ptr++;			len = ptr - bufptr;			if (len > 0) {				new->pw_passwd = (char *)rad_malloc(len+1);				strncpy(new->pw_passwd, bufptr, len);				new->pw_passwd[len] = '\0';			} else {				new->pw_passwd = NULL;			}		}	}	fclose(shadow);#endif	/* log how many entries we stored from the passwd file */	radlog(L_INFO, "HASH:  Stored %d entries from %s", numread, passwd_file);	/* The remainder of this function caches the /etc/group or equivalent	 * file, so it's one less thing we have to lookup on disk.  it uses	 * fgetgrent(), which is quite slow, but the group file is generally	 * small enough that it won't matter	 * As a side note, caching the user list per group was a major pain	 * in the ass, and I won't even need it.  I really hope that somebody	 * out there needs and appreciates it.	 */	if ((group = fopen(group_file, "r")) == NULL) {		radlog(L_ERR, "rlm_unix:  Can't open file group file %s: %s",		    group_file, strerror(errno));		unix_freepwcache(cache);		return NULL;	}	numread = 0;	/* Get next entry from the group file */	while((grp = fgetgrent(group)) != NULL) {		/* Make new mygroup structure in mem */		g_new = (struct mygroup *)rad_malloc(sizeof(struct mygroup));		memset(g_new, 0, sizeof(struct mygroup));		/* copy grp entries to my structure */		len = strlen(grp->gr_name);		g_new->gr_name = (char *)rad_malloc(len+1);		strncpy(g_new->gr_name, grp->gr_name, len);		g_new->gr_name[len] = '\0';		len = strlen(grp->gr_passwd);		g_new->gr_passwd= (char *)rad_malloc(len+1);		strncpy(g_new->gr_passwd, grp->gr_passwd, len);		g_new->gr_passwd[len] = '\0';		g_new->gr_gid = grp->gr_gid;		/* Allocate space for user list, as much as I hate doing groups	  	 * that way.		 */		for(member = grp->gr_mem; *member!=NULL; member++);		len = member - grp->gr_mem;		g_new->gr_mem = (char **)rad_malloc((len+1)*sizeof(char **));		/* Now go back and copy individual users into it */		for(member = grp->gr_mem; *member; member++) {			len2 = strlen(*member);			idx = member - grp->gr_mem;			g_new->gr_mem[idx] = (char *)rad_malloc(len2+1);			strncpy(g_new->gr_mem[idx], *member, len2);			g_new->gr_mem[idx][len2] = '\0';		}		/* Make sure last entry in user list is 0 so we can loop thru it */		g_new->gr_mem[len] = 0;		/* Insert at beginning of list */		g_new->next = cache->grphead;		cache->grphead = g_new;		numread++;	}	/* End */	fclose(group);	radlog(L_INFO, "HASH:  Stored %d entries from %s", numread, group_file);	return cache;}void unix_freepwcache(struct pwcache *cache){	int hashindex;	struct mypasswd *cur, *next;	struct mygroup *g_cur, *g_next;	char **member;	for(hashindex=0; hashindex<HASHTABLESIZE; hashindex++) {		if(cache->hashtable[hashindex]) {			cur = cache->hashtable[hashindex];			while(cur) {				next = cur->next;				free(cur->pw_name);				if (cur->pw_passwd) free(cur->pw_passwd);				free(cur->pw_gecos);				free(cur);				cur = next;			}		}	}	g_cur = cache->grphead;	while(g_cur) {		g_next = g_cur->next;		/* Free name, name, member list */		for(member = g_cur->gr_mem; *member; member++) {			free(*member);		}		free(g_cur->gr_mem);		free(g_cur->gr_name);		free(g_cur->gr_passwd);		free(g_cur);		g_cur = g_next;	}	free(cache);}/* * Looks up user in hashtable.  If user can't be found, returns 0. * Otherwise returns a pointer to the structure for the user */static struct mypasswd *findHashUser(struct pwcache *cache, const char *user){	struct mypasswd *cur;	int idx;	/* first hash the username and get the index into the hashtable */	idx = hashUserName(user);	cur = cache->hashtable[idx];	while((cur != NULL) && (strcmp(cur->pw_name, user))) {		cur = cur->next;	}	if(cur) {		DEBUG2("  HASH:  user %s found in hashtable bucket %d", user, idx);		return cur;	}	return (struct mypasswd *)0;}/* Stores the username sent into the hashtable */static int storeHashUser(struct pwcache *cache, struct mypasswd *new, int idx){	/* store new record at beginning of list */	new->next = cache->hashtable[idx];	cache->hashtable[idx] = new;	return 1;}/* Hashes the username sent to it and returns index into hashtable */static int hashUserName(const char *s) {	unsigned long hash = 0;	while (*s != '\0') {		hash = hash * 7907 + (unsigned char)*s++;	}	return (hash % HASHTABLESIZE);}/* *	Emulate the cistron unix_pass function, but do it using *	our hashtable (iow, make it blaze). * return  0 on success * return -1 on failure * return -2 on error (let caller fall back to old method) */int H_unix_pass(struct pwcache *cache, char *name, char *passwd,		VALUE_PAIR **reply_items){	struct mypasswd	*pwd;	char *encrypted_pass;	/*	 *	Get encrypted password from password file	 */	if ((pwd = findHashUser(cache, name)) == NULL) {		/* Default to old way if user isn't hashed */		return -2;	}	encrypted_pass = pwd->pw_passwd;	/*	 *	We might have a passwordless account.	 */	if(encrypted_pass == NULL) return 0;	if(mainconfig.do_usercollide) {		while(pwd) {			/*		 	 * Make sure same user still.  If not, return as if			 * wrong pass given			 */			if(strcmp(name, pwd->pw_name))				return -1;			/*		 	 * Could still be null passwd			 */			encrypted_pass = pwd->pw_passwd;			if (encrypted_pass == NULL) {				return 0;			}			/*		 	 * Check password			 */			if(lrad_crypt_check(passwd, encrypted_pass) == 0) {				/*				 * Add 'Class' pair here with value of full				 * name from passwd				 */				if(strlen(pwd->pw_gecos))					pairadd(reply_items, pairmake("Class", pwd->pw_gecos, T_OP_EQ));				return 0;			}			pwd = pwd->next;		}		/*		 * If we get here, pwd is null, and no users matched		 */		return -1;	} else {		/*		 *	Check encrypted password.		 */		if (lrad_crypt_check(passwd, encrypted_pass))			return -1;		return 0;	}}/* * Emulate groupcmp in files.c, but do it (much) faster * return -2 on error (let caller fall back to old method), * -1 on match fail, or 0 on success */int H_groupcmp(struct pwcache *cache, VALUE_PAIR *check, char *username){	struct mypasswd *pwd;	struct mygroup *cur;	char **member;	/* get the user from the hash */	if (!(pwd = findHashUser(cache, username)))		return -2;	/* let's find this group */	if(cache->grphead) {		cur = cache->grphead;		while((cur) && (strcmp(cur->gr_name, (char *)check->strvalue))){			cur = cur->next;		}		/* found the group, now compare it */		if(!cur) {			/* Default to old function if we can't find it */			return -2;		} else {			if(pwd->pw_gid == cur->gr_gid) {				DEBUG2("  HASH:  matched user %s in group %s", username, cur->gr_name);				return 0;			} else {				for(member = cur->gr_mem; *member; member++) {					if (strcmp(*member, pwd->pw_name) == 0) {						DEBUG2("  HASH:  matched user %s in group %s", username, cur->gr_name);						return 0;					}				}			}		}	}	return -1;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲午夜久久久| 91精品婷婷国产综合久久性色 | 国产视频一区二区在线观看| 久久精品一区二区三区av| 1区2区3区国产精品| 亚洲国产wwwccc36天堂| 精品一区二区三区在线视频| 成人免费av网站| 欧美精品粉嫩高潮一区二区| 国产亚洲一区二区三区| 亚洲成av人片在线| 国产.欧美.日韩| 69p69国产精品| 亚洲欧洲日韩av| 久久99国产精品尤物| 色综合色狠狠综合色| 日韩欧美国产一区二区三区 | 91蜜桃在线免费视频| 日韩一区二区三区四区| 亚洲视频在线一区二区| 麻豆91在线播放免费| 在线亚洲+欧美+日本专区| 久久先锋影音av鲁色资源网| 亚洲国产日韩a在线播放| 国产夫妻精品视频| 正在播放亚洲一区| 亚洲人精品午夜| 国产美女一区二区| 69p69国产精品| 亚洲精品国产视频| 国产iv一区二区三区| 欧美一区二区日韩| 亚洲国产精品一区二区久久恐怖片 | 91福利在线播放| 久久久www成人免费毛片麻豆| 亚洲成a天堂v人片| 91免费看片在线观看| 国产午夜精品一区二区三区视频| 日韩1区2区日韩1区2区| 欧美性猛交xxxx黑人交| 国产精品久久久久久久久图文区| 国产在线视频一区二区| 91精品国产乱码| 午夜激情一区二区三区| 91农村精品一区二区在线| 欧美高清在线精品一区| 久久99精品久久久久婷婷| 69p69国产精品| 香蕉影视欧美成人| 色94色欧美sute亚洲线路一久| 国产精品美女久久久久久久久久久 | 欧美日韩中文国产| 亚洲欧美视频一区| 东方欧美亚洲色图在线| 精品成人a区在线观看| 麻豆成人免费电影| 波多野结衣中文字幕一区二区三区| 久久久噜噜噜久噜久久综合| 经典三级一区二区| 精品国产一区二区三区不卡| 免费美女久久99| 日韩一本二本av| 蜜臀av亚洲一区中文字幕| 欧美精品亚洲一区二区在线播放| 一区二区三区久久| 色欧美日韩亚洲| 一区二区在线观看视频| 一本色道亚洲精品aⅴ| 亚洲女同ⅹxx女同tv| 91老司机福利 在线| 亚洲精品视频在线观看网站| 色综合久久99| 亚洲午夜久久久久| 欧美剧情电影在线观看完整版免费励志电影 | 激情综合色播五月| 日本高清免费不卡视频| 日韩一区和二区| 1024成人网| 久久精品国产亚洲一区二区三区| 欧美丰满美乳xxx高潮www| 天堂一区二区在线| 欧美一区二区福利视频| 蜜臀久久99精品久久久久宅男| 日韩视频中午一区| 韩国精品主播一区二区在线观看| 久久精品欧美日韩| 成人黄动漫网站免费app| 亚洲色图.com| 777亚洲妇女| 精品一区二区三区蜜桃| 国产午夜精品一区二区三区嫩草 | 精品入口麻豆88视频| 久久69国产一区二区蜜臀| 26uuu另类欧美| 成人午夜视频在线观看| 综合久久久久久久| 欧美电影在线免费观看| 国产一区二区视频在线| 综合色天天鬼久久鬼色| 欧美老肥妇做.爰bbww视频| 免费在线欧美视频| 欧美激情一区二区三区不卡| 99re这里只有精品6| 午夜精品福利一区二区三区蜜桃| 欧美成人精品1314www| 成人涩涩免费视频| 亚洲第一狼人社区| 久久人人97超碰com| 日本韩国精品在线| 精品一区二区三区视频在线观看| 中文字幕高清不卡| 欧美性色黄大片手机版| 国产毛片精品视频| 一区二区三区在线看| 精品人伦一区二区色婷婷| 99在线热播精品免费| 日韩成人免费在线| 国产精品久久二区二区| 69堂国产成人免费视频| 成a人片国产精品| 免费高清成人在线| 亚洲女爱视频在线| 精品免费一区二区三区| 色综合天天狠狠| 久久99久久精品欧美| 亚洲欧美电影院| ww亚洲ww在线观看国产| 色女孩综合影院| 7799精品视频| jvid福利写真一区二区三区| 日韩精品成人一区二区在线| 国产精品白丝在线| 精品成人佐山爱一区二区| 欧美性生交片4| 国产91在线看| 久久综合综合久久综合| 亚洲日本va在线观看| 久久日韩精品一区二区五区| 在线观看精品一区| 成人一道本在线| 极品少妇xxxx精品少妇偷拍| 亚洲最大成人综合| 国产精品激情偷乱一区二区∴| 日韩一区二区三区电影| 在线免费观看视频一区| a4yy欧美一区二区三区| 国产伦精品一区二区三区视频青涩 | 国产成人在线电影| 日本vs亚洲vs韩国一区三区二区 | 欧美日本韩国一区二区三区视频| 成人午夜激情影院| 久久99这里只有精品| 偷窥少妇高潮呻吟av久久免费| 亚洲精选免费视频| 中文字幕亚洲欧美在线不卡| 久久久五月婷婷| 日韩一级二级三级| 欧美精品久久99| 欧美影院一区二区三区| 91在线视频播放| av资源站一区| youjizz久久| 成人av网址在线观看| 国产福利精品一区| 国产精品主播直播| 国产一区二区三区| 韩国av一区二区三区四区| 久久福利视频一区二区| 久久se精品一区精品二区| 日韩黄色小视频| 日韩精品欧美精品| 日韩高清不卡一区| 蜜臀av性久久久久av蜜臀妖精 | 欧美mv和日韩mv的网站| 欧美大片国产精品| 日韩写真欧美这视频| 91精品国产欧美一区二区成人| 这里只有精品免费| 日韩视频一区二区三区在线播放 | 国产一区视频网站| 国内精品不卡在线| 国产成人免费高清| av电影一区二区| 色香蕉久久蜜桃| 在线观看一区不卡| 欧美日韩在线不卡| 欧美一卡二卡在线| 精品久久99ma| 国产日韩精品一区| 国产精品不卡一区二区三区| 亚洲素人一区二区| 亚洲一区二区三区自拍| 午夜激情一区二区| 久久精品国产久精国产爱| 国产精品一线二线三线| 成人听书哪个软件好| 91麻豆免费视频| 欧美乱妇15p| www欧美成人18+| 国产精品久久久久毛片软件|