Print this page
*** NO COMMENTS ***

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/lofiadm/main.c
          +++ new/usr/src/cmd/lofiadm/main.c
↓ open down ↓ 56 lines elided ↑ open up ↑
  57   57  #include <sys/crypto/ioctladmin.h>
  58   58  #include "utils.h"
  59   59  #include <LzmaEnc.h>
  60   60  
  61   61  /* Only need the IV len #defines out of these files, nothing else. */
  62   62  #include <aes/aes_impl.h>
  63   63  #include <des/des_impl.h>
  64   64  #include <blowfish/blowfish_impl.h>
  65   65  
  66   66  static const char USAGE[] =
  67      -        "Usage: %s -a file [ device ] "
       67 +        "Usage: %s [-r] -a file [ device ] "
  68   68          " [-c aes-128-cbc|aes-192-cbc|aes-256-cbc|des3-cbc|blowfish-cbc]"
  69   69          " [-e] [-k keyfile] [-T [token]:[manuf]:[serial]:key]\n"
  70   70          "       %s -d file | device\n"
  71   71          "       %s -C [gzip|gzip-6|gzip-9|lzma] [-s segment_size] file\n"
  72   72          "       %s -U file\n"
  73   73          "       %s [ file | device ]\n";
  74   74  
  75   75  typedef struct token_spec {
  76   76          char    *name;
  77   77          char    *mfr;
↓ open down ↓ 279 lines elided ↑ open up ↑
 357  357          wait_until_dev_complete(minor);
 358  358          return (minor);
 359  359  }
 360  360  
 361  361  /*
 362  362   * Add a device association. If devicename is NULL, let the driver
 363  363   * pick a device.
 364  364   */
 365  365  static void
 366  366  add_mapping(int lfd, const char *devicename, const char *filename,
 367      -    mech_alias_t *cipher, const char *rkey, size_t rksz)
      367 +    mech_alias_t *cipher, const char *rkey, size_t rksz, boolean_t rdonly)
 368  368  {
 369  369          struct lofi_ioctl li;
 370  370  
      371 +        li.li_readonly = rdonly;
      372 +
 371  373          li.li_crypto_enabled = B_FALSE;
 372  374          if (cipher != NULL) {
 373  375                  /* set up encryption for mapped file */
 374  376                  li.li_crypto_enabled = B_TRUE;
 375  377                  (void) strlcpy(li.li_cipher, cipher->name,
 376  378                      sizeof (li.li_cipher));
 377  379                  if (rksz > sizeof (li.li_key)) {
 378  380                          die(gettext("key too large"));
 379  381                  }
 380  382                  bcopy(rkey, li.li_key, rksz);
↓ open down ↓ 109 lines elided ↑ open up ↑
 490  492  /*
 491  493   * Print the list of all the mappings, including a header.
 492  494   */
 493  495  static void
 494  496  print_mappings(int fd)
 495  497  {
 496  498          struct lofi_ioctl li;
 497  499          int     minor;
 498  500          int     maxminor;
 499  501          char    path[MAXPATHLEN];
 500      -        char    options[MAXPATHLEN];
      502 +        char    options[MAXPATHLEN] = { 0 };
 501  503  
 502  504          li.li_minor = 0;
 503  505          if (ioctl(fd, LOFI_GET_MAXMINOR, &li) == -1) {
 504  506                  die("ioctl");
 505  507          }
 506  508          maxminor = li.li_minor;
 507  509  
 508  510          (void) printf(FORMAT, gettext("Block Device"), gettext("File"),
 509  511              gettext("Options"));
 510  512          for (minor = 1; minor <= maxminor; minor++) {
 511  513                  li.li_minor = minor;
 512  514                  if (ioctl(fd, LOFI_GET_FILENAME, &li) == -1) {
 513  515                          if (errno == ENXIO)
 514  516                                  continue;
 515  517                          warn("ioctl");
 516  518                          break;
 517  519                  }
 518  520                  (void) snprintf(path, sizeof (path), "/dev/%s/%d",
 519  521                      LOFI_BLOCK_NAME, minor);
      522 +
      523 +                options[0] = '\0';
      524 +
 520  525                  /*
 521  526                   * Encrypted lofi and compressed lofi are mutually exclusive.
 522  527                   */
 523  528                  if (li.li_crypto_enabled)
 524  529                          (void) snprintf(options, sizeof (options),
 525  530                              gettext("Encrypted"));
 526  531                  else if (li.li_algorithm[0] != '\0')
 527  532                          (void) snprintf(options, sizeof (options),
 528  533                              gettext("Compressed(%s)"), li.li_algorithm);
 529      -                else
      534 +                if (li.li_readonly) {
      535 +                        if (strlen(options) != 0) {
      536 +                                (void) strlcat(options, ",", sizeof (options));
      537 +                                (void) strlcat(options, "Readonly",
      538 +                                    sizeof (options));
      539 +                        } else {
      540 +                                (void) snprintf(options, sizeof (options),
      541 +                                    gettext("Readonly"));
      542 +                        }
      543 +                }
      544 +                if (strlen(options) == 0)
 530  545                          (void) snprintf(options, sizeof (options), "-");
 531  546  
 532  547                  (void) printf(FORMAT, path, li.li_filename, options);
 533  548          }
 534  549  }
 535  550  
 536  551  /*
 537  552   * Verify the cipher selected by user.
 538  553   */
 539  554  static mech_alias_t *
↓ open down ↓ 1242 lines elided ↑ open up ↑
1782 1797          const char *algname = COMPRESS_ALGORITHM;
1783 1798          int     openflag;
1784 1799          int     minor;
1785 1800          int     compress_index;
1786 1801          uint32_t segsize = SEGSIZE;
1787 1802          static char *lofictl = "/dev/" LOFI_CTL_NAME;
1788 1803          boolean_t force = B_FALSE;
1789 1804          const char *pname;
1790 1805          boolean_t errflag = B_FALSE;
1791 1806          boolean_t addflag = B_FALSE;
     1807 +        boolean_t rdflag = B_FALSE;
1792 1808          boolean_t deleteflag = B_FALSE;
1793 1809          boolean_t ephflag = B_FALSE;
1794 1810          boolean_t compressflag = B_FALSE;
1795 1811          boolean_t uncompressflag = B_FALSE;
1796 1812          /* the next two work together for -c, -k, -T, -e options only */
1797 1813          boolean_t need_crypto = B_FALSE;        /* if any -c, -k, -T, -e */
1798 1814          boolean_t cipher_only = B_TRUE;         /* if -c only */
1799 1815          const char *keyfile = NULL;
1800 1816          mech_alias_t *cipher = NULL;
1801 1817          token_spec_t *token = NULL;
1802 1818          char    *rkey = NULL;
1803 1819          size_t  rksz = 0;
1804 1820          char realfilename[MAXPATHLEN];
1805 1821  
1806 1822          pname = getpname(argv[0]);
1807 1823  
1808 1824          (void) setlocale(LC_ALL, "");
1809 1825          (void) textdomain(TEXT_DOMAIN);
1810 1826  
1811      -        while ((c = getopt(argc, argv, "a:c:Cd:efk:o:s:T:U")) != EOF) {
     1827 +        while ((c = getopt(argc, argv, "a:c:Cd:efk:o:rs:T:U")) != EOF) {
1812 1828                  switch (c) {
1813 1829                  case 'a':
1814 1830                          addflag = B_TRUE;
1815 1831                          if ((filename = realpath(optarg, realfilename)) == NULL)
1816 1832                                  die("%s", optarg);
1817 1833                          if (((argc - optind) > 0) && (*argv[optind] != '-')) {
1818 1834                                  /* optional device */
1819 1835                                  devicename = argv[optind];
1820 1836                                  optind++;
1821 1837                          }
↓ open down ↓ 34 lines elided ↑ open up ↑
1856 1872                          cipher_only = B_FALSE;  /* need to unset cipher_only */
1857 1873                          break;
1858 1874                  case 'f':
1859 1875                          force = B_TRUE;
1860 1876                          break;
1861 1877                  case 'k':
1862 1878                          keyfile = optarg;
1863 1879                          need_crypto = B_TRUE;
1864 1880                          cipher_only = B_FALSE;  /* need to unset cipher_only */
1865 1881                          break;
     1882 +                case 'r':
     1883 +                        rdflag = B_TRUE;
     1884 +                        break;
1866 1885                  case 's':
1867 1886                          segsize = convert_to_num(optarg);
1868 1887                          if (segsize < DEV_BSIZE || !ISP2(segsize))
1869 1888                                  die(gettext("segment size %s is invalid "
1870 1889                                      "or not a multiple of minimum block "
1871 1890                                      "size %ld\n"), optarg, DEV_BSIZE);
1872 1891                          break;
1873 1892                  case 'T':
1874 1893                          if ((token = parsetoken(optarg)) == NULL) {
1875 1894                                  errflag = B_TRUE;
↓ open down ↓ 10 lines elided ↑ open up ↑
1886 1905                  case '?':
1887 1906                  default:
1888 1907                          errflag = B_TRUE;
1889 1908                          break;
1890 1909                  }
1891 1910          }
1892 1911  
1893 1912          /* Check for mutually exclusive combinations of options */
1894 1913          if (errflag ||
1895 1914              (addflag && deleteflag) ||
     1915 +            (rdflag && !addflag) ||
1896 1916              (!addflag && need_crypto) ||
1897 1917              ((compressflag || uncompressflag) && (addflag || deleteflag)))
1898 1918                  usage(pname);
1899 1919  
1900 1920          /* ephemeral key, and key from either file or token are incompatible */
1901 1921          if (ephflag && (keyfile != NULL || token != NULL)) {
1902 1922                  die(gettext("ephemeral key cannot be used with keyfile"
1903 1923                      " or token key\n"));
1904 1924          }
1905 1925  
↓ open down ↓ 96 lines elided ↑ open up ↑
2002 2022                          getkeyfromfile(keyfile, cipher, &rkey, &rksz);
2003 2023                  }
2004 2024  
2005 2025                  end_crypto(sess);
2006 2026          }
2007 2027  
2008 2028          /*
2009 2029           * Now to the real work.
2010 2030           */
2011 2031          if (addflag)
2012      -                add_mapping(lfd, devicename, filename, cipher, rkey, rksz);
     2032 +                add_mapping(lfd, devicename, filename, cipher, rkey, rksz,
     2033 +                    rdflag);
2013 2034          else if (compressflag)
2014 2035                  lofi_compress(&lfd, filename, compress_index, segsize);
2015 2036          else if (uncompressflag)
2016 2037                  lofi_uncompress(lfd, filename);
2017 2038          else if (deleteflag)
2018 2039                  delete_mapping(lfd, devicename, filename, force);
2019 2040          else if (filename || devicename)
2020 2041                  print_one_mapping(lfd, devicename, filename);
2021 2042          else
2022 2043                  print_mappings(lfd);
2023 2044  
2024 2045          if (lfd != -1)
2025 2046                  (void) close(lfd);
2026 2047          closelib();
2027 2048          return (E_SUCCESS);
2028 2049  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX