1/*- 2 * Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sbin/geom/class/eli/geom_eli.c 162353 2006-09-16 10:43:17Z pjd $"); |
29 30#include <stdio.h> 31#include <stdint.h> 32#include <stdlib.h> 33#include <unistd.h> 34#include <fcntl.h> 35#include <readpassphrase.h> 36#include <string.h> --- 23 unchanged lines hidden (view full) --- 60static intmax_t keyno = -1; 61static intmax_t iterations = -1; 62static intmax_t sectorsize = 0; 63static char keyfile[] = "", newkeyfile[] = ""; 64 65static void eli_main(struct gctl_req *req, unsigned flags); 66static void eli_init(struct gctl_req *req); 67static void eli_attach(struct gctl_req *req); |
68static void eli_configure(struct gctl_req *req); |
69static void eli_setkey(struct gctl_req *req); 70static void eli_delkey(struct gctl_req *req); 71static void eli_kill(struct gctl_req *req); 72static void eli_backup(struct gctl_req *req); 73static void eli_restore(struct gctl_req *req); 74static void eli_clear(struct gctl_req *req); 75static void eli_dump(struct gctl_req *req); 76 77/* 78 * Available commands: 79 * 80 * init [-bhPv] [-a aalgo] [-e ealgo] [-i iterations] [-l keylen] [-K newkeyfile] prov 81 * label - alias for 'init' 82 * attach [-dprv] [-k keyfile] prov 83 * detach [-fl] prov ... 84 * stop - alias for 'detach' 85 * onetime [-d] [-a aalgo] [-e ealgo] [-l keylen] prov ... |
86 * configure [-bB] prov ... |
87 * setkey [-pPv] [-n keyno] [-k keyfile] [-K newkeyfile] prov 88 * delkey [-afv] [-n keyno] prov 89 * kill [-av] [prov ...] 90 * backup [-v] prov file 91 * restore [-v] file prov 92 * clear [-v] prov ... 93 * dump [-v] prov ... 94 */ --- 58 unchanged lines hidden (view full) --- 153 { 'd', "detach", NULL, G_TYPE_NONE }, 154 { 'e', "ealgo", ealgo, G_TYPE_STRING }, 155 { 'l', "keylen", &keylen, G_TYPE_NUMBER }, 156 { 's', "sectorsize", §orsize, G_TYPE_NUMBER }, 157 G_OPT_SENTINEL 158 }, 159 "[-d] [-a aalgo] [-e ealgo] [-l keylen] [-s sectorsize] prov ..." 160 }, |
161 { "configure", G_FLAG_VERBOSE, eli_main, 162 { 163 { 'b', "boot", NULL, G_TYPE_NONE }, 164 { 'B', "noboot", NULL, G_TYPE_NONE }, 165 G_OPT_SENTINEL 166 }, 167 "[-bB] prov ..." 168 }, |
169 { "setkey", G_FLAG_VERBOSE, eli_main, 170 { 171 { 'i', "iterations", &iterations, G_TYPE_NUMBER }, 172 { 'k', "keyfile", keyfile, G_TYPE_STRING }, 173 { 'K', "newkeyfile", newkeyfile, G_TYPE_STRING }, 174 { 'n', "keyno", &keyno, G_TYPE_NUMBER }, 175 { 'p', "nopassphrase", NULL, G_TYPE_NONE }, 176 { 'P', "nonewpassphrase", NULL, G_TYPE_NONE }, --- 70 unchanged lines hidden (view full) --- 247 if (name == NULL) { 248 gctl_error(req, "No '%s' argument.", "verb"); 249 return; 250 } 251 if (strcmp(name, "init") == 0 || strcmp(name, "label") == 0) 252 eli_init(req); 253 else if (strcmp(name, "attach") == 0) 254 eli_attach(req); |
255 else if (strcmp(name, "configure") == 0) 256 eli_configure(req); |
257 else if (strcmp(name, "setkey") == 0) 258 eli_setkey(req); 259 else if (strcmp(name, "delkey") == 0) 260 eli_delkey(req); 261 else if (strcmp(name, "kill") == 0) 262 eli_kill(req); 263 else if (strcmp(name, "backup") == 0) 264 eli_backup(req); --- 408 unchanged lines hidden (view full) --- 673 if (gctl_issue(req) == NULL) { 674 if (verbose) 675 printf("Attched to %s.\n", prov); 676 } 677 bzero(key, sizeof(key)); 678} 679 680static void |
681eli_configure_detached(struct gctl_req *req, const char *prov, int boot) 682{ 683 struct g_eli_metadata md; 684 685 if (eli_metadata_read(req, prov, &md) == -1) 686 return; 687 688 if (boot && (md.md_flags & G_ELI_FLAG_BOOT)) { 689 if (verbose) 690 printf("BOOT flag already configured for %s.\n", prov); 691 } else if (!boot && !(md.md_flags & G_ELI_FLAG_BOOT)) { 692 if (verbose) 693 printf("BOOT flag not configured for %s.\n", prov); 694 } else { 695 if (boot) 696 md.md_flags |= G_ELI_FLAG_BOOT; 697 else 698 md.md_flags &= ~G_ELI_FLAG_BOOT; 699 eli_metadata_store(req, prov, &md); 700 } 701 bzero(&md, sizeof(md)); 702} 703 704static void 705eli_configure(struct gctl_req *req) 706{ 707 const char *prov; 708 int i, nargs, boot, noboot; 709 710 nargs = gctl_get_int(req, "nargs"); 711 if (nargs == 0) { 712 gctl_error(req, "Too few arguments."); 713 return; 714 } 715 716 boot = gctl_get_int(req, "boot"); 717 noboot = gctl_get_int(req, "noboot"); 718 719 if (boot && noboot) { 720 gctl_error(req, "Options -b and -B are mutually exclusive."); 721 return; 722 } 723 if (!boot && !noboot) { 724 gctl_error(req, "No option given."); 725 return; 726 } 727 728 /* First attached providers. */ 729 gctl_issue(req); 730 /* Now the rest. */ 731 for (i = 0; i < nargs; i++) { 732 prov = gctl_get_ascii(req, "arg%d", i); 733 if (!eli_is_attached(prov)) 734 eli_configure_detached(req, prov, boot); 735 } 736} 737 738static void |
739eli_setkey_attached(struct gctl_req *req, struct g_eli_metadata *md) 740{ 741 unsigned char key[G_ELI_USERKEYLEN]; 742 intmax_t val; 743 744 val = gctl_get_intmax(req, "iterations"); 745 /* Check if iterations number should be changed. */ 746 if (val != -1) --- 484 unchanged lines hidden --- |