Print this page
4178 lofiadm usage message for the -a option is bogus
Reviewed by: Garrett D'Amore <garrett@damore.org>


  49 #include <unistd.h>
  50 #include <stropts.h>
  51 #include <libdevinfo.h>
  52 #include <libgen.h>
  53 #include <ctype.h>
  54 #include <dlfcn.h>
  55 #include <limits.h>
  56 #include <security/cryptoki.h>
  57 #include <cryptoutil.h>
  58 #include <sys/crypto/ioctl.h>
  59 #include <sys/crypto/ioctladmin.h>
  60 #include "utils.h"
  61 #include <LzmaEnc.h>
  62 
  63 /* Only need the IV len #defines out of these files, nothing else. */
  64 #include <aes/aes_impl.h>
  65 #include <des/des_impl.h>
  66 #include <blowfish/blowfish_impl.h>
  67 
  68 static const char USAGE[] =
  69         "Usage: %s [-r] -a file [ device ] "
  70         " [-c aes-128-cbc|aes-192-cbc|aes-256-cbc|des3-cbc|blowfish-cbc]"
  71         " [-e] [-k keyfile] [-T [token]:[manuf]:[serial]:key]\n"





  72         "       %s -d file | device\n"
  73         "       %s -C [gzip|gzip-6|gzip-9|lzma] [-s segment_size] file\n"
  74         "       %s -U file\n"
  75         "       %s [ file | device ]\n";
  76 
  77 typedef struct token_spec {
  78         char    *name;
  79         char    *mfr;
  80         char    *serno;
  81         char    *key;
  82 } token_spec_t;
  83 
  84 typedef struct mech_alias {
  85         char    *alias;
  86         CK_MECHANISM_TYPE type;
  87         char    *name;          /* for ioctl */
  88         char    *iv_name;       /* for ioctl */
  89         size_t  iv_len;         /* for ioctl */
  90         iv_method_t iv_type;    /* for ioctl */
  91         size_t  min_keysize;    /* in bytes */


 134         {NULL,                  gzip_compress,  9,      "gzip-9"},
 135         {NULL,                  lzma_compress,  0,      "lzma"}
 136 };
 137 
 138 /* For displaying lofi mappings */
 139 #define FORMAT                  "%-20s     %-30s        %s\n"
 140 
 141 #define COMPRESS_ALGORITHM      "gzip"
 142 #define COMPRESS_THRESHOLD      2048
 143 #define SEGSIZE                 131072
 144 #define BLOCK_SIZE              512
 145 #define KILOBYTE                1024
 146 #define MEGABYTE                (KILOBYTE * KILOBYTE)
 147 #define GIGABYTE                (KILOBYTE * MEGABYTE)
 148 #define LIBZ                    "libz.so"
 149 
 150 static void
 151 usage(const char *pname)
 152 {
 153         (void) fprintf(stderr, gettext(USAGE), pname, pname, pname,
 154             pname, pname);
 155         exit(E_USAGE);
 156 }
 157 
 158 static int
 159 gzip_compress(void *src, size_t srclen, void *dst, size_t *dstlen, int level)
 160 {
 161         static int (*compress2p)(void *, ulong_t *, void *, size_t, int) = NULL;
 162         void *libz_hdl = NULL;
 163 
 164         /*
 165          * The first time we are called, attempt to dlopen()
 166          * libz.so and get a pointer to the compress2() function
 167          */
 168         if (compress2p == NULL) {
 169                 if ((libz_hdl = openlib(LIBZ)) == NULL)
 170                         die(gettext("could not find %s. "
 171                             "gzip compression unavailable\n"), LIBZ);
 172 
 173                 if ((compress2p =
 174                     (int (*)(void *, ulong_t *, void *, size_t, int))




  49 #include <unistd.h>
  50 #include <stropts.h>
  51 #include <libdevinfo.h>
  52 #include <libgen.h>
  53 #include <ctype.h>
  54 #include <dlfcn.h>
  55 #include <limits.h>
  56 #include <security/cryptoki.h>
  57 #include <cryptoutil.h>
  58 #include <sys/crypto/ioctl.h>
  59 #include <sys/crypto/ioctladmin.h>
  60 #include "utils.h"
  61 #include <LzmaEnc.h>
  62 
  63 /* Only need the IV len #defines out of these files, nothing else. */
  64 #include <aes/aes_impl.h>
  65 #include <des/des_impl.h>
  66 #include <blowfish/blowfish_impl.h>
  67 
  68 static const char USAGE[] =
  69         "Usage: %s [-r] -a file [ device ]\n"
  70         "       %s [-r] -c crypto_algorithm -a file [device]\n"
  71         "       %s [-r] -c crypto_algorithm -k raw_key_file -a file [device]\n"
  72         "       %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key "
  73         "-a file [device]\n"
  74         "       %s [-r] -c crypto_algorithm -T [token]:[manuf]:[serial]:key "
  75         "-k wrapped_key_file -a file [device]\n"
  76         "       %s [-r] -c crypto_algorithm -e -a file [device]\n"
  77         "       %s -d file | device\n"
  78         "       %s -C [gzip|gzip-6|gzip-9|lzma] [-s segment_size] file\n"
  79         "       %s -U file\n"
  80         "       %s [ file | device ]\n";
  81 
  82 typedef struct token_spec {
  83         char    *name;
  84         char    *mfr;
  85         char    *serno;
  86         char    *key;
  87 } token_spec_t;
  88 
  89 typedef struct mech_alias {
  90         char    *alias;
  91         CK_MECHANISM_TYPE type;
  92         char    *name;          /* for ioctl */
  93         char    *iv_name;       /* for ioctl */
  94         size_t  iv_len;         /* for ioctl */
  95         iv_method_t iv_type;    /* for ioctl */
  96         size_t  min_keysize;    /* in bytes */


 139         {NULL,                  gzip_compress,  9,      "gzip-9"},
 140         {NULL,                  lzma_compress,  0,      "lzma"}
 141 };
 142 
 143 /* For displaying lofi mappings */
 144 #define FORMAT                  "%-20s     %-30s        %s\n"
 145 
 146 #define COMPRESS_ALGORITHM      "gzip"
 147 #define COMPRESS_THRESHOLD      2048
 148 #define SEGSIZE                 131072
 149 #define BLOCK_SIZE              512
 150 #define KILOBYTE                1024
 151 #define MEGABYTE                (KILOBYTE * KILOBYTE)
 152 #define GIGABYTE                (KILOBYTE * MEGABYTE)
 153 #define LIBZ                    "libz.so"
 154 
 155 static void
 156 usage(const char *pname)
 157 {
 158         (void) fprintf(stderr, gettext(USAGE), pname, pname, pname,
 159             pname, pname, pname, pname, pname, pname, pname);
 160         exit(E_USAGE);
 161 }
 162 
 163 static int
 164 gzip_compress(void *src, size_t srclen, void *dst, size_t *dstlen, int level)
 165 {
 166         static int (*compress2p)(void *, ulong_t *, void *, size_t, int) = NULL;
 167         void *libz_hdl = NULL;
 168 
 169         /*
 170          * The first time we are called, attempt to dlopen()
 171          * libz.so and get a pointer to the compress2() function
 172          */
 173         if (compress2p == NULL) {
 174                 if ((libz_hdl = openlib(LIBZ)) == NULL)
 175                         die(gettext("could not find %s. "
 176                             "gzip compression unavailable\n"), LIBZ);
 177 
 178                 if ((compress2p =
 179                     (int (*)(void *, ulong_t *, void *, size_t, int))