📄 http_psr.c
字号:
return(FAILURE);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Authenticated_Check
*
* DESCRIPTION
*
* This function checks to see if this connection is authenticated.
*
* INPUTS
*
* *req Pointer to Request structure that
* holds all information pertaining
* to the HTTP request.
*
* OUTPUTS
*
* SUCCESS Server already authenticated
* FAILURE Unable to authenticate server
*
*************************************************************************/
static INT HTTP_Authenticated_Check(WS_REQUEST *req)
{
WS_AUTH * a;
/* is authentication enabled ? */
if(((req->ws_server->ws_master.ws_flags & WS_AUTH_ENABLED) == 0))
{
#ifdef WS_AUTH_PLUGIN
/* Setup login pages to be only access during login */
if(req->ws_server->ws_master.ws_auth_state == 1)
{
if((strcmp(req->ws_fname,"/Login.htm") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/Login.class") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/ErrorDialog.class") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/StreamListener.class") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/COM/widget/des/cipher_ctx.class") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/COM/widget/des/cipher.class") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/COM/widget/util/Hex.class") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/ps_rand") == 0))
return(SUCCESS);
if ((strcmp(req->ws_fname,"/ps_sendurl") == 0))
return(SUCCESS);
return(FAILURE);
}
#endif
return SUCCESS;
};
if((a = HTTP_Check_Auth_IP(req->ws_server,(CHAR *)req->ws_ip)) == FAILURE)
return FAILURE;
if(a->ws_state & WS_AUTH_GIVEN )
{
a->ws_countdown = req->ws_server->ws_master.ws_timeoutval;
return SUCCESS;
}
return SUCCESS;
}
/***********************************************************************
*
* FUNCTION
*
* HTTP_Check_Auth_IP
*
* DESCRIPTION
*
* Function to check and see if the ip address is an already
* authenticated address.
*
* INPUTS
*
* *server Pointer to WS_SERVER structure
* that contains all local server
* information.
* *ip The ip address to compare with.
*
* OUTPUTS
*
* a If the ip address was found in the
* authentication table
* FAILURE The ip address was not found
*
*************************************************************************/
static WS_AUTH *HTTP_Check_Auth_IP(WS_SERVER *server , CHAR *ip )
{
WS_AUTH * a;
/* look for the ip address in the table */
a =server->ws_master.ws_user_auth;
while( a )
{
if( HTTP_IP_Match((UINT8 *)ip,a->ws_ip) )
{
return(a);
}
a = a->ws_next;
}
return(FAILURE);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Free_Auth
*
* DESCRIPTION
*
* Function to free the authorization for a particular ip
* address.
*
* INPUTS
*
* *a Pointer to authentication
* structure.
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID HTTP_Free_Auth(WS_AUTH *a)
{
a->ws_ip[0] = 0;
a->ws_state = WS_AUTH_FREE;
a->ws_countdown = 0;
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Add_Authenticated
*
* DESCRIPTION
*
* Function to add a client ip address once the user has been
* found to be authenticated.
*
* INPUTS
*
* *server Pointer to server structure that
* contains list of authenticated
* clients.
* *ipaddr Clients ip address that wishes to
* be authenticated.
*
* OUTPUTS
*
* SUCCESS Added the ip address
* FAILURE Unable to add the ip address
*
*************************************************************************/
static INT HTTP_Add_Authenticated(WS_SERVER *server, CHAR *ipaddr)
{
WS_AUTH *a;
INT i;
if( (server->ws_master.ws_flags & WS_AUTH_ENABLED) == 0 ) return(FAILURE);
if( ( a = HTTP_Check_Auth_IP(server, ipaddr) ) == FAILURE)
{
a = server->ws_master.ws_user_auth;
while( a )
{ /* find a free auth structure */
if( a->ws_state & WS_AUTH_FREE)
break;
a = a->ws_next;
}
if( a )
{
for(i = 0; i < WS_IP_SIZE; i++)
a->ws_ip[i] = ipaddr[i];
a->ws_state = WS_AUTH_GIVEN;
a->ws_countdown = server->ws_master.ws_timeoutval;
}
else
return(FAILURE);
}
else
{
a->ws_state = WS_AUTH_GIVEN;
a->ws_countdown = server->ws_master.ws_timeoutval;
}
return(SUCCESS);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Global_Access
*
* DESCRIPTION
*
* Function to find out if the requested path is in the global
* unauthenticated space. The / means that everything is
* unauthentciated.
*
* INPUTS
*
* *req Pointer to Request structure that
* holds all information pertaining
* to the HTTP request.
*
* OUTPUTS
*
* SUCCESS The user has authority to access
* the page
* FAILURE The client wants a restricted page
*
*************************************************************************/
static INT HTTP_Global_Access(WS_REQUEST *req)
{
CHAR * g;
g = req->ws_server->ws_master.ws_auth_public;
if( (*g == '/') && (*(g+1) == 0) ) /* if "/" is the global dir everthing is global */
return(SUCCESS);
if( (strncmp(g, req->ws_fname, strlen(g))) == 0 )
return(SUCCESS);
else
return(FAILURE);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_IP_Match
*
* DESCRIPTION
*
* Function to compare IP addresses to verify a match.
*
* INPUTS
*
* *a Argument 1 ip address.
* *b Argument 2 ip address.
*
* OUTPUTS
*
* r = Success if the ip address was
* found.
* = Failure if the ip address was
* not found.
*
*************************************************************************/
static INT HTTP_IP_Match(UINT8 *a, UINT8 *b )
{
register i, r;
r = SUCCESS;
for(i = 0; i < WS_IP_SIZE; i++)
if( (a[i]&0xff) != (b[i]&0xff) )
r = FAILURE;
return(r);
}
/************************************************************************
*
* FUNCTION
*
* HTTP_Header_Num_Insert
*
* DESCRIPTION
*
* Function place a numeric number into the value of slot of the
* output header.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -