![]() |
| Home |
|
|
Function http_set_authThis function sets basic authentication information for the Web server.
typedef struct web_auth_entry
{
char * filename; // Web page path/filename or part thereof
char * realm; // Protection partition (see RFC 2068, section 11)
char * user_pwd; // Username and password separated by a colon (e.g. "user:secret")
char * encoded_user_pwd; // Space to encode
int encoded_len; // Length of encoded user_pwd
char * err401_file; // page to display on authentication failure
} web_auth_entry;
int http_set_auth(web_auth_entry * web_auth, int num_entries);
Parametersweb_authPointer to an array of structures containing the authentication information. num_entriesNumber of entries in *web_auth. return valueReturns 0 if successful, otherwise SOCKET_ERROR. If an error occurred, call xn_getlasterror and xn_geterror_string to return the error value. Section Error Codes further describes each error. This function saves a pointer to the basic authentication information, web_auth, in a global variable and encodes the user name and password information to the *encoded_user_pwd members. The *user_pwd members can be deallocated after the call. The *filename member is matched case insensitive against any part of a filename requested by a browser. For example, if file name "secret\\" is protected, then all files below a directory called "secret" will require a password (e.g. "secret\index.html", "..\..\TomsSecret\hidden.jpg", etc.). File "secret.htm" would be served without the need to enter a password. Example:
// set up strings for username "hisname" and password "hispassword"
char usrpwd1[] = "hisname:hispassword";
char encoded_string1[BASE64_MAX_ENCODED_SIZE(sizeof(usrpwd1))];
// set up strings for username "myname" and password "mypassword"
char usrpwd2[] = "myname:mypassword";
char encoded_string2[BASE64_MAX_ENCODED_SIZE(sizeof(usrpwd2))];
struct web_auth_entry auth_info[] =
{
// filename realm user_pwd encoded_user_pwd encoded_len
// --------------- --------- -------- ----------------- -----------
{"survey.html", "group2", usrpwd1, encoded_string1, sizeof(encoded_string1) },
{"index.html", "group1", usrpwd2, encoded_string2, sizeof(encoded_string2) }
};
Result = http_set_auth(auth_info, sizeof(auth_info) / sizeof(auth_info[0]));
|