main.c (7d82f0f819f2fde1c321b8ac4ff15e494c5eb4b1) | main.c (b1efbcd6740f24e4bce347c64e48d9b74b472c67) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* |
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 26/* 27 * lofiadm - administer lofi(7d). Very simple, add and remove file<->device 28 * associations, and display status. All the ioctls are private between 29 * lofi and lofiadm, and so are very simple - device information is 30 * communicated via a minor number. --- 18 unchanged lines hidden (view full) --- 49#include <ctype.h> 50#include <dlfcn.h> 51#include <limits.h> 52#include <security/cryptoki.h> 53#include <cryptoutil.h> 54#include <sys/crypto/ioctl.h> 55#include <sys/crypto/ioctladmin.h> 56#include "utils.h" | 23 * Use is subject to license terms. 24 */ 25 26/* 27 * lofiadm - administer lofi(7d). Very simple, add and remove file<->device 28 * associations, and display status. All the ioctls are private between 29 * lofi and lofiadm, and so are very simple - device information is 30 * communicated via a minor number. --- 18 unchanged lines hidden (view full) --- 49#include <ctype.h> 50#include <dlfcn.h> 51#include <limits.h> 52#include <security/cryptoki.h> 53#include <cryptoutil.h> 54#include <sys/crypto/ioctl.h> 55#include <sys/crypto/ioctladmin.h> 56#include "utils.h" |
57#include <LzmaEnc.h> |
|
57 58/* Only need the IV len #defines out of these files, nothing else. */ 59#include <aes/aes_impl.h> 60#include <des/des_impl.h> 61#include <blowfish/blowfish_impl.h> 62 63static const char USAGE[] = 64 "Usage: %s -a file [ device ] " 65 " [-c aes-128-cbc|aes-192-cbc|aes-256-cbc|des3-cbc|blowfish-cbc]" 66 " [-e] [-k keyfile] [-T [token]:[manuf]:[serial]:key]\n" 67 " %s -d file | device\n" | 58 59/* Only need the IV len #defines out of these files, nothing else. */ 60#include <aes/aes_impl.h> 61#include <des/des_impl.h> 62#include <blowfish/blowfish_impl.h> 63 64static const char USAGE[] = 65 "Usage: %s -a file [ device ] " 66 " [-c aes-128-cbc|aes-192-cbc|aes-256-cbc|des3-cbc|blowfish-cbc]" 67 " [-e] [-k keyfile] [-T [token]:[manuf]:[serial]:key]\n" 68 " %s -d file | device\n" |
68 " %s -C [algorithm] [-s segment_size] file\n" | 69 " %s -C [gzip|gzip-6|gzip-9|lzma] [-s segment_size] file\n" |
69 " %s -U file\n" 70 " %s [ file | device ]\n"; 71 72typedef struct token_spec { 73 char *name; 74 char *mfr; 75 char *serno; 76 char *key; --- 38 unchanged lines hidden (view full) --- 115#define DEFAULT_CIPHER (&mech_aliases[0]) 116 117#define DEFAULT_CIPHER_NUM 64 /* guess # kernel ciphers available */ 118#define DEFAULT_MECHINFO_NUM 16 /* guess # kernel mechs available */ 119#define MIN_PASSLEN 8 /* min acceptable passphrase size */ 120 121static int gzip_compress(void *src, size_t srclen, void *dst, 122 size_t *destlen, int level); | 70 " %s -U file\n" 71 " %s [ file | device ]\n"; 72 73typedef struct token_spec { 74 char *name; 75 char *mfr; 76 char *serno; 77 char *key; --- 38 unchanged lines hidden (view full) --- 116#define DEFAULT_CIPHER (&mech_aliases[0]) 117 118#define DEFAULT_CIPHER_NUM 64 /* guess # kernel ciphers available */ 119#define DEFAULT_MECHINFO_NUM 16 /* guess # kernel mechs available */ 120#define MIN_PASSLEN 8 /* min acceptable passphrase size */ 121 122static int gzip_compress(void *src, size_t srclen, void *dst, 123 size_t *destlen, int level); |
124static int lzma_compress(void *src, size_t srclen, void *dst, 125 size_t *destlen, int level); |
|
123 124lofi_compress_info_t lofi_compress_table[LOFI_COMPRESS_FUNCTIONS] = { | 126 127lofi_compress_info_t lofi_compress_table[LOFI_COMPRESS_FUNCTIONS] = { |
125 {NULL, gzip_compress, 6, "gzip"}, /* default */ 126 {NULL, gzip_compress, 6, "gzip-6"}, 127 {NULL, gzip_compress, 9, "gzip-9"} | 128 {NULL, gzip_compress, 6, "gzip"}, /* default */ 129 {NULL, gzip_compress, 6, "gzip-6"}, 130 {NULL, gzip_compress, 9, "gzip-9"}, 131 {NULL, lzma_compress, 0, "lzma"} |
128}; 129 130/* For displaying lofi mappings */ 131#define FORMAT "%-20s %-30s %s\n" 132 133#define COMPRESS_ALGORITHM "gzip" 134#define COMPRESS_THRESHOLD 2048 135#define SEGSIZE 131072 136#define BLOCK_SIZE 512 137#define KILOBYTE 1024 138#define MEGABYTE (KILOBYTE * KILOBYTE) 139#define GIGABYTE (KILOBYTE * MEGABYTE) 140#define LIBZ "libz.so" 141 | 132}; 133 134/* For displaying lofi mappings */ 135#define FORMAT "%-20s %-30s %s\n" 136 137#define COMPRESS_ALGORITHM "gzip" 138#define COMPRESS_THRESHOLD 2048 139#define SEGSIZE 131072 140#define BLOCK_SIZE 512 141#define KILOBYTE 1024 142#define MEGABYTE (KILOBYTE * KILOBYTE) 143#define GIGABYTE (KILOBYTE * MEGABYTE) 144#define LIBZ "libz.so" 145 |
142static int (*compress2p)(void *, ulong_t *, void *, size_t, int) = NULL; | 146static void 147usage(const char *pname) 148{ 149 (void) fprintf(stderr, gettext(USAGE), pname, pname, pname, 150 pname, pname); 151 exit(E_USAGE); 152} |
143 | 153 |
144static int gzip_compress(void *src, size_t srclen, void *dst, 145 size_t *dstlen, int level) | 154static int 155gzip_compress(void *src, size_t srclen, void *dst, size_t *dstlen, int level) |
146{ | 156{ |
157 static int (*compress2p)(void *, ulong_t *, void *, size_t, int) = NULL; |
|
147 void *libz_hdl = NULL; 148 149 /* 150 * The first time we are called, attempt to dlopen() 151 * libz.so and get a pointer to the compress2() function 152 */ 153 if (compress2p == NULL) { 154 if ((libz_hdl = openlib(LIBZ)) == NULL) --- 9 unchanged lines hidden (view full) --- 164 } 165 } 166 167 if ((*compress2p)(dst, (ulong_t *)dstlen, src, srclen, level) != 0) 168 return (-1); 169 return (0); 170} 171 | 158 void *libz_hdl = NULL; 159 160 /* 161 * The first time we are called, attempt to dlopen() 162 * libz.so and get a pointer to the compress2() function 163 */ 164 if (compress2p == NULL) { 165 if ((libz_hdl = openlib(LIBZ)) == NULL) --- 9 unchanged lines hidden (view full) --- 175 } 176 } 177 178 if ((*compress2p)(dst, (ulong_t *)dstlen, src, srclen, level) != 0) 179 return (-1); 180 return (0); 181} 182 |
183/*ARGSUSED*/ |
|
172static void | 184static void |
173usage(const char *pname) | 185*SzAlloc(void *p, size_t size) |
174{ | 186{ |
175 (void) fprintf(stderr, gettext(USAGE), pname, pname, pname, 176 pname, pname); 177 exit(E_USAGE); | 187 return (malloc(size)); |
178} 179 | 188} 189 |
190/*ARGSUSED*/ 191static void 192SzFree(void *p, void *address, size_t size) 193{ 194 free(address); 195} 196 197static ISzAlloc g_Alloc = { 198 SzAlloc, 199 SzFree 200}; 201 202#define LZMA_UNCOMPRESSED_SIZE 8 203#define LZMA_HEADER_SIZE (LZMA_PROPS_SIZE + LZMA_UNCOMPRESSED_SIZE) 204 205/*ARGSUSED*/ 206static int 207lzma_compress(void *src, size_t srclen, void *dst, 208 size_t *dstlen, int level) 209{ 210 CLzmaEncProps props; 211 size_t outsize2; 212 size_t outsizeprocessed; 213 size_t outpropssize = LZMA_PROPS_SIZE; 214 uint64_t t = 0; 215 SRes res; 216 Byte *dstp; 217 int i; 218 219 outsize2 = *dstlen; 220 221 LzmaEncProps_Init(&props); 222 223 /* 224 * The LZMA compressed file format is as follows - 225 * 226 * Offset Size(bytes) Description 227 * 0 1 LZMA properties (lc, lp, lp (encoded)) 228 * 1 4 Dictionary size (little endian) 229 * 5 8 Uncompressed size (little endian) 230 * 13 Compressed data 231 */ 232 233 /* set the dictionary size to be 8MB */ 234 props.dictSize = 1 << 23; 235 236 if (*dstlen < LZMA_HEADER_SIZE) 237 return (SZ_ERROR_OUTPUT_EOF); 238 239 dstp = (Byte *)dst; 240 t = srclen; 241 /* 242 * Set the uncompressed size in the LZMA header 243 * The LZMA properties (specified in 'props') 244 * will be set by the call to LzmaEncode() 245 */ 246 for (i = 0; i < LZMA_UNCOMPRESSED_SIZE; i++, t >>= 8) { 247 dstp[LZMA_PROPS_SIZE + i] = (Byte)t; 248 } 249 250 outsizeprocessed = outsize2 - LZMA_HEADER_SIZE; 251 res = LzmaEncode(dstp + LZMA_HEADER_SIZE, &outsizeprocessed, 252 src, srclen, &props, dstp, &outpropssize, 0, NULL, 253 &g_Alloc, &g_Alloc); 254 255 if (res != 0) 256 return (-1); 257 258 *dstlen = outsizeprocessed + LZMA_HEADER_SIZE; 259 return (0); 260} 261 |
|
180/* 181 * Translate a lofi device name to a minor number. We might be asked 182 * to do this when there is no association (such as when the user specifies 183 * a particular device), so we can only look at the string. 184 */ 185static int 186name_to_minor(const char *devicename) 187{ --- 1755 unchanged lines hidden --- | 262/* 263 * Translate a lofi device name to a minor number. We might be asked 264 * to do this when there is no association (such as when the user specifies 265 * a particular device), so we can only look at the string. 266 */ 267static int 268name_to_minor(const char *devicename) 269{ --- 1755 unchanged lines hidden --- |