Skip to content
Browse files

first step to porting to linux; can be broken :)

  • Loading branch information...
1 parent 12b9b59 commit 34165edf232a62703f44df7e2a42a7cf422be0a0 @bwalex committed Jul 20, 2011
Showing with 463 additions and 28 deletions.
  1. +6 −1 Makefile
  2. +2 −0 README
  3. +1 −0 crc32.c
  4. +1 −1 crc32.h
  5. +325 −0 crypto-gcrypt.c
  6. +12 −0 hdr.c
  7. +42 −0 io.c
  8. +11 −3 main.c
  9. +6 −0 safe_mem.c
  10. +49 −23 tcplay.c
  11. +8 −0 tcplay.h
View
7 Makefile
@@ -4,8 +4,13 @@ WARNFLAGS= -Wsystem-headers -Werror -Wall -W -Wno-unused-parameter \
-Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts \
-Winline -Wnested-externs -Wredundant-decls
+# for linux...
+WARNFLAGS= -Wall
+
+linux:
+ gcc -O0 $(WARNFLAGS) -g main.c tcplay.c crc32.c safe_mem.c io.c crypto-gcrypt.c hdr.c humanize.c -o tc-play -lcrypto -ldevmapper -luuid
all:
- gcc -O0 $(WARNFLAGS) -g main.c tcplay.c crc32.c safe_mem.c io.c crypto-dev.c hdr.c -o tc-play -lcrypto -ldevmapper -lprop -lutil
+ gcc -O0 $(WARNFLAGS) -g main.c tcplay.c crc32.c safe_mem.c io.c crypto-dev.c hdr.c humanize.c -o tc-play -lcrypto -ldevmapper -lprop -lutil
lib:
gcc $(WARNFLAGS) -c -fPIC -O0 -Wall -g tcplay_api.c tcplay.c crc32.c safe_mem.c io.c crypto-dev.c hdr.c
gcc -shared -Wl,-version-script=tcplay.map -o libtcplay.so tcplay_api.o tcplay.o crc32.o safe_mem.o io.o crypto-dev.o hdr.o
View
2 README
@@ -1,3 +1,5 @@
+A Linux port is underway.
+
*NOTE* tcplay has now been integrated into DragonFly BSD, it's actual home. I'll
try to keep the version up here up to date, but I can't make any promises. For
the newest version, check out DragonFly BSD and look into sbin/tcplay and
View
1 crc32.c
@@ -38,6 +38,7 @@
*/
#include <stdlib.h>
+#include <stdint.h>
#include "crc32.h"
uint32_t crc32_tab[] = {
View
2 crc32.h
@@ -1,2 +1,2 @@
uint32_t crc32(const void *buf, size_t size);
-uint32_t crc32_intermediate(uint32_t crc, uint8_t d);
+uint32_t crc32_intermediate(uint32_t crc, uint8_t d);
View
325 crypto-gcrypt.c
@@ -0,0 +1,325 @@
+/*
+ * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#define __USE_GNU
+#endif
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/sysctl.h>
+
+#include <fcntl.h>
+//#include <unistd.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <string.h>
+#include <openssl/evp.h>
+
+#include "crc32.h"
+#include "tcplay.h"
+
+
+static
+int
+get_cryptodev_cipher_id(struct tc_crypto_algo *cipher)
+{
+#if 0
+ if (strcmp(cipher->name, "AES-128-XTS") == 0)
+ return CRYPTO_AES_XTS;
+ else if (strcmp(cipher->name, "AES-256-XTS") == 0)
+ return CRYPTO_AES_XTS;
+ else if (strcmp(cipher->name, "TWOFISH-128-XTS") == 0)
+ return CRYPTO_TWOFISH_XTS;
+ else if (strcmp(cipher->name, "TWOFISH-256-XTS") == 0)
+ return CRYPTO_TWOFISH_XTS;
+ else if (strcmp(cipher->name, "SERPENT-128-XTS") == 0)
+ return CRYPTO_SERPENT_XTS;
+ else if (strcmp(cipher->name, "SERPENT-256-XTS") == 0)
+ return CRYPTO_SERPENT_XTS;
+ else
+#endif
+ return -1;
+}
+
+int
+tc_crypto_init(void)
+{
+ OpenSSL_add_all_algorithms();
+
+ return 0;
+}
+
+int
+tc_cipher_chain_populate_keys(struct tc_cipher_chain *cipher_chain,
+ unsigned char *key)
+{
+ int total_key_bytes, used_key_bytes;
+ struct tc_cipher_chain *dummy_chain;
+
+ /*
+ * We need to determine the total key bytes as the key locations
+ * depend on it.
+ */
+ total_key_bytes = 0;
+ for (dummy_chain = cipher_chain;
+ dummy_chain != NULL;
+ dummy_chain = dummy_chain->next) {
+ total_key_bytes += dummy_chain->cipher->klen;
+ }
+
+ /*
+ * Now we need to get prepare the keys, as the keys are in
+ * forward order with respect to the cipher cascade, but
+ * the actual decryption is in reverse cipher cascade order.
+ */
+ used_key_bytes = 0;
+ for (dummy_chain = cipher_chain;
+ dummy_chain != NULL;
+ dummy_chain = dummy_chain->next) {
+ dummy_chain->key = alloc_safe_mem(dummy_chain->cipher->klen);
+ if (dummy_chain->key == NULL) {
+ tc_log(1, "tc_decrypt: Could not allocate key "
+ "memory\n");
+ return ENOMEM;
+ }
+
+ /* XXX: here we assume XTS operation! */
+ memcpy(dummy_chain->key,
+ key + used_key_bytes/2,
+ dummy_chain->cipher->klen/2);
+ memcpy(dummy_chain->key + dummy_chain->cipher->klen/2,
+ key + (total_key_bytes/2) + used_key_bytes/2,
+ dummy_chain->cipher->klen/2);
+
+ /* Remember how many key bytes we've seen */
+ used_key_bytes += dummy_chain->cipher->klen;
+ }
+
+ return 0;
+}
+
+int
+tc_encrypt(struct tc_cipher_chain *cipher_chain, unsigned char *key,
+ unsigned char *iv,
+ unsigned char *in, int in_len, unsigned char *out)
+{
+ int cipher_id;
+ int err;
+
+ if ((err = tc_cipher_chain_populate_keys(cipher_chain, key)))
+ return err;
+
+#ifdef DEBUG
+ printf("tc_encrypt: starting chain\n");
+#endif
+
+ /*
+ * Now process the actual decryption, in forward cascade order.
+ */
+ for (;
+ cipher_chain != NULL;
+ cipher_chain = cipher_chain->next) {
+ cipher_id = get_cryptodev_cipher_id(cipher_chain->cipher);
+ if (cipher_id < 0) {
+ tc_log(1, "Cipher %s not found\n",
+ cipher_chain->cipher->name);
+ return ENOENT;
+ }
+
+#ifdef DEBUG
+ printf("tc_encrypt: Currently using cipher %s\n",
+ cipher_chain->cipher->name);
+#endif
+
+#if 0
+ err = syscrypt(cipher_id, cipher_chain->key,
+ cipher_chain->cipher->klen, iv, in, out, in_len, 1);
+#endif
+
+ /* Deallocate this key, since we won't need it anymore */
+ free_safe_mem(cipher_chain->key);
+
+ if (err != 0)
+ return err;
+
+ /* Set next input buffer as current output buffer */
+ in = out;
+ }
+
+ return 0;
+}
+
+int
+tc_decrypt(struct tc_cipher_chain *cipher_chain, unsigned char *key,
+ unsigned char *iv,
+ unsigned char *in, int in_len, unsigned char *out)
+{
+ int cipher_id;
+ int err;
+
+ if ((err = tc_cipher_chain_populate_keys(cipher_chain, key)))
+ return err;
+
+#ifdef DEBUG
+ printf("tc_decrypt: starting chain!\n");
+#endif
+
+ /*
+ * Now process the actual decryption, in reverse cascade order; so
+ * first find the last element in the chain.
+ */
+ for (; cipher_chain->next != NULL; cipher_chain = cipher_chain->next)
+ ;
+ for (;
+ cipher_chain != NULL;
+ cipher_chain = cipher_chain->prev) {
+ cipher_id = get_cryptodev_cipher_id(cipher_chain->cipher);
+ if (cipher_id < 0) {
+ tc_log(1, "Cipher %s not found\n",
+ cipher_chain->cipher->name);
+ return ENOENT;
+ }
+
+#ifdef DEBUG
+ printf("tc_decrypt: Currently using cipher %s\n",
+ cipher_chain->cipher->name);
+#endif
+
+#if 0
+ err = syscrypt(cipher_id, cipher_chain->key,
+ cipher_chain->cipher->klen, iv, in, out, in_len, 0);
+#endif
+
+ /* Deallocate this key, since we won't need it anymore */
+ free_safe_mem(cipher_chain->key);
+
+ if (err != 0)
+ return err;
+
+ /* Set next input buffer as current output buffer */
+ in = out;
+ }
+
+ return 0;
+}
+
+int
+pbkdf2(const char *pass, int passlen, const unsigned char *salt, int saltlen,
+ int iter, const char *hash_name, int keylen, unsigned char *out)
+{
+ const EVP_MD *md;
+ int r;
+
+ md = EVP_get_digestbyname(hash_name);
+ if (md == NULL) {
+ printf("Hash %s not found\n", hash_name);
+ return ENOENT;
+ }
+ r = PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, md,
+ keylen, out);
+
+ if (r == 0) {
+ printf("Error in PBKDF2\n");
+ return EINVAL;
+ }
+
+ return 0;
+}
+
+int
+apply_keyfiles(unsigned char *pass, size_t pass_memsz, const char *keyfiles[],
+ int nkeyfiles)
+{
+ int pl, k;
+ unsigned char *kpool;
+ unsigned char *kdata;
+ int kpool_idx;
+ size_t i, kdata_sz;
+ uint32_t crc;
+
+ if (pass_memsz < MAX_PASSSZ) {
+ tc_log(1, "Not enough memory for password manipluation\n");
+ return ENOMEM;
+ }
+
+ pl = strlen(pass);
+ memset(pass+pl, 0, MAX_PASSSZ-pl);
+
+ if ((kpool = alloc_safe_mem(KPOOL_SZ)) == NULL) {
+ tc_log(1, "Error allocating memory for keyfile pool\n");
+ return ENOMEM;
+ }
+
+ memset(kpool, 0, KPOOL_SZ);
+
+ for (k = 0; k < nkeyfiles; k++) {
+#ifdef DEBUG
+ printf("Loading keyfile %s into kpool\n", keyfiles[k]);
+#endif
+ kpool_idx = 0;
+ crc = ~0U;
+ kdata_sz = MAX_KFILE_SZ;
+
+ if ((kdata = read_to_safe_mem(keyfiles[k], 0, &kdata_sz)) == NULL) {
+ tc_log(1, "Error reading keyfile %s content\n",
+ keyfiles[k]);
+ free_safe_mem(kpool);
+ return EIO;
+ }
+
+ for (i = 0; i < kdata_sz; i++) {
+ crc = crc32_intermediate(crc, kdata[i]);
+
+ kpool[kpool_idx++] += (unsigned char)(crc >> 24);
+ kpool[kpool_idx++] += (unsigned char)(crc >> 16);
+ kpool[kpool_idx++] += (unsigned char)(crc >> 8);
+ kpool[kpool_idx++] += (unsigned char)(crc);
+
+ /* Wrap around */
+ if (kpool_idx == KPOOL_SZ)
+ kpool_idx = 0;
+ }
+
+ free_safe_mem(kdata);
+ }
+
+#ifdef DEBUG
+ printf("Applying kpool to passphrase\n");
+#endif
+ /* Apply keyfile pool to passphrase */
+ for (i = 0; i < KPOOL_SZ; i++)
+ pass[i] += kpool[i];
+
+ free_safe_mem(kpool);
+
+ return 0;
+}
View
12 hdr.c
@@ -26,11 +26,23 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#define __USE_GNU
+#endif
+
#include <sys/types.h>
+
+#if defined(__DragonFly__)
#include <sys/endian.h>
+#elif defined(__linux__)
+#include <endian.h>
+#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <string.h>
#include "crc32.h"
View
42 io.c
@@ -26,8 +26,19 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#define __USE_GNU
+#endif
+
#include <sys/types.h>
+#if defined(__DragonFly__)
#include <sys/diskslice.h>
+#elif defined(__linux__)
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#endif
#include <sys/uio.h>
#include <sys/select.h>
#include <errno.h>
@@ -186,6 +197,7 @@ secure_erase(const char *dev, size_t bytes, size_t blksz)
return 0;
}
+#if defined(__DragonFly__)
int
get_disk_info(const char *dev, size_t *blocks, size_t *bsize)
{
@@ -210,6 +222,36 @@ get_disk_info(const char *dev, size_t *blocks, size_t *bsize)
close(fd);
return 0;
}
+#elif defined(__linux__)
+int
+get_disk_info(const char *dev, size_t *blocks, size_t *bsize)
+{
+ uint64_t nbytes;
+ int blocksz;
+ int fd;
+
+ if ((fd = open(dev, O_RDONLY)) < 0) {
+ tc_log(1, "Error opening %s\n", dev);
+ return -1;
+ }
+
+ if ((ioctl(fd, BLKSSZGET, &blocksz)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ if ((ioctl(fd, BLKGETSIZE64, &nbytes)) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ *blocks = (size_t)(nbytes / blocksz);
+ *bsize = (size_t)(blocksz);
+
+ close(fd);
+ return 0;
+}
+#endif
int
write_mem(const char *dev, off_t offset, size_t blksz __unused, void *mem,
View
14 main.c
@@ -26,20 +26,28 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#define __USE_GNU
+#endif
+
#include <sys/types.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
+#include <inttypes.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
-#include <err.h>
#include <time.h>
-#include <libutil.h>
#include "tcplay.h"
+#ifndef SIGINFO
+#define SIGINFO SIGUSR1
+#endif
+
static
void
sig_handler(int sig)
View
6 safe_mem.c
@@ -26,6 +26,12 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#define __USE_GNU
+#endif
+
#include <sys/types.h>
#include <sys/mman.h>
#include <stdlib.h>
View
72 tcplay.c
@@ -27,18 +27,30 @@
* SUCH DAMAGE.
*/
#include <sys/types.h>
+
+#if defined(__linux__)
+#define _GNU_SOURCE
+#define __USE_GNU
+#endif
+
#include <stdio.h>
#include <stdlib.h>
+#include <inttypes.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <err.h>
#include <time.h>
#include <libdevmapper.h>
-#include <libutil.h>
+#if defined(__linux__)
+#include <uuid/uuid.h>
+#elif defined(__DragonFly__)
+#include <uuid.h>
+#endif
#include "crc32.h"
#include "tcplay.h"
+#include "humanize.h"
/* XXX TODO:
@@ -54,22 +66,22 @@ char tc_internal_log_buffer[LOG_BUFFER_SZ];
void
tc_log(int is_err, const char *fmt, ...)
{
- __va_list ap;
+ va_list ap;
FILE *fp;
if (is_err)
fp = stderr;
else
fp = stdout;
- __va_start(ap, fmt);
+ va_start(ap, fmt);
vsnprintf(tc_internal_log_buffer, LOG_BUFFER_SZ, fmt, ap);
if (tc_internal_verbose)
vfprintf(fp, fmt, ap);
- __va_end(ap);
+ va_end(ap);
}
/* Supported algorithms */
@@ -360,7 +372,7 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
char buf[1024];
size_t blocks, blksz, hidden_blocks = 0;
struct tchdr_enc *ehdr, *hehdr = NULL;
- int64_t tmp;
+ uint64_t tmp;
int error, r;
if (cipher_chain == NULL)
@@ -417,8 +429,8 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
if (nkeyfiles > 0) {
/* Apply keyfiles to 'pass' */
- if ((error = apply_keyfiles(pass, MAX_PASSSZ, keyfiles,
- nkeyfiles))) {
+ if ((error = apply_keyfiles((unsigned char *)pass, MAX_PASSSZ,
+ keyfiles, nkeyfiles))) {
tc_log(1, "could not apply keyfiles\n");
}
}
@@ -461,8 +473,8 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
if (n_hkeyfiles > 0) {
/* Apply keyfiles to 'h_pass' */
- if ((error = apply_keyfiles(h_pass, MAX_PASSSZ, h_keyfiles,
- n_hkeyfiles))) {
+ if ((error = apply_keyfiles((unsigned char *)h_pass,
+ MAX_PASSSZ, h_keyfiles, n_hkeyfiles))) {
tc_log(1, "could not apply keyfiles\n");
return -1;
}
@@ -481,14 +493,14 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
/* This only happens in interactive mode */
while (hidden_blocks == 0) {
- if ((r = humanize_number(buf, strlen("XXX MB"),
- (int64_t)(blocks * blksz), "B", 0, 0)) < 0) {
+ if ((r = _humanize_number(buf, sizeof(buf),
+ (uint64_t)(blocks * blksz))) < 0) {
sprintf(buf, "%zu bytes", (blocks * blksz));
}
printf("The total volume size of %s is %s (bytes)\n", dev, buf);
memset(buf, 0, sizeof(buf));
- printf("Size of hidden volume (e.g. 127M): ");
+ printf("Size of hidden volume (e.g. 127M): ");
fflush(stdout);
if ((fgets(buf, sizeof(buf), stdin)) == NULL) {
@@ -498,7 +510,7 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
/* get rid of trailing newline */
buf[strlen(buf)-1] = '\0';
- if ((error = dehumanize_number(buf,
+ if ((error = _dehumanize_number(buf,
&tmp)) != 0) {
tc_log(1, "Could not interpret input: %s\n", buf);
return -1;
@@ -546,7 +558,8 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
}
/* create encrypted headers */
- ehdr = create_hdr(pass, (nkeyfiles > 0)?MAX_PASSSZ:strlen(pass),
+ ehdr = create_hdr((unsigned char *)pass,
+ (nkeyfiles > 0)?MAX_PASSSZ:strlen(pass),
prf_algo, cipher_chain, blksz, blocks, MIN_VOL_BLOCKS,
blocks-MIN_VOL_BLOCKS, 0);
if (ehdr == NULL) {
@@ -555,7 +568,7 @@ create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles
}
if (hidden) {
- hehdr = create_hdr(h_pass,
+ hehdr = create_hdr((unsigned char *)h_pass,
(n_hkeyfiles > 0)?MAX_PASSSZ:strlen(h_pass), h_prf_algo,
h_cipher_chain,
blksz, blocks, blocks - hidden_blocks, hidden_blocks, 1);
@@ -625,8 +638,8 @@ info_map_common(const char *dev, int sflag, const char *sys_dev,
if (nkeyfiles > 0) {
/* Apply keyfiles to 'pass' */
- if ((error = apply_keyfiles(pass, MAX_PASSSZ, keyfiles,
- nkeyfiles))) {
+ if ((error = apply_keyfiles((unsigned char *)pass, MAX_PASSSZ,
+ keyfiles, nkeyfiles))) {
tc_log(1, "could not apply keyfiles");
return NULL;
}
@@ -653,8 +666,8 @@ info_map_common(const char *dev, int sflag, const char *sys_dev,
if (n_hkeyfiles > 0) {
/* Apply keyfiles to 'pass' */
- if ((error = apply_keyfiles(h_pass, MAX_PASSSZ, h_keyfiles,
- n_hkeyfiles))) {
+ if ((error = apply_keyfiles((unsigned char *)h_pass, MAX_PASSSZ,
+ h_keyfiles, n_hkeyfiles))) {
tc_log(1, "could not apply keyfiles");
return NULL;
}
@@ -681,7 +694,8 @@ info_map_common(const char *dev, int sflag, const char *sys_dev,
hehdr = NULL;
}
- error = process_hdr(dev, pass, (nkeyfiles > 0)?MAX_PASSSZ:strlen(pass),
+ error = process_hdr(dev, (unsigned char *)pass,
+ (nkeyfiles > 0)?MAX_PASSSZ:strlen(pass),
ehdr, &info);
/*
@@ -691,11 +705,11 @@ info_map_common(const char *dev, int sflag, const char *sys_dev,
*/
if (hehdr && (error || protect_hidden)) {
if (error) {
- error2 = process_hdr(dev, pass,
+ error2 = process_hdr(dev, (unsigned char *)pass,
(nkeyfiles > 0)?MAX_PASSSZ:strlen(pass), hehdr,
&info);
} else if (protect_hidden) {
- error2 = process_hdr(dev, h_pass,
+ error2 = process_hdr(dev, (unsigned char *)h_pass,
(n_hkeyfiles > 0)?MAX_PASSSZ:strlen(h_pass), hehdr,
&hinfo);
}
@@ -814,7 +828,9 @@ dm_setup(const char *mapname, struct tcplay_info *info)
char *uu;
char *uu_stack[64];
int uu_stack_idx;
+#if defined(__DragonFly__)
uint32_t status;
+#endif
int ret = 0;
int j;
off_t start, offset;
@@ -842,7 +858,7 @@ dm_setup(const char *mapname, struct tcplay_info *info)
/* iv off---^ block off--^ */
snprintf(params, 512, "%s %s %"PRIu64 " %s %"PRIu64,
cipher_chain->cipher->dm_crypt_str, cipher_chain->dm_key,
- info->skip, dev, offset);
+ (uint64_t)info->skip, dev, (uint64_t)offset);
#ifdef DEBUG
printf("Params: %s\n", params);
#endif
@@ -868,6 +884,15 @@ dm_setup(const char *mapname, struct tcplay_info *info)
goto out;
}
+#if defined(__linux__)
+ uuid_generate(info->uuid);
+ if ((uu = malloc(1024)) == NULL) {
+ tc_log(1, "uuid_unparse memory failed\n");
+ ret = -1;
+ goto out;
+ }
+ uuid_unparse(info->uuid, uu);
+#elif defined(__DragonFly__)
uuid_create(&info->uuid, &status);
if (status != uuid_s_ok) {
tc_log(1, "uuid_create failed\n");
@@ -881,6 +906,7 @@ dm_setup(const char *mapname, struct tcplay_info *info)
ret = -1;
goto out;
}
+#endif
if ((dm_task_set_uuid(dmt, uu)) == 0) {
free(uu);
View
8 tcplay.h
@@ -57,7 +57,13 @@
#define DEBUG 1
#endif
+#include <inttypes.h>
+
+#if defined(__DragonFly__)
#include <uuid.h>
+#elif defined(__linux__)
+#include <uuid/uuid.h>
+#endif
struct pbkdf_prf_algo {
const char *name;
@@ -199,3 +205,5 @@ extern summary_fn_t summary_fn;
#define free_safe_mem(x) \
_free_safe_mem(x, __FILE__, __LINE__)
+
+#define __unused __attribute__((__unused__))

0 comments on commit 34165ed

Please sign in to comment.
Something went wrong with that request. Please try again.