?? bsc_auth.c
字號:
len = strlen(buf);
WS_Write_To_Net(req, buf, len, WS_FILETRNSFR);
return(WPW_BASIC_AUTH_FAILED);
}
BSC_Base64_Decode((UINT8*)total_char, (UINT8*)final_decode);
#ifdef NU_WEBSERV_DEBUG
printf(" final decode = %s \r\n", final_decode);
#endif
while(final_decode[count] != ':')
{
user_id[count] = final_decode[count];
count++;
}
/* Increment the count passed the : marker */
count++;
while(final_decode[count] != NU_NULL)
{
password[index] = final_decode[count];
index++;
count++;
}
#ifdef NU_WEBSERV_DEBUG
printf("user_id = %s password = %s \r\n",user_id, password);
#endif
/* Traverse through Pw list structure to see if user is verified. */
for(bpwlist = BSC_Pw_List_info.wpw_list_head ; bpwlist ; bpwlist = bpwlist->wpw_list_next)
{
if(strcmp((CHAR *)bpwlist->wpw_user, user_id) == 0 )
{
if(strcmp((CHAR *)bpwlist->wpw_password, password)==0)
{
found++;
break;
}
}
}
/* If not found then send Forbidden */
if( !found )
{
/* Store the 403 Header Response */
strcpy(req->ws_response, BSC_Text_H403);
/* Send the Plug-in Proto Header */
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
/* Get the 403 Forbidden Data */
strcpy(buf, BSC_Text_D403);
len = strlen(buf);
/* Write the Plug-in Data */
WS_Write_To_Net(req, buf, len, WS_PLUGIN_DATA);
/* Let the WS_Write_To_Net send the stored data */
WS_Write_To_Net(req, 0, 0, WS_PLUGIN_SEND);
/* Return Basic Auth Failed */
return(WPW_BASIC_AUTH_FAILED);
}
else
{
/* If authenticated continue processing */
return(NU_SUCCESS);
}
}
/************************************************************************
*
* FUNCTION
*
* BSC_Base64_Decode
*
* DESCRIPTION
*
* This function is used to decode a base64 encoded string. It
* returns the decoded string to the calling routine.
*
* INPUTS
*
* *total_char
* *final_decode
*
* OUTPUTS
*
* The decoded string.
*
************************************************************************/
UINT8 *BSC_Base64_Decode(UINT8 *total_char, UINT8 final_decode[])
{
INT16 index = 0;
INT16 len;
INT16 end_text = 0;
INT16 decode_counter;
INT16 count;
INT16 ignore_char = 0;
UINT8 decode_value[76];
UINT8 tempbits;
UINT8 ch;
len = (INT16)strlen((CHAR *)total_char);
while((index < len))
{
ch= total_char[index];
if ((ch >= 'A') && (ch <= 'Z'))
ch= ch- 'A';
else if((ch >='a') && (ch <= 'z'))
ch= ch -'a' +26;
else if ((ch >='0') && (ch <= '9'))
ch = ch - '0' +52;
else if (ch == '+')
ch = 62;
else if (ch == '=')
{
end_text++;
ch='\0';
}
else if (ch == '/')
ch = 63;
else
ignore_char++;
decode_value[index] = ch;
index++;
}
index = index - end_text;
count = 0;
decode_counter = 0;
while(count < index)
{
final_decode[decode_counter] = (UINT8)(decode_value[count] << 2);
tempbits = (UINT8)((decode_value[count + 1] & 0x30) >> 4);
final_decode[decode_counter] = final_decode[decode_counter] | tempbits;
decode_counter++;
final_decode[decode_counter] = (UINT8)((decode_value[count + 1] & 0x0f) << 4);
tempbits = (UINT8)((decode_value[count + 2] & 0x3c) >> 2);
final_decode[decode_counter] = final_decode[decode_counter] | tempbits;
decode_counter++;
final_decode[decode_counter] = (UINT8)((decode_value[count + 2] & 0x03) << 6);
final_decode[decode_counter] = final_decode[decode_counter] | (decode_value[count +3]);
decode_counter++;
count = count + 4;
}
return(final_decode);
}
/************************************************************************
*
* FUNCTION
*
* BSC_Add_Delete_Auth
*
* DESCRIPTION
*
* A plug-in used to add and delete users and passwords to and from
* the Nucleus WebServ's database. This plug-in will redirect the
* URL to user.ssi if it is successful. If the plug-in is
* unsuccessful it will give an error message with a tag to return
* it to the addel.htm web page.
*
* INPUTS
*
* *req
*
* OUTPUTS
*
* WS_REQ_PROCEED
*
************************************************************************/
static INT BSC_Add_Delete_Auth(WS_REQUEST *req)
{
CHAR o[600];
CHAR *user;
CHAR *password;
INT add_func = 0;
INT del_func = 0;
CHAR *pg_string;
UTL_Zero(o,600);
/* Check if arguement name is equal to user_id */
user = HTTP_Token_Value_by_Name("user_id", req);
/* Check if the name is eual to password */
password = HTTP_Token_Value_by_Name("password", req);
/* Verify it is an add or delete function */
pg_string = HTTP_Token_Value_by_Name("AddDel", req);
if(pg_string)
{
/* Check if it is an add */
if(strncmp(pg_string, "Add", 3) == 0)
{
/* Then set the add_func to true */
add_func = 1;
}
/* Check if it is a delete function */
else if(strncmp(pg_string, "Delete", 6) == 0)
{
/* Then set the delete to a true */
del_func = 1;
}
}
if(!user || !password || !pg_string)
return(WS_REQ_ABORTED);
else if(add_func)
{
/* If add function then add the entry */
if(BSC_Auth_Add_Entry(user, password) != NU_SUCCESS)
{
/* If the add entry fails then send a response. */
/* This is setting up a page for the response */
HTTP_Response_Header(req, WS_PROTO_OK);
HTTP_Header_Name_Insert(WS_CONTENT_TYPE, WS_TYPE_TXT_HTML, req->ws_response);
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
strcat(o,"<BR><FONT COLOR=\"#980040\"><FONT SIZE=4>\n");
strcat(o,"User id and password already exists.<BR>");
strcat(o,"<BR></FONT></FONT>");
strcat(o,"<p align=\"left\"><a href=\"addel.htm\"><fontsize=\"3\">Back to Add and Deleting</font></a></p>");
/* Write the Plugin Data */
WS_Write_To_Net(req, o, strlen(o), WS_PLUGIN_DATA);
/* Set the Plug-in to send the data */
WS_Write_To_Net(req, NU_NULL, 0, WS_PLUGIN_SEND);
}
else
{
/* If successful then redirect the URL */
/* Redirect to user.ssi script when completed */
HTTP_Redirect_Client(req,"/user.ssi");
}
}
else if(del_func)
{
/* If the user selected Delete then try add delete the user and the password */
if(BSC_Auth_Delete_Entry(user,password) != NU_SUCCESS)
{
/* An error occured, send a response to the Web Browser */
/* This is settig up a page for the response */
HTTP_Response_Header(req, WS_PROTO_OK);
HTTP_Header_Name_Insert(WS_CONTENT_TYPE, WS_TYPE_TXT_HTML, req->ws_response);
HTTP_Initiate_Response(req, WS_PLUGIN_PROTO);
strcat(o,"<BR><FONT COLOR=\"#980040\"><FONT SIZE=4>\n");
strcat(o,"Unable to find user, password combination.<BR></FONT></FONT>");
strcat(o,"<p align=\"left\"><a href=\"addel.htm\"><fontsize=\"3\">Back to Add and Deleting</font></a></p>");
WS_Write_To_Net(req, o, strlen(o), WS_PLUGIN_DATA);
/* Set the Plug-in to send the data */
WS_Write_To_Net(req, NU_NULL, 0, WS_PLUGIN_SEND);
}
else
{
/* Delete was successful Redirect the user to user id passworfd
* list.
*/
HTTP_Redirect_Client(req,"/user.ssi");
}
}
return(WS_REQ_PROCEED);
}
/************************************************************************
*
* FUNCTION
*
* BSC_Show_Users
*
* DESCRIPTION
*
* This plug-in is a server side include function that shows all the
* user id's and password that are in the Nucleus WebServ's
* database.
*
* INPUTS
*
* *env
* *req
*
* OUTPUTS
*
* WS_REQ_PROCEED
*
************************************************************************/
static INT BSC_Show_Users(WS_REQUEST *req)
{
CHAR ubuf[700];
WPW_INFO_NODE *bpwlist;
CHAR password[32];
INT16 len;
/* Set up table for HTMLMarkup */
strcpy(ubuf,"<div align=\"center\"><center>");
WS_Write_To_Net(req, ubuf, strlen(ubuf), WS_PLUGIN_DATA);
strcpy(ubuf,"<table border=\"4\" cellpadding=\"2\" width=\"40%%\">");
WS_Write_To_Net(req, ubuf, strlen(ubuf), WS_PLUGIN_DATA);
/* Set up the table columns and headers for the SSI User ID/ Password */
strcpy(ubuf,"<tr><td align=\"center\" width=\"20%%\"> \
<FONT COLOR=\"black\"> USER ID </font></td> \
<td align=\"center\" width=\"20%%\">\
<FONT COLOR=\"black\">PASSWORD</font></td></tr>");
WS_Write_To_Net(req, ubuf, strlen(ubuf), WS_PLUGIN_DATA);
/* Traverse through Password/user list structure to see if user is verified. */
for(bpwlist = BSC_Pw_List_info.wpw_list_head ; bpwlist ; bpwlist = bpwlist->wpw_list_next)
{
UTL_Zero(password,32);
len = (INT16)strlen((CHAR *)bpwlist->wpw_password);
memset(password, 0x2a, (size_t)len);
/* Print to ubuf the user id and password name */
strcpy(ubuf,"<tr><td align=\"center\" width=\"20%%\"> \
<FONT COLOR=\"#980040\">");
strcat(ubuf, bpwlist->wpw_user);
strcat(ubuf, "</font> </td> \
<td align=\"center\" width=\"20%%\"> \
<FONT COLOR=\"#980040\">");
strcat(ubuf, password);
strcat(ubuf, "</font></td></tr>");
/* Output the user id and statistics */
WS_Write_To_Net(req, ubuf, strlen(ubuf), WS_PLUGIN_DATA);
}
/* Make end of table HTML and output */
strcpy(ubuf,"</table></center></div>");
WS_Write_To_Net(req, ubuf, strlen(ubuf), WS_PLUGIN_DATA);
/* return to Request Proceed */
return(WS_REQ_PROCEED);
}
#endif /* WS_BASIC_AUTH */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -