]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/losetup.c
mount: losetup: remove obsolete encryption support
[thirdparty/util-linux.git] / sys-utils / losetup.c
index 24d3d3cf1093b42483931171aebc7444c1aa6b0f..38ccc7d08459e4ea3636537cd4093988cfe90911 100644 (file)
 #include "nls.h"
 #include "strutils.h"
 #include "loopdev.h"
-#include "xgetpass.h"
 #include "closestream.h"
 #include "optutils.h"
 
-#define EXCL_ERROR "--{all,associated,set-capacity,detach,detach-all,find}"
-
 enum {
        A_CREATE = 1,           /* setup a new device */
        A_DELETE,               /* delete given device(s) */
@@ -168,10 +165,8 @@ static void usage(FILE *out)
                " -j, --associated <file>       list all devices associated with <file>\n"), out);
        fputs(USAGE_SEPARATOR, out);
 
-       fputs(_(" -e, --encryption <type>       enable encryption with specified <name/num>\n"
-               " -o, --offset <num>            start at offset <num> into file\n"
+       fputs(_(" -o, --offset <num>            start at offset <num> into file\n"
                "     --sizelimit <num>         device limited to <num> bytes of the file\n"
-               " -p, --pass-fd <num>           read passphrase from file descriptor <num>\n"
                " -P, --partscan                create partitioned loop device\n"
                " -r, --read-only               setup read-only loop device\n"
                "     --show                    print device name after setup (with -f)\n"
@@ -209,22 +204,11 @@ static void warn_size(const char *filename, uint64_t size)
 int main(int argc, char **argv)
 {
        struct loopdev_cxt lc;
-       int act = 0, flags = 0, passfd = -1, c;
-       char *file = NULL, *encryption = NULL;
+       int act = 0, flags = 0, c;
+       char *file = NULL;
        uint64_t offset = 0, sizelimit = 0;
        int res = 0, showdev = 0, lo_flags = 0;
 
-       enum {
-               EXCL_NONE,
-               EXCL_ALL,
-               EXCL_ASSOCIATED,
-               EXCL_SET_CAPACITY,
-               EXCL_DETACH,
-               EXCL_DETACH_ALL,
-               EXCL_FIND
-       };
-       int excl_any = EXCL_NONE;
-
        enum {
                OPT_SIZELIMIT = CHAR_MAX + 1,
                OPT_SHOW
@@ -249,6 +233,12 @@ int main(int argc, char **argv)
                { NULL, 0, 0, 0 }
        };
 
+       static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
+               { 'D','a','c','d','f','j' },
+               { 0 }
+       };
+       int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
@@ -261,13 +251,14 @@ int main(int argc, char **argv)
 
        while ((c = getopt_long(argc, argv, "ac:d:De:E:fhj:o:p:PrvV",
                                longopts, NULL)) != -1) {
+
+               err_exclusive_options(c, longopts, excl, excl_st);
+
                switch (c) {
                case 'a':
-                       exclusive_option(&excl_any, EXCL_ALL, EXCL_ERROR);
                        act = A_SHOW;
                        break;
                case 'c':
-                       exclusive_option(&excl_any, EXCL_SET_CAPACITY, EXCL_ERROR);
                        act = A_SET_CAPACITY;
                        if (loopcxt_set_device(&lc, optarg))
                                err(EXIT_FAILURE, _("%s: failed to use device"),
@@ -277,29 +268,25 @@ int main(int argc, char **argv)
                        lo_flags |= LO_FLAGS_READ_ONLY;
                        break;
                case 'd':
-                       exclusive_option(&excl_any, EXCL_DETACH, EXCL_ERROR);
                        act = A_DELETE;
                        if (loopcxt_set_device(&lc, optarg))
                                err(EXIT_FAILURE, _("%s: failed to use device"),
                                                optarg);
                        break;
                case 'D':
-                       exclusive_option(&excl_any, EXCL_DETACH_ALL, EXCL_ERROR);
                        act = A_DELETE_ALL;
                        break;
                case 'E':
                case 'e':
-                       encryption = optarg;
+                       errx(EXIT_FAILURE, _("encryption not supported, use cryptsetup(8) instead"));
                        break;
                case 'f':
-                       exclusive_option(&excl_any, EXCL_FIND, EXCL_ERROR);
                        act = A_FIND_FREE;
                        break;
                case 'h':
                        usage(stdout);
                        break;
                case 'j':
-                       exclusive_option(&excl_any, EXCL_ASSOCIATED, EXCL_ERROR);
                        act = A_SHOW;
                        file = optarg;
                        break;
@@ -308,8 +295,7 @@ int main(int argc, char **argv)
                        flags |= LOOPDEV_FL_OFFSET;
                        break;
                case 'p':
-                       passfd = strtou32_or_err(optarg,
-                                       _("invalid passphrase file descriptor"));
+                        warn(_("--pass-fd is no longer supported"));
                        break;
                case 'P':
                        lo_flags |= LO_FLAGS_PARTSCAN;
@@ -361,7 +347,7 @@ int main(int argc, char **argv)
                if (optind >= argc)
                        errx(EXIT_FAILURE, _("no loop device specified"));
                if (loopcxt_set_device(&lc, argv[optind]))
-                       err(EXIT_FAILURE, _("%s failed to use device"),
+                       err(EXIT_FAILURE, _("%s: failed to use device"),
                                        argv[optind]);
                optind++;
 
@@ -371,10 +357,10 @@ int main(int argc, char **argv)
        }
 
        if (act != A_CREATE &&
-           (encryption || sizelimit || passfd != -1 || lo_flags || showdev))
+           (sizelimit || lo_flags || showdev))
                errx(EXIT_FAILURE,
                        _("the options %s are allowed to loop device setup only"),
-                       "--{encryption,sizelimit,pass-fd,read-only,show}");
+                       "--{sizelimit,read-only,show}");
 
        if ((flags & LOOPDEV_FL_OFFSET) &&
            act != A_CREATE && (act != A_SHOW || !file))
@@ -383,16 +369,8 @@ int main(int argc, char **argv)
        switch (act) {
        case A_CREATE:
        {
-               char *pass = NULL;
                int hasdev = loopcxt_has_device(&lc);
 
-               if (encryption) {
-#ifdef MCL_FUTURE
-                       if(mlockall(MCL_CURRENT | MCL_FUTURE))
-                               err(EXIT_FAILURE, _("couldn't lock into memory"));
-#endif
-                       pass = xgetpass(passfd, _("Password: "));
-               }
                do {
                        /* Note that loopcxt_{find_unused,set_device}() resets
                         * loopcxt struct.
@@ -401,8 +379,6 @@ int main(int argc, char **argv)
                                warnx(_("not found unused device"));
                                break;
                        }
-                       if (encryption && pass)
-                               loopcxt_set_encryption(&lc, encryption, pass);
                        if (flags & LOOPDEV_FL_OFFSET)
                                loopcxt_set_offset(&lc, offset);
                        if (flags & LOOPDEV_FL_SIZELIMIT)
@@ -425,8 +401,6 @@ int main(int argc, char **argv)
                        }
                } while (hasdev == 0);
 
-               free(pass);
-
                if (res == 0) {
                        if (showdev)
                                printf("%s\n", loopcxt_get_device(&lc));