Remove device renaming and select default device (#48)

This commit is contained in:
James Wilson
2022-05-08 15:52:07 -07:00
committed by GitHub
parent 8078a346d1
commit fbba173a1f
2 changed files with 10 additions and 33 deletions

View File

@@ -88,26 +88,9 @@ AC_ARG_WITH([static-libgcc],
],
[AC_MSG_RESULT(no)])
AC_MSG_CHECKING(whether to convert rewinding device names to non-rewinding device names)
AC_ARG_ENABLE([device-name-conversion],
[AS_HELP_STRING([--enable-device-name-conversion],[converts /dev/st* to /dev/st*.1 and /dev/rmt* to /dev/rmt*.1 to prevent rewinds. Enabled by default.])],
[enable_dnc=$enableval],
[enable_dnc="yes"]
)
if test "$enable_dnc" = "yes"; then
AC_MSG_RESULT(yes)
else
AC_DEFINE(DISABLE_DEVICE_NAME_CONVERSION,1,"")
AC_MSG_RESULT(no)
fi
AC_CHECK_PROG(PANDOC, [pandoc], [yes])
AM_CONDITIONAL([FOUND_PANDOC], [test "x$PANDOC" = xyes])
AM_COND_IF([FOUND_PANDOC],,[AC_MSG_ERROR([required program 'pandoc' not found.])])
AC_CONFIG_FILES([Makefile src/Makefile man/Makefile tests/Makefile])
AC_OUTPUT

View File

@@ -28,6 +28,7 @@ GNU General Public License for more details.
#include <stdint.h>
#include <sstream>
#include <string>
#include <sys/mtio.h>
#include <sys/stat.h>
#include <termios.h>
#include <time.h>
@@ -132,7 +133,7 @@ int main(int argc, char **argv) {
break;
}
std::string tapeDrive = "";
std::string tapeDrive;
int action = 0; // 0 = status, 1 =setting param, 2 = generating key
std::string keyFile, keyDesc;
int keyLength = 0;
@@ -248,9 +249,14 @@ int main(int argc, char **argv) {
std::cout << "Permissions of keyfile set to 600\n";
exit(EXIT_SUCCESS);
}
// validate the tape device
if (tapeDrive == "") {
errorOut("Tape drive device must be specified with the -f option");
// select device from env variable or system default if not given with -f
if (tapeDrive.empty()) {
const char *env_tape = getenv("TAPE");
if (env_tape != nullptr) {
tapeDrive = env_tape;
} else {
tapeDrive = DEFTAPE;
}
}
if (drvOptions.cryptMode == CRYPTMODE_RAWREAD &&
drvOptions.rdmc == RDMC_PROTECT) {
@@ -258,18 +264,6 @@ int main(int argc, char **argv) {
"'--protect' is not valid when setting encryption mode to 'rawread'");
}
#ifndef DISABLE_DEVICE_NAME_CONVERSION
if (tapeDrive.find(".") == std::string::npos) {
if (tapeDrive.substr(0, 7) == "/dev/st") {
tapeDrive = "/dev/nst" + tapeDrive.substr(7, tapeDrive.size() - 6);
}
if (tapeDrive.substr(0, 8) == "/dev/rmt" &&
tapeDrive.substr(tapeDrive.size() - 2, 2) != ".1") {
tapeDrive = "/dev/rmt" + tapeDrive.substr(8, tapeDrive.size() - 7) + ".1";
}
}
#endif
if (getuid() != 0) {
errorOut("You must be root to read or set encryption options on a drive!");
}