# # # patch "database.cc" # from [95b2352645a231b30b7b923b7798ed0143f8c2f8] # to [6ad21a6454947a4835eec90e721ba97fdef60d22] # # patch "schema_migration.cc" # from [a7f3cafb70434de167246e8220450f74e23f3b90] # to [15368db7cd5386e1692a494d651cffc4620028b0] # ============================================================ --- database.cc 95b2352645a231b30b7b923b7798ed0143f8c2f8 +++ database.cc 6ad21a6454947a4835eec90e721ba97fdef60d22 @@ -1464,10 +1464,7 @@ "SELECT data FROM revisions WHERE id = ?", id.inner()().c_str()); - base64 > rdat_packed; - rdat_packed = base64 >(res[0][0]); - data rdat; - unpack(rdat_packed, rdat); + data rdat(res[0][0]); // verify that we got a revision with the right id { @@ -1557,13 +1554,11 @@ // Phase 3: Write the revision data - base64 > d_packed; - pack(d.inner(), d_packed); + std::vector args; + args.push_back(new_id.inner()()); + args.push_back(queryarg(d.inner()(),true)); + execute("INSERT INTO revisions VALUES(?, ?)", args); - execute("INSERT INTO revisions VALUES(?, ?)", - new_id.inner()().c_str(), - d_packed().c_str()); - for (edge_map::const_iterator e = rev.edges.begin(); e != rev.edges.end(); ++e) { @@ -1748,7 +1743,7 @@ "SELECT id, keydata FROM public_keys WHERE hash = ?", hash().c_str()); id = res[0][0]; - pub_encoded = res[0][1]; + encode_base64(res[0][1], pub_encoded); } void @@ -1759,7 +1754,7 @@ fetch(res, one_col, one_row, "SELECT keydata FROM public_keys WHERE id = ?", pub_id().c_str()); - pub_encoded = res[0][0]; + encode_base64(res[0][0], pub_encoded); } void @@ -1771,8 +1766,13 @@ I(!public_key_exists(thash)); E(!public_key_exists(pub_id), F("another key with name '%s' already exists") % pub_id); - execute("INSERT INTO public_keys VALUES(?, ?, ?)", - thash().c_str(), pub_id().c_str(), pub_encoded().c_str()); + rsa_pub_key pub_key; + decode_base64(pub_encoded, pub_key); + std::vector args; + args.push_back(thash()); + args.push_back(pub_id()); + args.push_back(queryarg(pub_key(),true)); + execute("INSERT INTO public_keys VALUES(?, ?, ?)", args); } void @@ -1795,13 +1795,18 @@ "AND value = ? " "AND keypair = ? " "AND signature = ?"; - - fetch(res, 1, any_rows, query.c_str(), - t.ident().c_str(), - t.name().c_str(), - t.value().c_str(), - t.key().c_str(), - t.sig().c_str()); + std::vector args; + args.push_back(t.ident()); + args.push_back(t.name()); + cert_value value; + decode_base64(t.value, value); + args.push_back(queryarg(value(),true)); + args.push_back(t.key()); + rsa_sha1_signature sig; + decode_base64(t.sig, sig); + args.push_back(queryarg(sig(),true)); + + fetch(res, 1, any_rows, query, args); I(res.size() == 0 || res.size() == 1); return res.size() == 1; } @@ -1810,18 +1815,22 @@ database::put_cert(cert const & t, string const & table) { + std::vector args; hexenc thash; cert_hash_code(t, thash); + args.push_back(thash()); + args.push_back(t.ident()); + args.push_back(t.name()); + cert_value value; + decode_base64(t.value, value); + args.push_back(queryarg(value(),true)); + args.push_back(t.key()); + rsa_sha1_signature sig; + decode_base64(t.sig, sig); + args.push_back(queryarg(sig(),true)); string insert = "INSERT INTO " + table + " VALUES(?, ?, ?, ?, ?, ?)"; - - execute(insert.c_str(), - thash().c_str(), - t.ident().c_str(), - t.name().c_str(), - t.value().c_str(), - t.key().c_str(), - t.sig().c_str()); + execute(insert, args); } void @@ -1832,11 +1841,15 @@ for (size_t i = 0; i < res.size(); ++i) { cert t; + base64 value; + encode_base64(cert_value(res[i][2]), value); + base64 sig; + encode_base64(rsa_sha1_signature(res[i][4]), sig); t = cert(hexenc(res[i][0]), cert_name(res[i][1]), - base64(res[i][2]), + value, rsa_keypair_id(res[i][3]), - base64(res[i][4])); + sig); certs.push_back(t); } } @@ -1962,10 +1975,13 @@ "SELECT id, name, value, keypair, signature FROM " + table + " WHERE id = ? AND name = ? AND value = ?"; - fetch(res, 5, any_rows, query.c_str(), - ident().c_str(), - name().c_str(), - value().c_str()); + std::vector args; + args.push_back(ident()); + args.push_back(name()); + cert_value binvalue; + decode_base64(value, binvalue); + args.push_back(queryarg(binvalue(),true)); + fetch(res, 5, any_rows, query, args); results_to_certs(res, certs); } @@ -2519,12 +2535,8 @@ for (results::const_iterator i = res.begin(); i != res.end(); ++i) { var_domain domain(idx(*i, 0)); - base64 name_encoded(idx(*i, 1)); - var_name name; - decode_base64(name_encoded, name); - base64 value_encoded(idx(*i, 2)); - var_value value; - decode_base64(value_encoded, value); + var_name name(idx(*i, 1)); + var_value value(idx(*i, 2)); I(vars.find(std::make_pair(domain, name)) == vars.end()); vars.insert(std::make_pair(std::make_pair(domain, name), value)); } @@ -2554,23 +2566,20 @@ void database::set_var(var_key const & key, var_value const & value) { - base64 name_encoded; - encode_base64(key.second, name_encoded); - base64 value_encoded; - encode_base64(value, value_encoded); - execute("INSERT OR REPLACE INTO db_vars VALUES(?, ?, ?)", - key.first().c_str(), - name_encoded().c_str(), - value_encoded().c_str()); + std::vector args; + args.push_back(key.first()); + args.push_back(queryarg(key.second(),true)); + args.push_back(queryarg(value(),true)); + execute("INSERT OR REPLACE INTO db_vars VALUES(?, ?, ?)", args); } void database::clear_var(var_key const & key) { - base64 name_encoded; - encode_base64(key.second, name_encoded); - execute("DELETE FROM db_vars WHERE domain = ? AND name = ?", - key.first().c_str(), name_encoded().c_str()); + std::vector args; + args.push_back(key.first()); + args.push_back(queryarg(key.second(),true)); + execute("DELETE FROM db_vars WHERE domain = ? AND name = ?", args); } // branches ============================================================ --- schema_migration.cc a7f3cafb70434de167246e8220450f74e23f3b90 +++ schema_migration.cc 15368db7cd5386e1692a494d651cffc4620028b0 @@ -1014,7 +1014,8 @@ if (res != SQLITE_OK) return false; - res = logged_sqlite3_exec(sql, "UPDATE db_vars SET value=unbase64(value)", NULL, NULL, errmsg); + res = logged_sqlite3_exec(sql, "UPDATE db_vars " + "SET value=unbase64(value),name=unbase64(name)", NULL, NULL, errmsg); if (res != SQLITE_OK) return false; res = logged_sqlite3_exec(sql, "UPDATE public_keys "