コード例 #1
0
ファイル: ui_openssl.c プロジェクト: awakecoding/libressl
/* Internal functions to open, handle and close a channel to the console.  */
static int
open_console(UI *ui)
{
	CRYPTO_w_lock(CRYPTO_LOCK_UI);
	is_a_tty = 1;

#define DEV_TTY "/dev/tty"
	if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
		tty_in = stdin;
	if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
		tty_out = stderr;

#if defined(TTY_get)
	if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
		if (errno == ENOTTY)
			is_a_tty = 0;
		else
			/*
			 * Ariel Glenn [email protected] reports that
			 * solaris can return EINVAL instead.  This should be
			 * ok
			 */
			if (errno == EINVAL)
				is_a_tty = 0;
		else
			return 0;
	}
#endif
	return 1;
}
コード例 #2
0
ファイル: ui_openssl.c プロジェクト: NickAger/elm-slider
/* Internal functions to open, handle and close a channel to the console.  */
static int open_console(UI *ui)
{
    CRYPTO_w_lock(CRYPTO_LOCK_UI);
    is_a_tty = 1;

#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS)
    tty_in = stdin;
    tty_out = stderr;
#else
# ifdef OPENSSL_SYS_MSDOS
#  define DEV_TTY "con"
# else
#  define DEV_TTY "/dev/tty"
# endif
    if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
        tty_in = stdin;
    if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
        tty_out = stderr;
#endif

#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
    if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
# ifdef ENOTTY
        if (errno == ENOTTY)
            is_a_tty = 0;
        else
# endif
# ifdef EINVAL
            /*
             * Ariel Glenn [email protected] reports that solaris can return
             * EINVAL instead.  This should be ok
             */
        if (errno == EINVAL)
            is_a_tty = 0;
        else
# endif
            return 0;
    }
#endif
#ifdef OPENSSL_SYS_VMS
    status = sys$assign(&terminal, &channel, 0, 0);
    if (status != SS$_NORMAL)
        return 0;
    status =
        sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12, 0, 0,
                 0, 0);
    if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
        return 0;
#endif
    return 1;
}
コード例 #3
0
ファイル: read_pwd.c プロジェクト: gdzhu/opensgx
/* return 0 if ok, 1 (or -1) otherwise */
int des_read_pw(char *buf, char *buff, int size, const char *prompt,
                int verify)
{
# ifdef OPENSSL_SYS_VMS
    struct IOSB iosb;
    $DESCRIPTOR(terminal, "TT");
    long tty_orig[3], tty_new[3];
    long status;
    unsigned short channel = 0;
# else
#  if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
    TTY_STRUCT tty_orig, tty_new;
#  endif
# endif
    int number;
    int ok;
    /*
     * statics are simply to avoid warnings about longjmp clobbering things
     */
    static int ps;
    int is_a_tty;
    static FILE *tty;
    char *p;

    if (setjmp(save)) {
        ok = 0;
        goto error;
    }

    number = 5;
    ok = 0;
    ps = 0;
    is_a_tty = 1;
    tty = NULL;

# ifdef OPENSSL_SYS_MSDOS
    if ((tty = fopen("con", "r")) == NULL)
        tty = stdin;
# elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VXWORKS)
    tty = stdin;
# else
#  ifndef OPENSSL_SYS_MPE
    if ((tty = fopen("/dev/tty", "r")) == NULL)
#  endif
        tty = stdin;
# endif

# if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
    if (TTY_get(fileno(tty), &tty_orig) == -1) {
#  ifdef ENOTTY
        if (errno == ENOTTY)
            is_a_tty = 0;
        else
#  endif
#  ifdef EINVAL
            /*
             * Ariel Glenn [email protected] reports that solaris can return
             * EINVAL instead.  This should be ok
             */
        if (errno == EINVAL)
            is_a_tty = 0;
        else
#  endif
            return (-1);
    }
    memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
# endif
# ifdef OPENSSL_SYS_VMS
    status = sys$assign(&terminal, &channel, 0, 0);
    if (status != SS$_NORMAL)
        return (-1);
    status =
        sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12, 0, 0,
                 0, 0);
    if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
        return (-1);
# endif

    pushsig();
    ps = 1;

# ifdef TTY_FLAGS
    tty_new.TTY_FLAGS &= ~ECHO;
# endif

# if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
    if (is_a_tty && (TTY_set(fileno(tty), &tty_new) == -1))
#  ifdef OPENSSL_SYS_MPE
        ;                       /* MPE lies -- echo really has been disabled */
#  else
        return (-1);
#  endif
# endif
# ifdef OPENSSL_SYS_VMS
    tty_new[0] = tty_orig[0];
    tty_new[1] = tty_orig[1] | TT$M_NOECHO;
    tty_new[2] = tty_orig[2];
    status =
        sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12, 0, 0, 0,
                 0);
    if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
        return (-1);
# endif
    ps = 2;

    while ((!ok) && (number--)) {
        fputs(prompt, stderr);
        fflush(stderr);

        buf[0] = '\0';
        fgets(buf, size, tty);
        if (feof(tty))
            goto error;
        if (ferror(tty))
            goto error;
        if ((p = (char *)strchr(buf, '\n')) != NULL)
            *p = '\0';
        else
            read_till_nl(tty);
        if (verify) {
            fprintf(stderr, "\nVerifying password - %s", prompt);
            fflush(stderr);
            buff[0] = '\0';
            fgets(buff, size, tty);
            if (feof(tty))
                goto error;
            if ((p = (char *)strchr(buff, '\n')) != NULL)
                *p = '\0';
            else
                read_till_nl(tty);

            if (strcmp(buf, buff) != 0) {
                fprintf(stderr, "\nVerify failure");
                fflush(stderr);
                break;
                /* continue; */
            }
        }
        ok = 1;
    }

 error:
    fprintf(stderr, "\n");
# if 0
    perror("fgets(tty)");
# endif
    /* What can we do if there is an error? */
# if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
    if (ps >= 2)
        TTY_set(fileno(tty), &tty_orig);
# endif
# ifdef OPENSSL_SYS_VMS
    if (ps >= 2)
        status =
            sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_orig, 12, 0, 0,
                     0, 0);
# endif

    if (ps >= 1)
        popsig();
    if (stdin != tty)
        fclose(tty);
# ifdef OPENSSL_SYS_VMS
    status = sys$dassgn(channel);
# endif
    return (!ok);
}
コード例 #4
0
ファイル: ui_openssl.c プロジェクト: AlexanderPankiv/node
/* Internal functions to open, handle and close a channel to the console.  */
static int open_console(UI *ui)
{
    CRYPTO_THREAD_write_lock(ui->lock);
    is_a_tty = 1;

#if defined(OPENSSL_SYS_VXWORKS)
    tty_in = stdin;
    tty_out = stderr;
#elif defined(_WIN32) && !defined(_WIN32_WCE)
    if ((tty_out = fopen("conout$", "w")) == NULL)
        tty_out = stderr;

    if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &tty_orig)) {
        tty_in = stdin;
    } else {
        is_a_tty = 0;
        if ((tty_in = fopen("conin$", "r")) == NULL)
            tty_in = stdin;
    }
#else
# ifdef OPENSSL_SYS_MSDOS
#  define DEV_TTY "con"
# else
#  define DEV_TTY "/dev/tty"
# endif
    if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
        tty_in = stdin;
    if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
        tty_out = stderr;
#endif

#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
    if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
# ifdef ENOTTY
        if (errno == ENOTTY)
            is_a_tty = 0;
        else
# endif
# ifdef EINVAL
            /*
             * Ariel Glenn [email protected] reports that solaris can return
             * EINVAL instead.  This should be ok
             */
        if (errno == EINVAL)
            is_a_tty = 0;
        else
# endif
# ifdef ENODEV
            /*
             * MacOS X returns ENODEV (Operation not supported by device),
             * which seems appropriate.
             */
        if (errno == ENODEV)
            is_a_tty = 0;
        else
# endif
            {
                char tmp_num[10];
                BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%d", errno);
                UIerr(UI_F_OPEN_CONSOLE, UI_R_UNKNOWN_TTYGET_ERRNO_VALUE);
                ERR_add_error_data(2, "errno=", tmp_num);

                return 0;
            }
    }
#endif
#ifdef OPENSSL_SYS_VMS
    status = sys$assign(&terminal, &channel, 0, 0);

    /* if there isn't a TT device, something is very wrong */
    if (status != SS$_NORMAL) {
        char tmp_num[12];

        BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status);
        UIerr(UI_F_OPEN_CONSOLE, UI_R_SYSASSIGN_ERROR);
        ERR_add_error_data(2, "status=", tmp_num);
        return 0;
    }

    status = sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12,
                      0, 0, 0, 0);

    /* If IO$_SENSEMODE doesn't work, this is not a terminal device */
    if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
        is_a_tty = 0;
#endif
    return 1;
}
コード例 #5
0
ファイル: ui_openssl.c プロジェクト: G-P-S/openssl
/* Internal functions to open, handle and close a channel to the console.  */
static int open_console(UI *ui)
{
    CRYPTO_THREAD_write_lock(ui->lock);
    is_a_tty = 1;

#if defined(OPENSSL_SYS_VXWORKS)
    tty_in = stdin;
    tty_out = stderr;
#elif defined(_WIN32) && !defined(_WIN32_WCE)
    if ((tty_out = fopen("conout$", "w")) == NULL)
        tty_out = stderr;

    if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &tty_orig)) {
        tty_in = stdin;
    } else {
        is_a_tty = 0;
        if ((tty_in = fopen("conin$", "r")) == NULL)
            tty_in = stdin;
    }
#else
# ifdef OPENSSL_SYS_MSDOS
#  define DEV_TTY "con"
# else
#  define DEV_TTY "/dev/tty"
# endif
    if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
        tty_in = stdin;
    if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
        tty_out = stderr;
#endif

#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
    if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
# ifdef ENOTTY
        if (errno == ENOTTY)
            is_a_tty = 0;
        else
# endif
# ifdef EINVAL
            /*
             * Ariel Glenn [email protected] reports that solaris can return
             * EINVAL instead.  This should be ok
             */
        if (errno == EINVAL)
            is_a_tty = 0;
        else
# endif
            return 0;
    }
#endif
#ifdef OPENSSL_SYS_VMS
    status = sys$assign(&terminal, &channel, 0, 0);
    if (status != SS$_NORMAL)
        return 0;
    status =
        sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12, 0, 0,
                 0, 0);
    if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
        return 0;
#endif
    return 1;
}