static void build_edit_dialog(struct terminal *term, struct cookie *cookie) { #define EDIT_WIDGETS_COUNT 8 /* [gettext_accelerator_context(.build_edit_dialog)] */ struct dialog *dlg; unsigned char *name, *value, *domain, *expires, *secure; unsigned char *dlg_server; int length = 0; dlg = calloc_dialog(EDIT_WIDGETS_COUNT, MAX_STR_LEN * 5); if (!dlg) return; dlg->title = _("Edit", term); dlg->layouter = generic_dialog_layouter; dlg->udata = cookie; dlg->udata2 = NULL; name = get_dialog_offset(dlg, EDIT_WIDGETS_COUNT); value = name + MAX_STR_LEN; domain = value + MAX_STR_LEN; expires = domain + MAX_STR_LEN; secure = expires + MAX_STR_LEN; safe_strncpy(name, cookie->name, MAX_STR_LEN); safe_strncpy(value, cookie->value, MAX_STR_LEN); safe_strncpy(domain, cookie->domain, MAX_STR_LEN); /* Bug 923: Assumes time_t values fit in unsigned long. */ ulongcat(expires, &length, cookie->expires, MAX_STR_LEN, 0); length = 0; ulongcat(secure, &length, cookie->secure, MAX_STR_LEN, 0); dlg_server = cookie->server->host; dlg_server = straconcat(_("Server", term), ": ", dlg_server, "\n", (unsigned char *) NULL); if (!dlg_server) { mem_free(dlg); return; } add_dlg_text(dlg, dlg_server, ALIGN_LEFT, 0); add_dlg_field_float(dlg, _("Name", term), 0, 0, set_cookie_name, MAX_STR_LEN, name, NULL); add_dlg_field_float(dlg, _("Value", term), 0, 0, set_cookie_value, MAX_STR_LEN, value, NULL); add_dlg_field_float(dlg, _("Domain", term), 0, 0, set_cookie_domain, MAX_STR_LEN, domain, NULL); add_dlg_field_float(dlg, _("Expires", term), 0, 0, set_cookie_expires, MAX_STR_LEN, expires, NULL); add_dlg_field_float(dlg, _("Secure", term), 0, 0, set_cookie_secure, MAX_STR_LEN, secure, NULL); add_dlg_button(dlg, _("~OK", term), B_ENTER, ok_dialog, NULL); add_dlg_button(dlg, _("~Cancel", term), B_ESC, cancel_dialog, NULL); add_dlg_end(dlg, EDIT_WIDGETS_COUNT); do_dialog(term, dlg, getml(dlg, (void *) dlg_server, (void *) NULL)); #undef EDIT_WIDGETS_COUNT }
void do_auth_dialog( struct session *ses, void *data ) { int edx; struct dialog *dlg; struct dialog_data *dlg_data; struct terminal *term = ses->tab->term; struct auth_entry *a; unsigned char sticker[1024], *text; int sticker_len; if ( get_invalid_auth_entry( ) && !( ( *(char*)(get_invalid_auth_entry( ) + 112) & 1 ) & 255 ) && get_uri_string( &a->uri->user[0], URI_HTTP_AUTH ) ) { dlg = &a->realm[0]; if ( 0 != 65 ) { if ( term[0] && current_charset != get_terminal_codepage( &term[0] ) ) { bind_textdomain_codeset( "elinks", get_cp_mime_name( get_terminal_codepage( &term[0] ) ) ); *ebp_1076 = text[0]; current_charset = get_terminal_codepage( &term[0] ); } gettext( "Authentication required for %s at %s" ); text[0] = text[0]; } sticker_len = __snprintf_chk( sticker, 1024, 1, 1024, (char*)gettext( "Authentication required for %s at %s" ), dlg, text[0] ); mem_free( &text[0] ); if ( sticker_len <= 1024 ) { dlg = (struct dialog*)mem_calloc( 1, sticker_len + 277 ); if ( dlg ) { a->bits_at_112/*.1_1of4*/ |= 1; dlg->layouter = &generic_dialog_layouter; dlg[0].title = _( "Authentication required", &term[0] ); text[0] = dlg[3].abort; memcpy( dlg[3].abort, sticker, sticker_len ); dlg->udata = (void*)ses[0].next; dlg->udata2 = (void*)a[0].next; add_dlg_text( dlg, (unsigned char*)dlg[3].abort, ALIGN_LEFT, 0 ); add_dlg_field_do( dlg, WIDGET_FIELD, _( "Login", &term[0] ), 0, 0, 0, 40, &a->user[0], 0, INPFIELD_FLOAT ); add_dlg_field_do( dlg, WIDGET_FIELD_PASS, _( "Password", &term[0] ), 0, 0, 0, 40, &a->password[0], 0, INPFIELD_FLOAT ); add_dlg_button_do( dlg, _( "~OK", &term[0] ), 1, &ok_dialog, 0, &auth_ok, (void*)dlg ); add_dlg_button_do( dlg, _( "~Cancel", &term[0] ), 2, &ok_dialog, 0, &auth_cancel, (void*)a[0].next ); if ( assert_failed == 0 ) { assert_failed = dlg->number_of_widgets != 5; if ( dlg->number_of_widgets != 5 ) { errfile = "/home/naftali/source/elinks-0.12~pre5/src/protocol/auth/dialogs.c"; errline = 118; elinks_internal( "assertion 5 == (dlg)->number_of_widgets failed!" ); } } if ( dlg_data[0] && a->user[0] && a->password[0] == 0 ) select_widget_by_id( &dlg_data[0], 1 ); } } } if ( 0 ^ 0 ) { __stack_chk_fail( ); } return; }
/* TODO: Take auth_entry from data. --jonas */ void do_auth_dialog(struct session *ses, void *data) { /* [gettext_accelerator_context(do_auth_dialog)] */ struct dialog *dlg; struct dialog_data *dlg_data; struct terminal *term = ses->tab->term; struct auth_entry *a = get_invalid_auth_entry(); unsigned char sticker[MAX_STR_LEN], *text; int sticker_len; if (!a || a->blocked) return; text = get_uri_string(a->uri, URI_HTTP_AUTH); if (!text) return; #ifdef CONFIG_FORMHIST { unsigned char *user = get_form_history_value(text, (unsigned char *)"user"); unsigned char *password = get_form_history_value(text, (unsigned char *)"password"); if (user) { strncpy((char *)a->user, (const char *)user, AUTH_USER_MAXLEN - 1); } if (password) { strncpy((char *)a->password, (const char *)password, AUTH_PASSWORD_MAXLEN - 1); } } #endif sticker_len = snprintf((char *)sticker, sizeof(sticker), (const char *)_("Authentication required for %s at %s", term), a->realm, text); mem_free(text); if (sticker_len < 0 || sticker_len > MAX_STR_LEN) return; #define AUTH_WIDGETS_COUNT 5 /* + 1 to leave room for the '\0'. */ dlg = calloc_dialog(AUTH_WIDGETS_COUNT, sticker_len + 1); if (!dlg) return; a->blocked = 1; /* This function is used for at least HTTP and FTP, so don't * name the protocol here. Consider also what an FTP server * behind an HTTP proxy should be called. */ dlg->title = _("Authentication required", term); dlg->layouter = generic_dialog_layouter; text = get_dialog_offset(dlg, AUTH_WIDGETS_COUNT); memcpy(text, sticker, sticker_len); /* calloc_dialog has stored '\0' */ dlg->udata = (void *) ses; dlg->udata2 = a; add_dlg_text(dlg, text, ALIGN_LEFT, 0); add_dlg_field_float(dlg, _("Login", term), 0, 0, NULL, AUTH_USER_MAXLEN, a->user, NULL); add_dlg_field_float_pass(dlg, _("Password", term), 0, 0, NULL, AUTH_PASSWORD_MAXLEN, a->password); add_dlg_ok_button(dlg, _("~OK", term), B_ENTER, auth_ok, dlg); add_dlg_ok_button(dlg, _("~Cancel", term), B_ESC, auth_cancel, a); add_dlg_end(dlg, AUTH_WIDGETS_COUNT); dlg_data = do_dialog(term, dlg, getml(dlg, (void *) NULL)); /* When there's some username, but no password, automagically jump to * the password. */ if (dlg_data && a->user[0] && !a->password[0]) select_widget_by_id(dlg_data, 1); }