static void auth_ok(void *data) { struct dialog *dlg = (struct dialog *)data; struct auth_entry *entry = (struct auth_entry *)dlg->udata2; struct session *ses = (struct session *)dlg->udata; entry->blocked = 0; entry->valid = auth_entry_has_userinfo(entry); #ifdef CONFIG_FORMHIST if (get_opt_bool((const unsigned char *)"document.browse.forms.show_formhist", ses)) { unsigned char *url = get_uri_string(entry->uri, URI_HTTP_AUTH); if (url) { struct form form = {}; form.action = url; INIT_LIST_OF(struct submitted_value, submit); struct submitted_value *user, *password; user = init_submitted_value((unsigned char *)"user", entry->user, FC_TEXT, NULL, 0); if (user) { add_to_list(submit, user); } password = init_submitted_value((unsigned char *)"password", entry->password, FC_PASSWORD, NULL, 0); if (password) { add_to_list(submit, password); } memorize_form(ses, &submit, &form); done_submitted_value_list(&submit); mem_free(url); } } #endif if (entry->valid && have_location(ses)) { struct location *loc = cur_loc(ses); struct uri *uri = loc->vs.uri; /* Make a 'fake' redirect to a URI without user/password so that * the user/password from the URI will not override what the * user just entered in the dialog. */ if ((uri->userlen && strlcmp(entry->user, -1, uri->user, uri->userlen)) || (uri->password && strlcmp(entry->password, -1, uri->password, uri->passwordlen))) { uri = get_composed_uri(uri, URI_HTTP_AUTH | URI_DATA | URI_POST); if (uri) { goto_uri_frame(ses, uri, NULL, CACHE_MODE_INCREMENT); done_uri(uri); return; } } } reload(ses, CACHE_MODE_INCREMENT); }
/* It returns a base 64 encoded user + pass suitable to use in Authorization * header, or NULL on failure. */ struct auth_entry * find_auth(struct uri *uri) { struct auth_entry *entry = NULL; #ifdef DEBUG_HTTP_AUTH DBG("find_auth: newurl=%s uri=%p", newurl, uri); #endif entry = find_auth_entry(uri, NULL); /* Check is user/pass info is in url. */ if (uri->userlen || uri->passwordlen) { /* Add a new entry either to save the user/password info from the URI * so it is available if we later get redirected to a URI with * the user/password stripped. Else if update with entry with * the user/password from the URI. */ if (!entry || (uri->userlen && strlcmp(entry->user, -1, uri->user, uri->userlen)) || (uri->password && strlcmp(entry->password, -1, uri->password, uri->passwordlen))) { entry = add_auth_entry(uri, NULL, NULL, NULL, 0); } } /* No entry found or waiting for user/password in dialog. */ if (!entry || entry->blocked) return NULL; /* Sanity check. */ if (!auth_entry_has_userinfo(entry)) { del_auth_entry(entry); return NULL; } return entry; }