认证流程【4】-http_callback_auth()函数
来源:互联网 发布:传承网络 编辑:程序博客网 时间:2024/06/04 19:14
void http_callback_auth(httpd *webserver, request *r)
{
t_client *client;
httpVar * token;
char *mac;
httpVar *logout = httpdGetVariableByName(r, "logout");
if (wx_link_wifi == 1) {
debug(LOG_DEBUG, "#####http_callback_auth#######: %s/%s\r\n", r->request.host, r->request.path);
return;
}
t_client *client;
httpVar * token;
char *mac;
httpVar *logout = httpdGetVariableByName(r, "logout");
if (wx_link_wifi == 1) {
debug(LOG_DEBUG, "#####http_callback_auth#######: %s/%s\r\n", r->request.host, r->request.path);
return;
}
debug(LOG_DEBUG, "!!!!http_callback_auth!!!\n");
/* 检查http 报文里有没有token*/
if ((token = httpdGetVariableByName(r, "token"))) {
/* They supplied variable "token" */
/* 然后通过arp_get 拿该报文发送者的ip 对应的MAC 地址*/
if (!(mac = arp_get(r->clientAddr))) {
/* We could not get their MAC address */
debug(LOG_ERR, "Failed to retrieve MAC address for ip %s", r->clientAddr);
send_http_page(r, "WiFiDog Error", "Failed to retrieve your MAC address");
} else {
/* We have their MAC address */
/* We could not get their MAC address */
debug(LOG_ERR, "Failed to retrieve MAC address for ip %s", r->clientAddr);
send_http_page(r, "WiFiDog Error", "Failed to retrieve your MAC address");
} else {
/* We have their MAC address */
LOCK_CLIENT_LIST();
/* 到之前提到的客户端链表里搜此ip 和mac 对应的客户端*/
if ((client = client_list_find(r->clientAddr, mac)) == NULL) {
/* 搜不到,说明是新的客户端接入,那么就需要把它追加到链表里*/
debug(LOG_DEBUG, "New client for %s", r->clientAddr);
client_list_append(r->clientAddr, mac, token->value);
client_list_append(r->clientAddr, mac, token->value);
} else if (logout) {
/*客户端是logout请求(http报文请求里有logout)
网关会发一个关于此客户端下线的通知到认证服务器*/
t_authresponse authresponse;
s_config *config = config_get_config();
unsigned long long incoming = client->counters.incoming;
unsigned long long outgoing = client->counters.outgoing;
char *ip = safe_strdup(client->ip);
char *urlFragment = NULL;
t_auth_serv *auth_server = get_auth_server();
fw_deny(client->ip, client->mac, client->fw_connection_state);
qos_del_user(client);
client_list_delete(client);
debug(LOG_DEBUG, "Got logout from %s", client->ip);
/* Advertise the logout if we have an auth server */
if (config->auth_servers != NULL) {
UNLOCK_CLIENT_LIST();
auth_server_request(&authresponse, REQUEST_TYPE_LOGOUT, ip, mac, token->value,
incoming, outgoing);
LOCK_CLIENT_LIST();
/* Re-direct them to auth server */
debug(LOG_INFO, "Got manual logout from client ip %s, mac %s, token %s"
"- redirecting them to logout message", client->ip, client->mac, client->token);
safe_asprintf(&urlFragment, "%smessage=%s",
auth_server->authserv_msg_script_path_fragment,
GATEWAY_MESSAGE_ACCOUNT_LOGGED_OUT
);
http_send_redirect_to_auth(r, urlFragment, "Redirect to logout message");
free(urlFragment);
}
free(ip);
}
else {
debug(LOG_DEBUG, "Client for %s is already in the client list", client->ip);
}
s_config *config = config_get_config();
unsigned long long incoming = client->counters.incoming;
unsigned long long outgoing = client->counters.outgoing;
char *ip = safe_strdup(client->ip);
char *urlFragment = NULL;
t_auth_serv *auth_server = get_auth_server();
fw_deny(client->ip, client->mac, client->fw_connection_state);
qos_del_user(client);
client_list_delete(client);
debug(LOG_DEBUG, "Got logout from %s", client->ip);
/* Advertise the logout if we have an auth server */
if (config->auth_servers != NULL) {
UNLOCK_CLIENT_LIST();
auth_server_request(&authresponse, REQUEST_TYPE_LOGOUT, ip, mac, token->value,
incoming, outgoing);
LOCK_CLIENT_LIST();
/* Re-direct them to auth server */
debug(LOG_INFO, "Got manual logout from client ip %s, mac %s, token %s"
"- redirecting them to logout message", client->ip, client->mac, client->token);
safe_asprintf(&urlFragment, "%smessage=%s",
auth_server->authserv_msg_script_path_fragment,
GATEWAY_MESSAGE_ACCOUNT_LOGGED_OUT
);
http_send_redirect_to_auth(r, urlFragment, "Redirect to logout message");
free(urlFragment);
}
free(ip);
}
else {
debug(LOG_DEBUG, "Client for %s is already in the client list", client->ip);
}
UNLOCK_CLIENT_LIST();
/* 不是logout请求,那么不管是不是新的客户端,都需要再次认证一下*/
if (!logout) {
authenticate_client(r);
}
free(mac);
}
} else {
/* They did not supply variable "token" */
send_http_page(r, "WiFiDog error", "Invalid token");
}
authenticate_client(r);
}
free(mac);
}
} else {
/* They did not supply variable "token" */
send_http_page(r, "WiFiDog error", "Invalid token");
}
}
0 0
- 认证流程【4】-http_callback_auth()函数
- 认证流程【1】-main函数
- 认证流程【2】-main_loop函数
- 认证流程【3】-http_callback_404函数
- 认证流程【5】-authenticate_client()函数
- 认证流程
- Oauth2 认证流程
- 苹果MFI认证流程
- OAUTH认证授权流程
- ISO13485认证流程
- ISO14000认证流程
- Oauth认证流程
- OCP认证流程详解
- Kerberos认证流程详解
- cas 认证流程
- wifidog认证流程
- CAS客户端认证流程
- OAuth认证流程
- 第二周项目3—汉诺塔程序
- 认证流程【3】-http_callback_404函数
- NYOJ 1163 cakes(自己想复杂了)
- GIT上优秀的IOS框架
- 设置Activity的显示位置
- 认证流程【4】-http_callback_auth()函数
- 第二周项目2个人感受 别让大学对不起青春
- vm调整相关算法(草稿)
- JavaWeb工程师面试(一)
- 第2周项目3-体验复杂度(2)
- CLRS 10.2链表
- Qt绘图控件QCustomPlot安装
- 第二周项目一
- 认证流程【5】-authenticate_client()函数