diff --git a/Product/user/user_auth/authfree_configure.c b/Product/user/user_auth/authfree_configure.c deleted file mode 100644 index 0d1ec1d09..000000000 --- a/Product/user/user_auth/authfree_configure.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -struct authfree_configure -{ - char name[32]; //免认证规则名称 - uint32_t sip; //免认证规则源ip - uint32_t dip; //免认证规则目的ip - int dport; //免认证规则目的端口号 - time_t begin_time; //有效时间范围的起始时间 - time_t over_time; //有效时间范围内的结束时间 -}; - -//判断IPv4格式是否正确 -int isIpV4Addr(const char *ipAddr) -{ - int ip_part_1 = 0; - int ip_part_2 = 0; - int ip_part_3 = 0; - int ip_part_4 = 0; - char end_char = 0; - if((NULL == ipAddr) || (0 == strlen(ipAddr))) - { - return -1; - } - if(4 == sscanf(ipAddr,"%d.%d.%d.%d%c",&ip_part_1,&ip_part_2,&ip_part_3,&ip_part_4,&end_char)) - { - if((ip_part_1 >= 0) && (ip_part_1 <= 255) && - (ip_part_2 >= 0) && (ip_part_2 <= 255) && - (ip_part_3 >= 0) && (ip_part_3 <= 255) && - (ip_part_4 >= 0) && (ip_part_4 <= 255) - ) - { - return 0; - } - } - return -1; -} - - -//判断免认证规则是否有效,所有条件有效则返回值为0,其中一项条件无效则返回值为1 -int _valid_authfreerule(struct authfree_configure *s) -{ - char sstr[32]; - inet_ntop(AF_INET, (void *)&s->sip, sstr, 32); - char *sip_addr = sstr; - if(!isIpV4Addr(sip_addr)) - { - char dstr[32]; - inet_ntop(AF_INET, (void *)&s->dip, dstr, 32); - char *dip_addr = dstr; - if(!isIpV4Addr(dip_addr)) - { - time_t lt; - lt = time(NULL); - if( (memcmp(&s->sip, &s->dip, 32) < 0) & (lt >= s->begin_time) & (lt <= s->over_time)) - { - return 0; - } - else - { - return -1; - } - } - else - { - return -1; - } - } - else - { - return -1; - } -} - diff --git a/Product/user/user_auth/hlist.h b/Product/user/user_auth/hlist.h deleted file mode 100644 index e049f555f..000000000 --- a/Product/user/user_auth/hlist.h +++ /dev/null @@ -1,136 +0,0 @@ -#ifndef __HLIST_H -#define __HLIST_H - -struct hlist_head { - struct hlist_node *first; -}; - -struct hlist_node { - struct hlist_node *next, **pprev; -}; - -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) - -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) - -#define HLIST_HEAD_INIT { .first = NULL } -#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } - -#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) - -static inline void INIT_HLIST_NODE(struct hlist_node *h) -{ - h->next = NULL; - h->pprev = NULL; -} - -static inline int hlist_unhashed(const struct hlist_node *h) -{ - return !h->pprev; -} - -static inline int hlist_empty(const struct hlist_head *h) -{ - return !h->first; -} - -static inline void __hlist_del(struct hlist_node *n) -{ - struct hlist_node *next = n->next; - struct hlist_node **pprev = n->pprev; - *pprev = next; - if (next) - next->pprev = pprev; -} - -static inline void hlist_del(struct hlist_node *n) -{ - __hlist_del(n); - n->next = NULL; - n->pprev = NULL; -} - -static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) -{ - struct hlist_node *first = h->first; - n->next = first; - if (first) - first->pprev = &n->next; - h->first = n; - n->pprev = &h->first; -} - - -static inline void hlist_del_init(struct hlist_node *n) -{ - if (!hlist_unhashed(n)) { - __hlist_del(n); - INIT_HLIST_NODE(n); - } -} - -static inline void hlist_add_before(struct hlist_node *n, - struct hlist_node *next) -{ - n->pprev = next->pprev; - n->next = next; - next->pprev = &n->next; - *(n->pprev) = n; -} - -static inline void hlist_add_after(struct hlist_node *n, - struct hlist_node *next) -{ - next->next = n->next; - n->next = next; - next->pprev = &n->next; - - if(next->next) - next->next->pprev = &next->next; -} - -static inline void hlist_move_list(struct hlist_head *old, - struct hlist_head *new) -{ - new->first = old->first; - if (new->first) - new->first->pprev = &new->first; - old->first = NULL; -} - -#define hlist_entry(ptr, type, member) container_of(ptr,type,member) - - -#define hlist_for_each_safe(pos, n, head) \ - for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ - pos = n) - -#define hlist_for_each_entry(tpos, pos, head, member) \ - for (pos = (head)->first; \ - pos && ({ prefetch(pos->next); 1;}) && \ - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = pos->next) - -#define hlist_for_each_entry_continue(tpos, pos, member) \ - for (pos = (pos)->next; \ - pos && ({ prefetch(pos->next); 1;}) && \ - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = pos->next) - -#define hlist_for_each_entry_from(tpos, pos, member) \ - for (; pos && ({ prefetch(pos->next); 1;}) && \ - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = pos->next) - -#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ - for (pos = (head)->first; \ - pos && ({ n = pos->next; 1; }) && \ - ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ - pos = n) - - - -#endif - \ No newline at end of file diff --git a/Product/user/user_auth/ku-hashtable.c b/Product/user/user_auth/ku-hashtable.c deleted file mode 100644 index eeeaaf2e2..000000000 --- a/Product/user/user_auth/ku-hashtable.c +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "hlist.h" -#include "k-hashtable.h" - -struct hlist_head *hash; -struct hlist_node *p = NULL, *n = NULL ; -int i = 0; -USER_INFO *pNode ; - -/*计算hash值 */ -struct hlist_head *call_hash(struct hlist_head *hash, uint32_t ip) -{ - unsigned int val = ip % 100; - return &hash[val]; -} - -/*初始化函数 */ -int Init_hash() -{ - hash = (struct hlist_head*)malloc(sizeof(*hash)*100); - if(NULL == hash) - { - printf("alloc error\n"); - return -1; - } - - for(i = 0; i < 100; i++) - INIT_HLIST_HEAD(&hash[i]); -} - - -/*查找用户信息*/ -struct user_info *kfind_user(uint32_t user_ip) -{ - hlist_for_each_safe(p,n,call_hash(hash,user_ip)) - { - pNode = hlist_entry(p, struct user_info ,hnode); - if(pNode != NULL) - printf("user_id :%d\n",pNode->id); - return pNode; - } -} - -/*增加用户信息*/ -int kadd_user(uint32_t user_ip, int user_id) -{ - USER_INFO *pNode =NULL; - hlist_for_each_safe(p,n,call_hash(hash, user_ip)) /*查找ip是否存在hash表中 */ - { - pNode = hlist_entry(p, struct user_info ,hnode); - if(pNode != NULL) - printf("IP ALEADY EXISTED\n"); - } - - if (pNode == NULL) - { - pNode = (struct user_info *)malloc(sizeof(struct user_info)); - if (NULL == pNode) - { - return -1; - } - memset(pNode,0,sizeof(struct user_info)); - INIT_HLIST_NODE(&pNode->hnode); - pNode->ip = user_ip; - hlist_add_head(&pNode->hnode, call_hash(hash, user_ip)); - } - pNode->id = user_id; - -} - -/*删除用户信息 */ -void kdelete_user(int user_ip) -{ - hlist_for_each_safe(p,n,call_hash(hash,user_ip)) - { - pNode = hlist_entry(p, struct user_info ,hnode); - hlist_del(&pNode->hnode); - free(pNode); - } -} - -/*删除所有的hash节点 */ -void kdelete_all() -{ - for(i = 0; i < 100; i++) - { - hlist_for_each_safe(p,n,&hash[i]) - { - pNode = hlist_entry(p, struct user_info ,hnode); - hlist_del(&pNode->hnode); - free(pNode); - } - } -} - -/*打印所有信息信息 */ -void kprintf_users() -{ - for(i = 0; i < 100; i++) - { - hlist_for_each_safe(p,n,&hash[i]) - { - char str[32]; - pNode = hlist_entry(p, struct user_info ,hnode); - if(pNode != NULL) - inet_ntop(AF_INET, (void *)&pNode->ip, str, 32); - printf("user_ip :%s user_id:%d\n", str, pNode->id); - } - } -} - diff --git a/Product/user/user_auth/ku-hashtable.h b/Product/user/user_auth/ku-hashtable.h deleted file mode 100644 index 1bd852a02..000000000 --- a/Product/user/user_auth/ku-hashtable.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef K_HASHTABLE_H -#define K_HASHTABLE_H -#include -#include "hlist.h" - -typedef struct user_info{ - struct hlist_node hnode; - int id; - uint32_t ip; -}USER_INFO; - -/*计算hash值 */ -struct hlist_head *call_hash(struct hlist_head *hash, uint32_t ip); - -/*初始化函数 */ -int Init_hash(); - -/*查找用户信息*/ -struct user_info *kfind_user(uint32_t user_ip); - -/*增加用户信息*/ -int kadd_user(uint32_t user_ip, int user_id); - -/*删除用户信息 */ -void kdelete_user(int user_ip); - -/*删除所有的hash节点 */ -void kdelete_all(); - -/*打印所有信息信息 */ -void kprintf_users(); - -#endif \ No newline at end of file diff --git a/Product/user/user_auth/port-ip.c b/Product/user/user_auth/port-ip.c deleted file mode 100644 index cc0184749..000000000 --- a/Product/user/user_auth/port-ip.c +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int _valid_ipv4_port(const char *str, int port) -{ - int ret; - int fd; - int i; - volatile int local_errno; - struct sockaddr_in addr; - fd = socket(AF_INET,SOCK_STREAM,0); //初始化socket - - - if(fd ==-1) //检查是否正常初始化socket - { - return -1; - } - - errno = 0; - local_errno = errno; - - ret = inet_pton(AF_INET, str ,&addr.sin_addr); - printf("the value of ret is:%d\n",ret); - if(ret > 0) - { - fprintf(stderr, "\"%s\" is a vaild IPv4 address\n", str); - - addr.sin_family = AF_INET; //地址结构的协议簇 - addr.sin_port=htons(port); //地址结构的端口地址,网络字节序 - printf("the value of str:%s\n", str); - i = (bind(fd, (struct sockaddr*)&addr, sizeof(struct sockaddr))); - printf("the value of i:%d\n", i); - - if( i < 0) - { - printf("port %d has been used. \n", port); - close(fd); - return -1; - } - - printf("port %d is ok. \n", port); - close(fd); - return 0; - } - - else if (ret < 0) - { - fprintf(stderr, "EAFNOSUPPORT: %s\n", strerror(local_errno)); - return -1; - } - else - { - fprintf(stderr, "\"%s\" is not a vaild IPv4 address\n", str); - return -1; - } -} \ No newline at end of file