From f56732113e534c3bd29af551a2261d2f07e9c5ea Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Mon, 26 Dec 2011 04:19:01 +0000 Subject: [PATCH] cryptop.list: New tool for listing keys. Organization: Straylight/Edgeware From: Mark Wooding Surprisingly nice output format. --- Makefile.am | 1 + cryptop.list | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100755 cryptop.list diff --git a/Makefile.am b/Makefile.am index ba7fdff..9491f71 100644 --- a/Makefile.am +++ b/Makefile.am @@ -119,6 +119,7 @@ dist_pkglib_DATA += ktype.seccure ## Commands. dist_pkglib_SCRIPTS += cryptop.genkey +dist_pkglib_SCRIPTS += cryptop.list dist_pkglib_SCRIPTS += cryptop.delkey dist_pkglib_SCRIPTS += cryptop.recover dist_pkglib_SCRIPTS += cryptop.info diff --git a/cryptop.list b/cryptop.list new file mode 100755 index 0000000..c51f402 --- /dev/null +++ b/cryptop.list @@ -0,0 +1,268 @@ +#! /bin/sh +### +### List a user's keys +### +### (c) 2011 Mark Wooding +### + +###----- Licensing notice --------------------------------------------------- +### +### This file is part of the distorted.org.uk key management suite. +### +### distorted-keys is free software; you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 2 of the License, or +### (at your option) any later version. +### +### distorted-keys is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with distorted-keys; if not, write to the Free Software Foundation, +### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +set -e +case "${KEYSLIB+t}" in t) ;; *) echo >&2 "$0: KEYSLIB unset"; exit 1 ;; esac +. "$KEYSLIB"/keyfunc.sh + +defhelp <&2 "$quis: unknown column \`$name'"; exit 1 ;; + esac +done + +## Second and third pass: find the keys, compute their properties and either +## measure column widths or display the results. +while :; do + + ## Decide whether we need to display a header. (We need this on both + ## passes, because it may contribute to width.) + doheader=$header + + ## Find the metadata files. This tells us where the keys are. + case $all in + t) dir=store ;; + nil) dir=store/$user ;; + esac + metas=$(find store -type f -name meta) + + ## Work through the keys we found. + while :; do + + ## If we're not doing a header line, read the next metadata file name. + ## Check that it matches at least one pattern. + case $doheader in + nil) + if ! read meta; then break; fi + label=${meta#store/}; label=${label%/meta} + matchp=nil + for pat in "$@"; do + case "$label" in $pat) matchp=t; break ;; esac + done + case $matchp in nil) continue ;; esac + ;; + esac + + ## Now iterate over the columns. If we're calculating widths, use the + ## ones we worked out last time, and clear the list so we can build a new + ## one as we go. + case $calcwd in t) cols=$wdcols ;; esac + cc=$cols wdcols="" sep="" + while :; do + + ## Pick off the next column spec. + case "$cc" in + *,*) col=${cc%%,*} cc=${cc#*,} ;; + ?*) col=$cc cc="" ;; + *) break ;; + esac + + ## Work out the column name. + name=${col%[:=+]*} wd=${col#*[:=+]} + + ## Work out the value. If this is a header line, then it's just the + ## column name in upper case; otherwise we have work to do. + case $doheader in + t) value=$(echo $name | tr a-z A-Z) ;; + nil) value=$(col_$name $label) ;; + esac + + ## Work out what to do about it. If we're measuring, then update our + ## idea of the column width. If we're printing, work out a format. + case $calcwd,$col in + t,*[:=]*) + wdcols=${wdcols:+$wdcols,}$col + ;; + t,*+*) + colwd=$(( $(echo "$value" | wc -c) - 1 )) + if [ $colwd -gt $wd ]; then wd=$colwd; fi + wdcols=${wdcols:+$wdcols,}$name+$wd + ;; + nil,*[=+]*) + fmt="%-${wd}.${wd}s" + ;; + nil,*:*) + fmt="%-${wd}s" + ;; + esac + + ## If we're printing, then print something. Leave space between the + ## columns. + case $calcwd in nil) printf "$sep$fmt" "$value"; sep=" " ;; esac + done + + ## The next line will certainly not be a header. + doheader=nil + + ## Start a new line if we're printing. + case $calcwd in nil) printf "\n" ;; esac + done <