Example #1
0
static int ui_read(UI *ui, UI_STRING *uis)
{
    switch (UI_get_string_type(uis)) {
    case UIT_PROMPT:
        {
            char result[PEM_BUFSIZE];
            const struct pem_password_cb_data *data =
                UI_method_get_ex_data(UI_get_method(ui), ui_method_data_index);
            int maxsize = UI_get_result_maxsize(uis);
            int len = data->cb(result,
                               maxsize > PEM_BUFSIZE ? PEM_BUFSIZE : maxsize,
                               data->rwflag, UI_get0_user_data(ui));

            if (len <= 0)
                return len;
            if (UI_set_result(ui, uis, result) >= 0)
                return 1;
            return 0;
        }
    case UIT_VERIFY:
    case UIT_NONE:
    case UIT_BOOLEAN:
    case UIT_INFO:
    case UIT_ERROR:
        break;
    }
    return 1;
}
Example #2
0
NOEXPORT int pin_cb(UI *ui, UI_STRING *uis) {
    ui_data=UI_get0_user_data(ui); /* was: ui_data=UI_get_app_data(ui); */
    if(!ui_data) {
        s_log(LOG_ERR, "INTERNAL ERROR: user data data pointer");
        return 0;
    }
    if(!DialogBox(ghInst, TEXT("PassBox"), hwnd, (DLGPROC)pass_proc))
        return 0; /* error */
    UI_set_result(ui, uis, ui_data->pass);
    return 1;
}
Example #3
0
static int
read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
{
	static int ps;
	int ok;
	char result[BUFSIZ];
	int maxsize = BUFSIZ - 1;
	char *p;

	intr_signal = 0;
	ok = 0;
	ps = 0;

	pushsig();

	ps = 1;

	if (!echo && !noecho_console(ui))
		goto error;
	ps = 2;

	result[0] = '\0';
	p = fgets(result, maxsize, tty_in);
	if (!p)
		goto error;
	if (feof(tty_in))
		goto error;
	if (ferror(tty_in))
		goto error;
	if ((p = strchr(result, '\n')) != NULL) {
		if (strip_nl)
			*p = '\0';
	} else if (!read_till_nl(tty_in))
		goto error;
	if (UI_set_result(ui, uis, result) >= 0)
		ok = 1;

error:
	if (intr_signal == SIGINT)
		ok = -1;
	if (!echo)
		fprintf(tty_out, "\n");
	if (ps >= 2 && !echo && !echo_console(ui))
		ok = 0;

	if (ps >= 1)
		popsig();

	OPENSSL_cleanse(result, BUFSIZ);
	return ok;
}
Example #4
0
static int ui_flush(UI *ui)
{
	struct ui_data *ui_data = UI_get0_user_data(ui);
	struct openconnect_info *vpninfo = ui_data->vpninfo;
	struct ui_form_opt *opt;
	int ret;

	ret = process_auth_form(vpninfo, &ui_data->form);
	if (ret)
		return 0;

	for (opt = (struct ui_form_opt *)ui_data->form.opts; opt;
	     opt = (struct ui_form_opt *)opt->opt.next) {
		if (opt->opt.value && opt->uis)
			UI_set_result(ui, opt->uis, opt->opt.value);
	}
	return 1;
}
Example #5
0
static int ui_read(UI *ui, UI_STRING *uis)
{
	if (UI_get_input_flags(uis) & UI_INPUT_FLAG_DEFAULT_PWD
		&& UI_get0_user_data(ui))
	{
		switch(UI_get_string_type(uis))
		{
		case UIT_PROMPT:
		case UIT_VERIFY:
			{
				const char *password = (const char*)
					((PW_CB_DATA *)UI_get0_user_data(ui))->password;
				if (password && password[0] != '\0')
				{
					UI_set_result(ui, uis, password);
					return 1;
				}
			}
		default:
			break;
		}
	}
	return UI_method_get_reader(UI_OpenSSL())(ui, uis);
}
Example #6
0
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
	{
	static int ps;
	int ok;
	char result[BUFSIZ];
	int maxsize = BUFSIZ-1;
#if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE)
	char *p;

	intr_signal=0;
	ok=0;
	ps=0;

	pushsig();
	ps=1;

	if (!echo && !noecho_console(ui))
		goto error;
	ps=2;

	result[0]='\0';
#ifdef OPENSSL_SYS_MSDOS
	if (!echo)
		{
		noecho_fgets(result,maxsize,tty_in);
		p=result; /* FIXME: noecho_fgets doesn't return errors */
		}
	else
		p=fgets(result,maxsize,tty_in);
#else
	p=fgets(result,maxsize,tty_in);
#endif
	if(!p)
		goto error;
	if (feof(tty_in)) goto error;
	if (ferror(tty_in)) goto error;
	if ((p=(char *)strchr(result,'\n')) != NULL)
		{
		if (strip_nl)
			*p='\0';
		}
	else
		if (!read_till_nl(tty_in))
			goto error;
	if (UI_set_result(ui, uis, result) >= 0)
		ok=1;

error:
	if (intr_signal == SIGINT)
		ok=-1;
	if (!echo) fprintf(tty_out,"\n");
	if (ps >= 2 && !echo && !echo_console(ui))
		ok=0;

	if (ps >= 1)
		popsig();
#else
	ok=1;
#endif

	OPENSSL_cleanse(result,BUFSIZ);
	return ok;
	}
Example #7
0
static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
{
    static int ps;
    int ok;
    char result[BUFSIZ];
    int maxsize = BUFSIZ - 1;
#if !defined(OPENSSL_SYS_WINCE)
    char *p = NULL;
    int echo_eol = !echo;

    intr_signal = 0;
    ok = 0;
    ps = 0;

    pushsig();
    ps = 1;

    if (!echo && !noecho_console(ui))
        goto error;
    ps = 2;

    result[0] = '\0';
# if defined(_WIN32)
    if (is_a_tty) {
        DWORD numread;
#  if defined(CP_UTF8)
        if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) != 0) {
            WCHAR wresult[BUFSIZ];

            if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE),
                         wresult, maxsize, &numread, NULL)) {
                if (numread >= 2 &&
                    wresult[numread-2] == L'\r' &&
                    wresult[numread-1] == L'\n') {
                    wresult[numread-2] = L'\n';
                    numread--;
                }
                wresult[numread] = '\0';
                if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1,
                                        result, sizeof(result), NULL, 0) > 0)
                    p = result;

                OPENSSL_cleanse(wresult, sizeof(wresult));
            }
        } else
#  endif
        if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE),
                         result, maxsize, &numread, NULL)) {
            if (numread >= 2 &&
                result[numread-2] == '\r' && result[numread-1] == '\n') {
                result[numread-2] = '\n';
                numread--;
            }
            result[numread] = '\0';
            p = result;
        }
    } else
# elif defined(OPENSSL_SYS_MSDOS)
    if (!echo) {
        noecho_fgets(result, maxsize, tty_in);
        p = result;             /* FIXME: noecho_fgets doesn't return errors */
    } else
# endif
    p = fgets(result, maxsize, tty_in);
    if (p == NULL)
        goto error;
    if (feof(tty_in))
        goto error;
    if (ferror(tty_in))
        goto error;
    if ((p = (char *)strchr(result, '\n')) != NULL) {
        if (strip_nl)
            *p = '\0';
    } else if (!read_till_nl(tty_in))
        goto error;
    if (UI_set_result(ui, uis, result) >= 0)
        ok = 1;

 error:
    if (intr_signal == SIGINT)
        ok = -1;
    if (echo_eol)
        fprintf(tty_out, "\n");
    if (ps >= 2 && !echo && !echo_console(ui))
        ok = 0;

    if (ps >= 1)
        popsig();
#else
    ok = 1;
#endif

    OPENSSL_cleanse(result, BUFSIZ);
    return ok;
}
static int ui_android_read(UI *ui, UI_STRING *uis)
{
    int ok = 0;
    int num = 0;
    const char *str;
    char **args;

    switch (UI_get_string_type(uis)) {
	case UIT_BOOLEAN:
	    android_log(PRG_DEBUG, "called ui_android_read() output boolean %s",
	                UI_get0_output_string(uis));
	    android_log(PRG_DEBUG, "called ui_android_read() action boolean %s",
	                UI_get0_action_string(uis));
	    //			UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO
	case UIT_PROMPT:
        str = UI_get0_output_string(uis);
	    android_log(PRG_DEBUG, "called ui_android_read() output prompt %s",
                    str);
	    break;
	case UIT_VERIFY:
        str = UI_get0_output_string(uis);
	    android_log(PRG_DEBUG, "called ui_android_read() verify output %s",
                    str);
	    break;
	default:
        return 1;
	    break;
    }

    strlcat(ui_buf, "=X=", sizeof(ui_buf));
    strlcat(ui_buf, str, sizeof(ui_buf));

process:
    if (send_req(ui_buf) < 0) {
        android_log(PRG_ERR, "send_req() failed");
        goto out;
    }

    if (recv_cmd(&num, &args) < 0) {
        android_log(PRG_ERR, "recv_cmd() failed");
        goto out;
    }
    if (num != 1) {
        android_log(PRG_ERR, "parameter number mismatch");
        goto out;
    }

    android_log(PRG_DEBUG, "ui_android_read() cmd: %s %d", args[0], num);

    send_ack(num);

    UI_set_result(ui, uis, args[0]);

    ok = 1;

out:
    if (num)
        free_cmd(num, args);
    ui_buf[0] = '\0';
    return ok;
}