On 2012-05-25 at 10:53 -0400, Phil Pennock wrote:
> Attached patch for sksclient.ml lets it take multiple keys on argv and
> strips an optional 0x from the front of a keyid.

Attached patch is my diff from your hg tip.  Fixes the bdb include,
changes sksclient to:

 * use -stdin to read from stdin, one key per line
 * else expect keys to be in argv, not just first item in argv
 * strip off leading 0x

A lot of debugging caused by a missing semi-colon after a raise.

Attempted to find a sane way to add to settings.ml only for this file,
or replace settings, but decided against overhauling the Makefile or
using new globals examined at run-time -- I don't know enough about
order of execution of "let () = " blocks from various compilation units.
So I just made -stdin a standard option, albeit one only used by
sksclient.

Regards,
-Phil
diff --git a/bdb/Makefile b/bdb/Makefile
--- a/bdb/Makefile
+++ b/bdb/Makefile
@@ -13,6 +13,8 @@
 
 # $Id: Makefile,v 1.6 2003/07/05 15:16:29 yminsky Exp $
 
+include ../Makefile.local
+
 CINCLUDES=-I`ocamlc -where` $(BDBINCLUDE)
 CC=gcc
 CXX=g++
diff --git a/settings.ml b/settings.ml
--- a/settings.ml
+++ b/settings.ml
@@ -197,6 +197,8 @@ let get_from_addr () =
 	from_addr := Some addr;
 	addr
 
+let use_stdin = ref false
+
 let basedir = ref "."
 
 let base_dbdir = "KDB"
@@ -315,6 +317,8 @@ let parse_spec =
      " Disable sending of PKS mailsync messages.  ONLY FOR STANDALONE SERVERS!");
     ("-disable_log_diffs", Arg.Clear log_diffs,
      " Disable logging of recent hashset diffs.");
+    ("-stdin", Arg.Set use_stdin,
+     " Read keyids from stdin (sksclient only)");
   ]
 
 let parse_spec = Arg.align parse_spec
diff --git a/sksclient.ml b/sksclient.ml
--- a/sksclient.ml
+++ b/sksclient.ml
@@ -20,25 +20,20 @@ open MoreLabels
 open Printf
 open Common
 open DbMessages
-  
+
 exception Misc_error of string
 exception No_results of string
 
-let key_id =
-  if Array.length Sys.argv = 2 then
-    Sys.argv.(1)
-  else
-    ""
-
 let settings = {
     Keydb.withtxn = !Settings.transactions;
     Keydb.cache_bytes = !Settings.cache_bytes;
     Keydb.pagesize = !Settings.pagesize;
     Keydb.dbdir = Lazy.force Settings.dbdir;
     Keydb.dumpdir = Lazy.force Settings.dumpdir;
- } 
- module Keydb = Keydb.Safe
-	 
+}
+
+module Keydb = Keydb.Safe
+
 let get_keys_by_keyid keyid =
     let keyid_length = String.length keyid in
     let short_keyid = String.sub ~pos:(keyid_length - 4) ~len:4 keyid in
@@ -47,7 +42,7 @@ let get_keys_by_keyid keyid =
       | 4 -> (* 32-bit keyid.  No further filtering required. *)
 	  keys
 
-      | 8 -> (* 64-bit keyid *) 
+      | 8 -> (* 64-bit keyid *)
 	   List.filter keys
 	   ~f:(fun key -> keyid = (Fingerprint.from_key key).Fingerprint.keyid ||
 	   (** Return keys i& subkeys with matching long keyID *)
@@ -55,19 +50,47 @@ let get_keys_by_keyid keyid =
 	     List.exists (fun x -> x = keyid) subkeyids)
 
       | _ -> raise (Misc_error "Unknown keyid type")
-	  
-let () =
-	set_logfile "sksclient";
-	Keydb.open_dbs settings; 	
-	let keys = get_keys_by_keyid (KeyHash.dehexify key_id) in 
+
+let dump_one_key keyid =
+    begin
+	let deprefixed = (
+	    if String.sub keyid 0 2 = "0x" then
+		String.sub keyid 2 (String.length keyid - 2)
+	    else keyid
+	) in
+	let keys = get_keys_by_keyid (KeyHash.dehexify deprefixed) in
 	let count = List.length keys in
 	if count < 1 then
-	 exit 2;	 
-	let aakeys = 
+	 exit 2;
+	let aakeys =
 	    match keys with
 	      | [] -> ""
 	      | _ -> let keystr = Key.to_string_multiple keys in
 		      Armor.encode_pubkey_string keystr
 	  in
-	printf "%s\n" aakeys;	
-	Keydb.close_dbs ();
+	printf "%s\n" aakeys;
+    end
+
+let keysource action =
+    if !Settings.use_stdin then
+	try
+	    while true do
+		let line = input_line stdin in
+		action line;
+	    done;
+	with
+	End_of_file -> printf "";
+    else
+	begin
+	    let len = Array.length Sys.argv in
+	    let params = Array.sub Sys.argv 1 (len-1) in
+	    Array.iter action params;
+	end
+
+let () =
+    if (Array.length Sys.argv) < 2 then
+	raise(Misc_error "Keys in argv unless -stdin set");
+    set_logfile "sksclient";
+    Keydb.open_dbs settings;
+    keysource dump_one_key;
+    Keydb.close_dbs ();

Attachment: pgpg1IP6rKS1x.pgp
Description: PGP signature

_______________________________________________
Sks-devel mailing list
Sks-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/sks-devel

Reply via email to