/*
- * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2001-2022 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* https://www.openssl.org/source/license.html
*/
-#include "e_os.h"
+#include "internal/e_os.h"
#include <openssl/e_os2.h>
#include <openssl/err.h>
#include <openssl/ui.h>
# define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
# endif
-# if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
+# if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && ! (defined(OPENSSL_SYS_TANDEM) && defined(_SPT_MODEL_))
# include <sys/ioctl.h>
# endif
/* Internal functions to open, handle and close a channel to the console. */
static int open_console(UI *ui)
{
- CRYPTO_THREAD_write_lock(ui->lock);
+ if (!CRYPTO_THREAD_write_lock(ui->lock))
+ return 0;
is_a_tty = 1;
# if defined(OPENSSL_SYS_VXWORKS)
is_a_tty = 0;
else
# endif
+# ifdef EPERM
+ /*
+ * Linux can return EPERM (Operation not permitted),
+ * e.g. if a daemon executes openssl via fork()+execve()
+ * This should be ok
+ */
+ if (errno == EPERM)
+ 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;
+ 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);
-
+ ERR_raise_data(ERR_LIB_UI, UI_R_UNKNOWN_TTYGET_ERRNO_VALUE,
+ "errno=%d", errno);
return 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);
+ ERR_raise_data(ERR_LIB_UI, UI_R_SYSASSIGN_ERROR,
+ "status=%%X%08X", status);
return 0;
}
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)) {
- char tmp_num[2][12];
-
- BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
- status);
- BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
- iosb.iosb$w_value);
- UIerr(UI_F_NOECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
- ERR_add_error_data(5, "status=", tmp_num[0],
- ",", "iosb.iosb$w_value=", tmp_num[1]);
+ ERR_raise_data(ERR_LIB_UI, UI_R_SYSQIOW_ERROR,
+ "status=%%X%08X, iosb.iosb$w_value=%%X%08X",
+ status, iosb.iosb$w_value);
return 0;
}
}
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)) {
- char tmp_num[2][12];
-
- BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
- status);
- BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
- iosb.iosb$w_value);
- UIerr(UI_F_ECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
- ERR_add_error_data(5, "status=", tmp_num[0],
- ",", "iosb.iosb$w_value=", tmp_num[1]);
+ ERR_raise_data(ERR_LIB_UI, UI_R_SYSQIOW_ERROR,
+ "status=%%X%08X, iosb.iosb$w_value=%%X%08X",
+ status, iosb.iosb$w_value);
return 0;
}
}
static int close_console(UI *ui)
{
+ int ret = 1;
+
if (tty_in != stdin)
fclose(tty_in);
if (tty_out != stderr)
# ifdef OPENSSL_SYS_VMS
status = sys$dassgn(channel);
if (status != SS$_NORMAL) {
- char tmp_num[12];
-
- BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status);
- UIerr(UI_F_CLOSE_CONSOLE, UI_R_SYSDASSGN_ERROR);
- ERR_add_error_data(2, "status=", tmp_num);
- return 0;
+ ERR_raise_data(ERR_LIB_UI, UI_R_SYSDASSGN_ERROR,
+ "status=%%X%08X", status);
+ ret = 0;
}
# endif
CRYPTO_THREAD_unlock(ui->lock);
- return 1;
+ return ret;
}
# if !defined(OPENSSL_SYS_WINCE)