PERFORCE change 169074 for review

Gleb Kurtsou gk at FreeBSD.org
Thu Oct 1 11:08:27 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=169074

Change 169074 by gk at gk_h1 on 2009/10/01 11:07:39

	use consistent names for pefs commands
	print supported algorithms

Affected files ...

.. //depot/projects/soc2009/gk_pefs/sbin/pefs/pefs_ctl.c#9 edit
.. //depot/projects/soc2009/gk_pefs/sbin/pefs/pefs_ctl.h#9 edit
.. //depot/projects/soc2009/gk_pefs/sbin/pefs/pefs_key.c#8 edit

Differences ...

==== //depot/projects/soc2009/gk_pefs/sbin/pefs/pefs_ctl.c#9 (text+ko) ====

@@ -59,11 +59,12 @@
 static int	pefs_setkey(int argc, char *argv[]);
 static int	pefs_delkey(int argc, char *argv[]);
 static int	pefs_flushkeys(int argc, char *argv[]);
-static int	pefs_setchain(int argc, char *argv[]);
+static int	pefs_addchain(int argc, char *argv[]);
 static int	pefs_delchain(int argc, char *argv[]);
 static int	pefs_randomchain(int argc, char *argv[]);
 static int	pefs_showkeys(int argc, char *argv[]);
-static int	pefs_showchain(int argc, char *argv[]);
+static int	pefs_showchains(int argc, char *argv[]);
+static int	pefs_showalgs(int argc, char *argv[]);
 
 typedef int (*command_func_t)(int argc, char **argv);
 typedef int (*keyop_func_t)(struct pefs_keychain_head *kch, int fd,
@@ -85,9 +86,10 @@
 	{ "showkeys", pefs_showkeys },
 	{ "status", pefs_showkeys },
 	{ "randomchain", pefs_randomchain },
-	{ "setchain", pefs_setchain },
+	{ "addchain", pefs_addchain },
 	{ "delchain", pefs_delchain },
-	{ "showchain", pefs_showchain },
+	{ "showchains", pefs_showchains },
+	{ "showalgs", pefs_showalgs },
 	{ NULL, NULL },
 };
 
@@ -405,9 +407,8 @@
 pefs_showkeys(int argc, char *argv[])
 {
 	struct pefs_xkey k;
-	int chain, fd, i;
+	int fd, i;
 
-	chain = 1;
 	while ((i = getopt(argc, argv, "")) != -1)
 		switch(i) {
 		case '?':
@@ -442,9 +443,6 @@
 	}
 	close(fd);
 
-	if (chain) {
-	}
-
 	return (0);
 }
 
@@ -483,7 +481,7 @@
 }
 
 static int
-pefs_setchain(int argc, char *argv[])
+pefs_addchain(int argc, char *argv[])
 {
 	struct pefs_keychain *kc;
 	struct pefs_keychain_head kch;
@@ -690,7 +688,7 @@
 }
 
 static int
-pefs_showchain(int argc, char *argv[])
+pefs_showchains(int argc, char *argv[])
 {
 	struct pefs_xkey k;
 	struct pefs_keyparam kp;
@@ -813,7 +811,18 @@
 	return (0);
 }
 
+static int
+pefs_showalgs(int argc, char *argv[] __unused)
+{
+	if (argc != 0)
+		pefs_usage();
+
+	pefs_alg_list(stdout);
+
+	return (0);
+}
 
+
 void
 pefs_usage(void)
 {
@@ -824,12 +833,14 @@
 "	pefs setkey [-cCpvx] [-a alg] [-i iterations] [-k keyfile] directory\n"
 "	pefs delkey [-cCpv] [-i iterations] [-k keyfile] filesystem\n"
 "	pefs flushkeys filesystem\n"
-"	pefs setchain [-pPvZ] [-a alg] [-i iterations] [-k keyfile]\n"
+"	pefs showkeys filesystem\n"
+"	pefs addchain [-pPvZ] [-a alg] [-i iterations] [-k keyfile]\n"
 "		[-A alg] [-I iterations] [-K keyfile] filesystem\n"
 "	pefs delchain [-pv] [-i iterations] [-k keyfile] filesystem\n"
-"	pefs showchain [-p] [-i iterations] [-k keyfile] filesystem\n"
 "	pefs randomchain [-v] [-a alg] [-n min] [-N max] filesystem\n"
-"	pefs showkeys filesystem\n");
+"	pefs showchains [-p] [-i iterations] [-k keyfile] filesystem\n"
+"	pefs showalgs\n"
+);
 	exit(EX_USAGE);
 }
 

==== //depot/projects/soc2009/gk_pefs/sbin/pefs/pefs_ctl.h#9 (text+ko) ====

@@ -74,5 +74,5 @@
     const struct pefs_xkey *xk_parent);
 uintmax_t	pefs_keyid_as_int(char *keyid);
 const char *	pefs_alg_name(struct pefs_xkey *xk);
-int	pefs_alg_lookup(struct pefs_xkey *xk, const char *algname);
+void	pefs_alg_list(FILE *stream);
 

==== //depot/projects/soc2009/gk_pefs/sbin/pefs/pefs_key.c#8 (text+ko) ====

@@ -58,7 +58,6 @@
 };
 
 static struct algorithm algs[] = {
-	{ "salsa20-256", PEFS_ALG_SALSA20, 256 },
 	{ "aes128-ctr", PEFS_ALG_AES_CTR, 128 },
 	{ "aes128", PEFS_ALG_AES_CTR, 128 },
 	{ "aes192-ctr", PEFS_ALG_AES_CTR, 192 },
@@ -71,6 +70,7 @@
 	{ "camellia192", PEFS_ALG_CAMELLIA_CTR, 192 },
 	{ "camellia256-ctr", PEFS_ALG_CAMELLIA_CTR, 256 },
 	{ "camellia256", PEFS_ALG_CAMELLIA_CTR, 256 },
+	{ "salsa20-256", PEFS_ALG_SALSA20, 256 },
 	{ NULL, 0, 0 },
 };
 
@@ -87,7 +87,26 @@
 	return ("<unknown algorithm>");
 }
 
-int
+void
+pefs_alg_list(FILE *stream)
+{
+	struct algorithm *prev, *alg;
+
+	fprintf(stream, "Supported algorithms:\n");
+	for (prev = NULL, alg = algs; alg->name != NULL; prev = alg++) {
+		if (prev != NULL && alg->id == prev->id &&
+		    alg->keybits == prev->keybits) {
+			fprintf(stream, "\t%s\t(alias for %s)\n", alg->name, prev->name);
+		} else if (alg->id == PEFS_ALG_DEFAULT &&
+		    alg->keybits == PEFS_ALG_DEFAULT_KEYBITS) {
+			fprintf(stream, "\t%s\t(default)\n", alg->name);
+		} else {
+			fprintf(stream, "\t%s\n", alg->name);
+		}
+	}
+}
+
+static int
 pefs_alg_lookup(struct pefs_xkey *xk, const char *algname)
 {
 	struct algorithm *alg;
@@ -117,8 +136,11 @@
 	xk->pxk_keybits = PEFS_ALG_DEFAULT_KEYBITS;
 
 	if (kp->kp_alg != NULL) {
-		if (pefs_alg_lookup(xk, kp->kp_alg) < 0)
-			errx(EX_USAGE, "invalid algorithm %s", kp->kp_alg);
+		if (pefs_alg_lookup(xk, kp->kp_alg) < 0) {
+			warnx("invalid algorithm %s", kp->kp_alg);
+			pefs_alg_list(stderr);
+			exit(EX_USAGE);
+		}
 	}
 
 	g_eli_crypto_hmac_init(&ctx, NULL, 0);


More information about the p4-projects mailing list