# # add_file "tests/t_genkey_without_db.at" # # patch "ChangeLog" # from [cb52fecca27e830df7df79c18b526554e38b2b4e] # to [328429c6ea96553c432ab4c36e7983fc9b830282] # # patch "commands.cc" # from [3a5202dce2bd8a380ac9bf9b2ad736eca43dd25e] # to [7f5675e9a296b976e5ea81b4d7639326c6a3ce02] # # patch "database.cc" # from [a3c4507bf09e5aade2dd702ddc8c91f51d51df12] # to [9b5ee8d99b550e10e7dea779cbc9aa6c02f359b3] # # patch "database.hh" # from [4935d9f82c7eb489d96f79285db844a611c5a095] # to [3e62dfc435b831ba05a3e7a478d74b73916bc92e] # # patch "tests/t_genkey_without_db.at" # from [] # to [9f4369d40515411569f9d030694ecfb9222af4b9] # # patch "testsuite.at" # from [48e49271ecdf069dcde09ada32c00900cf66bd5b] # to [551e9015ab6f27e259a06d2c89bc694d467167ca] # ======================================================================== --- ChangeLog cb52fecca27e830df7df79c18b526554e38b2b4e +++ ChangeLog 328429c6ea96553c432ab4c36e7983fc9b830282 @@ -1,3 +1,13 @@ +2005-10-06 Timothy Brownawell + + * database.{cc,hh}: new function, database::database_specified() + return whether we were given a database (doesn't care about validity, + only that we were told to use one) + * commands.cc (genkey): don't insist on having a db, but still + check it for duplicates if we're given one. + * tests/t_genkey_without_db.at: make sure it works + * testsuite.at: add test + 2005-09-28 Timothy Brownawell * keys.cc (get_private_key): don't use lua hook passwords for ======================================================================== --- commands.cc 3a5202dce2bd8a380ac9bf9b2ad736eca43dd25e +++ commands.cc 7f5675e9a296b976e5ea81b4d7639326c6a3ce02 @@ -840,21 +840,24 @@ { if (args.size() != 1) throw usage(name); - - transaction_guard guard(app.db); + rsa_keypair_id ident; internalize_rsa_keypair_id(idx(args, 0), ident); + bool exists = app.keys.key_pair_exists(ident); + if (app.db.database_specified()) + { + transaction_guard guard(app.db); + exists = exists || app.db.public_key_exists(ident); + guard.commit(); + } - N(! (app.db.public_key_exists(ident) || app.keys.key_pair_exists(ident)), - F("key '%s' already exists") % ident); + N(!exists, F("key '%s' already exists") % ident); keypair kp; P(F("generating key-pair '%s'\n") % ident); generate_key_pair(app.lua, ident, kp); P(F("storing key-pair '%s' in keystore\n") % ident); app.keys.put_key_pair(ident, kp); - - guard.commit(); } CMD(dropkey, N_("key and cert"), N_("KEYID"), N_("drop a public and private key"), OPT_NONE) ======================================================================== --- database.cc a3c4507bf09e5aade2dd702ddc8c91f51d51df12 +++ database.cc 9b5ee8d99b550e10e7dea779cbc9aa6c02f359b3 @@ -2348,6 +2348,13 @@ } +bool +database::database_specified() +{ + return !filename.empty(); +} + + void database::open() { ======================================================================== --- database.hh 4935d9f82c7eb489d96f79285db844a611c5a095 +++ database.hh 3e62dfc435b831ba05a3e7a478d74b73916bc92e @@ -216,6 +216,7 @@ void migrate(); void rehash(); void ensure_open(); + bool database_specified(); bool file_version_exists(file_id const & id); bool manifest_version_exists(manifest_id const & id); ======================================================================== --- tests/t_genkey_without_db.at +++ tests/t_genkey_without_db.at 9f4369d40515411569f9d030694ecfb9222af4b9 @@ -0,0 +1,11 @@ +AT_SETUP([genkey without a database]) + +MONOTONE_SETUP + +# with no database should work +AT_CHECK((echo foobar; echo foobar) | RAW_MONOTONE --keydir=keys genkey foobar, [], [ignore], [ignore]) + +# with an invalid database should fail +AT_CHECK((echo address@hidden; echo address@hidden) | RAW_MONOTONE --keydir=keys --db=bork genkey address@hidden, [1], [ignore], [ignore]) + +AT_CLEANUP ======================================================================== --- testsuite.at 48e49271ecdf069dcde09ada32c00900cf66bd5b +++ testsuite.at 551e9015ab6f27e259a06d2c89bc694d467167ca @@ -708,3 +708,4 @@ m4_include(tests/t_automate_get_revision.at) m4_include(tests/t_unreadable_db.at) m4_include(tests/t_restriction_with_exclude.at) +m4_include(tests/t_genkey_without_db.at)