Enable ASLR feature
[platform/upstream/cryptsetup.git] / src / utils_tools.c
index 86836ca..23e4acb 100644 (file)
@@ -1,13 +1,15 @@
 /*
  * cryptsetup - setup cryptographic volumes for dm-crypt
  *
- * Copyright (C) 2004, Christophe Saout <christophe@saout.de>
+ * Copyright (C) 2004, Jana Saout <jana@saout.de>
  * Copyright (C) 2004-2007, Clemens Fruhwirth <clemens@endorphin.org>
  * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2009-2014, Milan Broz
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -35,6 +37,11 @@ static void int_handler(int sig __attribute__((__unused__)))
        quit++;
 }
 
+int tools_signals_blocked(void)
+{
+       return signals_blocked;
+}
+
 void set_int_block(int block)
 {
        sigset_t signals_open;
@@ -67,28 +74,6 @@ void check_signal(int *r)
                *r = -EINTR;
 }
 
-/* crypt_get_key() with signal handler */
-int tools_get_key(const char *prompt,
-                 char **key, size_t *key_size,
-                 size_t keyfile_offset, size_t keyfile_size_max,
-                 const char *key_file,
-                 int timeout, int verify,
-                 struct crypt_device *cd)
-{
-       int r, block;
-
-       block = signals_blocked;
-       if (block)
-               set_int_block(0);
-
-       r = crypt_get_key(prompt, key, key_size, keyfile_offset,
-                         keyfile_size_max, key_file, timeout, verify, cd);
-       if (block && !quit)
-               set_int_block(1);
-
-       return r;
-}
-
 __attribute__((format(printf, 5, 6)))
 void clogger(struct crypt_device *cd, int level, const char *file, int line,
             const char *format, ...)
@@ -151,13 +136,14 @@ int yesDialog(const char *msg, void *usrptr __attribute__((unused)))
        size_t size = 0;
        int r = 1, block;
 
-       block = signals_blocked;
+       block = tools_signals_blocked();
        if (block)
                set_int_block(0);
 
        if(isatty(STDIN_FILENO) && !opt_batch_mode) {
                log_std("\nWARNING!\n========\n");
                log_std("%s\n\nAre you sure? (Type uppercase yes): ", msg);
+               fflush(stdout);
                if(getline(&answer, &size, stdin) == -1) {
                        r = 0;
                        /* Aborted by signal */
@@ -178,7 +164,7 @@ int yesDialog(const char *msg, void *usrptr __attribute__((unused)))
 
 void show_status(int errcode)
 {
-       char error[256], *error_;
+       char error[256];
 
        if(!opt_verbose)
                return;
@@ -190,12 +176,16 @@ void show_status(int errcode)
 
        crypt_get_error(error, sizeof(error));
 
-       if (!error[0]) {
-               error_ = strerror_r(-errcode, error, sizeof(error));
-               if (error_ != error) {
+       if (*error) {
+#ifdef STRERROR_R_CHAR_P /* GNU-specific strerror_r */
+               char *error_ = strerror_r(-errcode, error, sizeof(error));
+               if (error_ != error)
                        strncpy(error, error_, sizeof(error));
-                       error[sizeof(error) - 1] = '\0';
-               }
+#else /* POSIX strerror_r variant */
+               if (strerror_r(-errcode, error, sizeof(error)))
+                       *error = '\0';
+#endif
+               error[sizeof(error) - 1] = '\0';
        }
 
        log_err(_("Command failed with code %i"), -errcode);