From owner-svn-soc-all@FreeBSD.ORG Thu Jul 12 23:01:53 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 9936B106564A for ; Thu, 12 Jul 2012 23:01:51 +0000 (UTC) (envelope-from vchan@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Thu, 12 Jul 2012 23:01:51 +0000 Date: Thu, 12 Jul 2012 23:01:51 +0000 From: vchan@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120712230151.9936B106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r239322 - soc2012/vchan/gtcp/bwalex-tc-play X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2012 23:01:53 -0000 Author: vchan Date: Thu Jul 12 23:01:51 2012 New Revision: 239322 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239322 Log: it COMPILES...well mostly Modified: soc2012/vchan/gtcp/bwalex-tc-play/Makefile soc2012/vchan/gtcp/bwalex-tc-play/io.c soc2012/vchan/gtcp/bwalex-tc-play/main.c soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c soc2012/vchan/gtcp/bwalex-tc-play/tcplay.h Modified: soc2012/vchan/gtcp/bwalex-tc-play/Makefile ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/Makefile Thu Jul 12 22:55:48 2012 (r239321) +++ soc2012/vchan/gtcp/bwalex-tc-play/Makefile Thu Jul 12 23:01:51 2012 (r239322) @@ -30,8 +30,8 @@ endif - LIBS+= -lcrypto -ldm -lprop - SRCS+= crypto-dev.c + LIBS+= -lcrypto -lgeom -lutil -lsbuf + SRCS+= crypto-dev.c ggate.c OBJS+= crypto-dev.o SRCS+= pbkdf2-openssl.c OBJS+= pbkdf2-openssl.o Modified: soc2012/vchan/gtcp/bwalex-tc-play/io.c ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/io.c Thu Jul 12 22:55:48 2012 (r239321) +++ soc2012/vchan/gtcp/bwalex-tc-play/io.c Thu Jul 12 23:01:51 2012 (r239322) @@ -39,6 +39,7 @@ #include #include #include +#include #include "tcplay.h" Modified: soc2012/vchan/gtcp/bwalex-tc-play/main.c ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/main.c Thu Jul 12 22:55:48 2012 (r239321) +++ soc2012/vchan/gtcp/bwalex-tc-play/main.c Thu Jul 12 23:01:51 2012 (r239322) @@ -278,7 +278,7 @@ /* Create a new volume */ if (create_vol) { - error = create_volume(dev, contain_hidden, keyfiles, nkeyfiles, + error = create_volume(map_name, dev, contain_hidden, keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, prf, cipher_chain, h_prf, h_cipher_chain, NULL, NULL, 0, 1 /* interactive */, @@ -287,7 +287,7 @@ tc_log(1, "could not create new volume on %s\n", dev); } } else if (info_vol) { - error = info_volume(dev, sflag, sys_dev, protect_hidden, + error = info_volume(map_name, dev, sflag, sys_dev, protect_hidden, keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, NULL, NULL, 1 /* interactive */, DEFAULT_RETRIES, 0); } else if (map_vol) { Modified: soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c Thu Jul 12 22:55:48 2012 (r239321) +++ soc2012/vchan/gtcp/bwalex-tc-play/tcplay.c Thu Jul 12 23:01:51 2012 (r239322) @@ -85,6 +85,18 @@ static int unit = G_GATE_UNIT_AUTO; static int force = 0; static unsigned sectorsize = 0; +static unsigned flags = 0; + +static int +g_gate_openflags(unsigned ggflags) +{ + + if ((ggflags & G_GATE_FLAG_READONLY) != 0) + return (O_RDONLY); + else if ((ggflags & G_GATE_FLAG_WRITEONLY) != 0) + return (O_WRONLY); + return (O_RDWR); +} void tc_log(int is_err, const char *fmt, ...) @@ -402,7 +414,7 @@ } int -create_volume(const char *dev, int hidden, const char *keyfiles[], int nkeyfiles, +create_volume(const char *map_name, const char *dev, int hidden, const char *keyfiles[], int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles, struct pbkdf_prf_algo *prf_algo, struct tc_cipher_chain *cipher_chain, struct pbkdf_prf_algo *h_prf_algo, struct tc_cipher_chain *h_cipher_chain, char *passphrase, @@ -417,7 +429,8 @@ struct tchdr_enc *ehdr_backup, *hehdr_backup; uint64_t tmp; int error, r, ret; - + int fd; + pass = h_pass = pass_again = NULL; ehdr = hehdr = NULL; ehdr_backup = hehdr_backup = NULL; @@ -431,11 +444,12 @@ h_cipher_chain = cipher_chain; if (h_prf_algo == NULL) h_prf_algo = prf_algo; - - if ((error = get_disk_info(dev, &blocks, &blksz)) != 0) { - tc_log(1, "could not get disk info\n"); - return -1; - } + + fd = open(map_name, g_gate_openflags(flags)); + blksz = g_gate_sectorsize(fd); + blocks = g_gate_mediasize(fd)/blksz; + + if ((blocks*blksz) <= MIN_VOL_BYTES) { tc_log(1, "Cannot create volumes on devices with less " @@ -705,7 +719,7 @@ static struct tcplay_info * -info_map_common(const char *dev, int sflag, const char *sys_dev, +info_map_common(const char *map_name, const char *dev, int sflag, const char *sys_dev, int protect_hidden, const char *keyfiles[], int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles, char *passphrase, char *passphrase_hidden, int interactive, int retries, time_t timeout) @@ -717,8 +731,13 @@ int error, error2 = 0; size_t sz; size_t blocks, blksz; - - if ((error = get_disk_info(dev, &blocks, &blksz)) != 0) { + int fd; + + fd = open(map_name, g_gate_openflags(flags)); + blksz = g_gate_sectorsize(fd); + blocks = g_gate_mediasize(fd)/blksz; + + if (blksz == 0) { tc_log(1, "could not get disk information\n"); return NULL; } @@ -915,7 +934,7 @@ } int -info_volume(const char *device, int sflag, const char *sys_dev, +info_volume(const char *map_name, const char *device, int sflag, const char *sys_dev, int protect_hidden, const char *keyfiles[], int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles, char *passphrase, char *passphrase_hidden, int interactive, int retries, @@ -923,7 +942,7 @@ { struct tcplay_info *info; - info = info_map_common(device, sflag, sys_dev, protect_hidden, + info = info_map_common(map_name, device, sflag, sys_dev, protect_hidden, keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, passphrase, passphrase_hidden, interactive, retries, timeout); @@ -940,97 +959,6 @@ return -1; } -/* not correct yet -int -map_volume(int fd, int interactive) -{ - - struct g_gate_ctl_io ggio; - size_t bsize; - - if (g_gate_verbose == 0) { - if (daemon(0, 0) == -1) { - g_gate_destroy(unit, 1); - err(EXIT_FAILURE, "Cannot daemonize"); - } - } - g_gate_log(LOG_DEBUG, "Worker created: %u.", getpid()); - ggio.gctl_version = G_GATE_VERSION; - ggio.gctl_unit = unit; - bsize = sectorsize; - ggio.gctl_data = malloc(bsize); - for (;;) { - int error; -once_again: - ggio.gctl_length = bsize; - ggio.gctl_error = 0; - g_gate_ioctl(G_GATE_CMD_START, &ggio); - error = ggio.gctl_error; - switch (error) { - case 0: - break; - case ECANCELED: - /* Exit gracefully. - free(ggio.gctl_data); - g_gate_close_device(); - close(fd); - exit(EXIT_SUCCESS); - case ENOMEM: - /* Buffer too small. - assert(ggio.gctl_cmd == BIO_DELETE || - ggio.gctl_cmd == BIO_WRITE); - ggio.gctl_data = realloc(ggio.gctl_data, - ggio.gctl_length); - if (ggio.gctl_data != NULL) { - bsize = ggio.gctl_length; - goto once_again; - } - /* FALLTHROUGH - case ENXIO: - default: - g_gate_xlog("ioctl(/dev/%s): %s.", G_GATE_CTL_NAME, - strerror(error)); - } - - error = 0; - switch (ggio.gctl_cmd) { - case BIO_READ: - if ((size_t)ggio.gctl_length > bsize) { - ggio.gctl_data = realloc(ggio.gctl_data, - ggio.gctl_length); - if (ggio.gctl_data != NULL) - bsize = ggio.gctl_length; - else - error = ENOMEM; - } - if (error == 0) { - if (pread(fd, ggio.gctl_data, ggio.gctl_length, - ggio.gctl_offset) == -1) { - error = errno; - } - } - break; - case BIO_DELETE: - case BIO_WRITE: - if (pwrite(fd, ggio.gctl_data, ggio.gctl_length, - ggio.gctl_offset) == -1) { - error = errno; - } - break; - default: - error = EOPNOTSUPP; - } - - ggio.gctl_error = error; - g_gate_ioctl(G_GATE_CMD_DONE, &ggio); - } - - - if (interactive) - printf("All ok!\n"); - - return 0; -}*/ int map_volume(const char *map_name, const char *device, int sflag, @@ -1042,16 +970,15 @@ { struct tcplay_info *info; int error; - int fd; - info = info_map_common(device, sflag, sys_dev, protect_hidden, + info = info_map_common(map_name, device, sflag, sys_dev, protect_hidden, keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, passphrase, passphrase_hidden, interactive, retries, timeout); if (info == NULL) return -1; - if ((error = dm_setup(fd, info)) != 0) { + if ((error = dm_setup(map_name, info)) != 0) { tc_log(1, "Could not set up mapping %s\n", map_name); if (info->hdr) free_safe_mem(info->hdr); @@ -1070,7 +997,7 @@ static int -dm_remove_device() +dm_remove_device(void) { int ret = EINVAL; @@ -1084,55 +1011,24 @@ g_gate_open_device(); g_gate_destroy(unit, force); -/* -static -int -dm_remove_device(const char *name) -{ - struct dm_task *dmt = NULL; - int ret = EINVAL; - - if ((dmt = dm_task_create(DM_DEVICE_REMOVE)) == NULL) - goto out; - - if ((dm_task_set_name(dmt, name)) == 0) - goto out; - - if ((dm_task_run(dmt)) == 0) - goto out; - - ret = 0; -out: - if (dmt) - dm_task_destroy(dmt); -*/ return ret; } int -dm_setup(int fd, struct tcplay_info *info) +dm_setup(const char *map_name, struct tcplay_info *info) { - /* Commented out variables not needed in freeBSD*/ struct tc_cipher_chain *cipher_chain; -// struct dm_task *dmt = NULL; -// struct dm_info dmi; - char *params = NULL; -// char *uu; - char *uu_stack[64]; - int uu_stack_idx; -/*#if defined(__DragonFly__) - uint32_t status; -#endif*/ - int r, ret = 0; + int ret = 0; int j; + int fd; off_t start, offset; char dev[PATH_MAX]; - char map[PATH_MAX]; + char *params = NULL; uint32_t cookie; - - /* dm_udev_set_sync_support(1); */ + fd = open(map_name, g_gate_openflags(flags) | O_DIRECT | O_FSYNC); + if ((params = alloc_safe_mem(512)) == NULL) { tc_log(1, "could not allocate safe parameters memory"); return ENOMEM; @@ -1141,7 +1037,6 @@ strcpy(dev, info->dev); start = info->start; offset = info->offset; - uu_stack_idx = 0; /* Get to the end of the chain */ for (cipher_chain = info->cipher_chain; cipher_chain->next != NULL; @@ -1152,7 +1047,6 @@ cipher_chain = cipher_chain->prev, j++) { cookie = 0; - //force = 1; used in g_gate_destroy /* aes-cbc-essiv:sha256 7997f8af... 0 /dev/ad0s0a 8 */ /* iv off---^ block off--^ */ @@ -1162,91 +1056,7 @@ #ifdef DEBUG printf("Params: %s\n", params); #endif - /* - if ((dmt = dm_task_create(DM_DEVICE_CREATE)) == NULL) { - tc_log(1, "dm_task_create failed\n"); - ret = -1; - goto out; - } - */ - - /* - * If this is the last element in the cipher chain, use the - * final map name. Otherwise pick a secondary name... - - if (cipher_chain->prev == NULL) - strcpy(map, mapname); - else - sprintf(map, "%s.%d", mapname, j); - - /* changed from, "if ((dm_task_set_name(dmt, map)) == 0" - if (map == NULL) { - tc_log(1, "task_set_name failed\n"); - ret = -1; - 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"); - ret = -1; - goto out; - } - - uuid_to_string(&info->uuid, &uu, &status); - if (uu == NULL) { - tc_log(1, "uuid_to_string failed\n"); - ret = -1; - goto out; - } -#endif - - if (( dm_task_set_uuid(dmt, uu)) == 0) { - free(uu); - tc_log(1, "dm_task_set_uuid failed\n"); - ret = -1; - goto out; - } - - free(uu); - - if (( dm_task_add_target(dmt, start, info->size, "crypt", params)) == 0) { - tc_log(1, "dm_task_add_target failed\n"); - ret = -1; - goto out; - } - - if ((dm_task_set_cookie(dmt, &cookie, 0)) == 0) { - tc_log(1, "dm_task_set_cookie failed\n"); - ret = -1; - goto out; - } - - if ((dm_task_run(dmt)) == 0) { - dm_udev_wait(cookie); - tc_log(1, "dm_task_run failed\n"); - ret = -1; - goto out; - } - - if ((dm_task_get_info(dmt, &dmi)) == 0) { - dm_udev_wait(cookie); - tc_log(1, "dm_task_get info failed\n"); - ret = -1; - goto out; - } - - dm_udev_wait(cookie); -*/ + } //FreeBSD struct g_gate_ctl_io ggio; @@ -1329,42 +1139,6 @@ g_gate_ioctl(G_GATE_CMD_DONE, &ggio); } -/* if ((r = asprintf(&uu_stack[uu_stack_idx++], "%s", map)) < 0) - tc_log(1, "warning, asprintf failed. won't be able to " - "unroll changes\n"); - - - offset = 0; - start = 0; - sprintf(dev, "/dev/mapper/%s.%d", mapname, j); - - /* was dm_task_destroy(dmt); - /*not needed in FreeBSD dm_task_update_nodes(); - } - -out: - /* - * If an error occured, try to unroll changes made before it - * happened. - - if (ret) { - j = uu_stack_idx; - while (j > 0) { -#ifdef DEBUG - printf("Unrolling dm changes! j = %d (%s)\n", j-1, - uu_stack[j-1]); -#endif - if ((uu_stack[j-1] == NULL) || - ((r = dm_remove_device(uu_stack[--j])) != 0)) { - tc_log(1, "Tried to unroll dm changes, " - "giving up.\n"); - break; - } - } - } -*/ - while (uu_stack_idx > 0) - free(uu_stack[--uu_stack_idx]); free_safe_mem(params); @@ -1374,14 +1148,11 @@ int dm_teardown(const char *mapname, const char *device __unused) { -#if 0 - struct dm_task *dmt = NULL; - struct dm_info dmi; -#endif + char map[PATH_MAX]; int i, error; - if ((error = dm_remove_device(mapname)) != 0) { + if ((error = dm_remove_device()) != 0) { tc_log(1, "Could not remove mapping %s\n", mapname); return error; } @@ -1389,7 +1160,7 @@ /* Try to remove other cascade devices */ for (i = 2; i >= 0; i--) { sprintf(map, "%s.%d", mapname, i); - dm_remove_device(map); + dm_remove_device(); } return 0; Modified: soc2012/vchan/gtcp/bwalex-tc-play/tcplay.h ============================================================================== --- soc2012/vchan/gtcp/bwalex-tc-play/tcplay.h Thu Jul 12 22:55:48 2012 (r239321) +++ soc2012/vchan/gtcp/bwalex-tc-play/tcplay.h Thu Jul 12 23:01:51 2012 (r239322) @@ -116,6 +116,7 @@ } __attribute__((__packed__)); struct tcplay_info { + const char *map_name; const char *dev; struct tchdr_dec *hdr; struct tc_cipher_chain *cipher_chain; @@ -185,13 +186,13 @@ int adjust_info(struct tcplay_info *info, struct tcplay_info *hinfo); int process_hdr(const char *dev, int sflag, unsigned char *pass, int passlen, struct tchdr_enc *ehdr, struct tcplay_info **pinfo); -int create_volume(const char *dev, int hidden, const char *keyfiles[], +int create_volume(const char *map_name, const char *dev, int hidden, const char *keyfiles[], int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles, struct pbkdf_prf_algo *prf_algo, struct tc_cipher_chain *cipher_chain, struct pbkdf_prf_algo *h_prf_algo, struct tc_cipher_chain *h_cipher_chain, char *passphrase, char *h_passphrase, size_t hidden_bytes_in, int interactive, int secure_erase); -int info_volume(const char *device, int sflag, const char *sys_dev, +int info_volume(const char *map_name, const char *device, int sflag, const char *sys_dev, int protect_hidden, const char *keyfiles[], int nkeyfiles, const char *h_keyfiles[], int n_hkeyfiles, char *passphrase, char *passphrase_hidden, int interactive, int retries,