aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_namestore_sqlite.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-08 18:41:07 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-08 18:41:07 +0000
commit2168e300fae74c5da28a2f3f57d67b7705f038a2 (patch)
tree2fec4a8a42292f9feff2481c85db50df3638f94d /src/namestore/plugin_namestore_sqlite.c
parentd9e144b09a47db8e72cbf85390df298421451322 (diff)
downloadgnunet-2168e300fae74c5da28a2f3f57d67b7705f038a2.tar.gz
gnunet-2168e300fae74c5da28a2f3f57d67b7705f038a2.zip
fixing #2992: do not use hash of pkey and then match against pkey, that will not work...
Diffstat (limited to 'src/namestore/plugin_namestore_sqlite.c')
-rw-r--r--src/namestore/plugin_namestore_sqlite.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c
index 1acb5aff2..bd32e3fd1 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -158,7 +158,7 @@ create_indices (sqlite3 * dbh)
158 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_block_expiration ON ns096blocks (expiration_time)", 158 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_block_expiration ON ns096blocks (expiration_time)",
159 NULL, NULL, NULL)) || 159 NULL, NULL, NULL)) ||
160 (SQLITE_OK != 160 (SQLITE_OK !=
161 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_reverse ON ns096records (zone_private_key,pkey_hash)", 161 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_reverse ON ns096records (zone_private_key,pkey)",
162 NULL, NULL, NULL)) || 162 NULL, NULL, NULL)) ||
163 (SQLITE_OK != 163 (SQLITE_OK !=
164 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON ns096records (zone_private_key,rvalue)", 164 sqlite3_exec (dbh, "CREATE INDEX IF NOT EXISTS ir_pkey_iter ON ns096records (zone_private_key,rvalue)",
@@ -284,7 +284,7 @@ database_setup (struct Plugin *plugin)
284 (plugin->dbh, 284 (plugin->dbh,
285 "CREATE TABLE ns096records (" 285 "CREATE TABLE ns096records ("
286 " zone_private_key BLOB NOT NULL DEFAULT ''," 286 " zone_private_key BLOB NOT NULL DEFAULT '',"
287 " pkey_hash BLOB," 287 " pkey BLOB,"
288 " rvalue INT8 NOT NULL DEFAULT ''," 288 " rvalue INT8 NOT NULL DEFAULT '',"
289 " record_count INT NOT NULL DEFAULT 0," 289 " record_count INT NOT NULL DEFAULT 0,"
290 " record_data BLOB NOT NULL DEFAULT ''," 290 " record_data BLOB NOT NULL DEFAULT '',"
@@ -318,7 +318,7 @@ database_setup (struct Plugin *plugin)
318 &plugin->lookup_block) != SQLITE_OK) || 318 &plugin->lookup_block) != SQLITE_OK) ||
319 (sq_prepare 319 (sq_prepare
320 (plugin->dbh, 320 (plugin->dbh,
321 "INSERT INTO ns096records (zone_private_key, pkey_hash, rvalue, record_count, record_data, label)" 321 "INSERT INTO ns096records (zone_private_key, pkey, rvalue, record_count, record_data, label)"
322 " VALUES (?, ?, ?, ?, ?, ?)", 322 " VALUES (?, ?, ?, ?, ?, ?)",
323 &plugin->store_records) != SQLITE_OK) || 323 &plugin->store_records) != SQLITE_OK) ||
324 (sq_prepare 324 (sq_prepare
@@ -328,7 +328,7 @@ database_setup (struct Plugin *plugin)
328 (sq_prepare 328 (sq_prepare
329 (plugin->dbh, 329 (plugin->dbh,
330 "SELECT record_count,record_data,label" 330 "SELECT record_count,record_data,label"
331 " FROM ns096records WHERE zone_private_key=? AND pkey_hash=?", 331 " FROM ns096records WHERE zone_private_key=? AND pkey=?",
332 &plugin->zone_to_name) != SQLITE_OK) || 332 &plugin->zone_to_name) != SQLITE_OK) ||
333 (sq_prepare 333 (sq_prepare
334 (plugin->dbh, 334 (plugin->dbh,
@@ -663,19 +663,19 @@ namestore_sqlite_store_records (void *cls,
663{ 663{
664 struct Plugin *plugin = cls; 664 struct Plugin *plugin = cls;
665 int n; 665 int n;
666 struct GNUNET_HashCode pkey_hash; 666 struct GNUNET_CRYPTO_EccPublicSignKey pkey;
667 uint64_t rvalue; 667 uint64_t rvalue;
668 size_t data_size; 668 size_t data_size;
669 unsigned int i; 669 unsigned int i;
670 670
671 memset (&pkey_hash, 0, sizeof (pkey_hash)); 671 memset (&pkey, 0, sizeof (pkey));
672 for (i=0;i<rd_count;i++) 672 for (i=0;i<rd_count;i++)
673 if (GNUNET_NAMESTORE_TYPE_PKEY == rd[i].record_type) 673 if (GNUNET_NAMESTORE_TYPE_PKEY == rd[i].record_type)
674 { 674 {
675 GNUNET_break (sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) == rd[i].data_size); 675 GNUNET_break (sizeof (struct GNUNET_CRYPTO_EccPublicSignKey) == rd[i].data_size);
676 GNUNET_CRYPTO_hash (rd[i].data, 676 memcpy (&pkey,
677 rd[i].data_size, 677 rd[i].data,
678 &pkey_hash); 678 rd[i].data_size);
679 break; 679 break;
680 } 680 }
681 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 681 rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
@@ -720,7 +720,7 @@ namestore_sqlite_store_records (void *cls,
720 if ((SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 1, 720 if ((SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 1,
721 zone_key, sizeof (struct GNUNET_CRYPTO_EccPrivateKey), SQLITE_STATIC)) || 721 zone_key, sizeof (struct GNUNET_CRYPTO_EccPrivateKey), SQLITE_STATIC)) ||
722 (SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 2, 722 (SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 2,
723 &pkey_hash, sizeof (struct GNUNET_HashCode), SQLITE_STATIC)) || 723 &pkey, sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), SQLITE_STATIC)) ||
724 (SQLITE_OK != sqlite3_bind_int64 (plugin->store_records, 3, rvalue)) || 724 (SQLITE_OK != sqlite3_bind_int64 (plugin->store_records, 3, rvalue)) ||
725 (SQLITE_OK != sqlite3_bind_int (plugin->store_records, 4, rd_count)) || 725 (SQLITE_OK != sqlite3_bind_int (plugin->store_records, 4, rd_count)) ||
726 (SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 5, data, data_size, SQLITE_STATIC)) || 726 (SQLITE_OK != sqlite3_bind_blob (plugin->store_records, 5, data, data_size, SQLITE_STATIC)) ||
@@ -733,7 +733,7 @@ namestore_sqlite_store_records (void *cls,
733 LOG_SQLITE (plugin, 733 LOG_SQLITE (plugin,
734 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 734 GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
735 "sqlite3_reset"); 735 "sqlite3_reset");
736 return GNUNET_SYSERR; 736 return GNUNET_SYSERR;
737 } 737 }
738 n = sqlite3_step (plugin->store_records); 738 n = sqlite3_step (plugin->store_records);
739 if (SQLITE_OK != sqlite3_reset (plugin->store_records)) 739 if (SQLITE_OK != sqlite3_reset (plugin->store_records))
@@ -775,7 +775,7 @@ namestore_sqlite_store_records (void *cls,
775 */ 775 */
776static int 776static int
777get_record_and_call_iterator (struct Plugin *plugin, 777get_record_and_call_iterator (struct Plugin *plugin,
778 sqlite3_stmt *stmt, 778 sqlite3_stmt *stmt,
779 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key, 779 const struct GNUNET_CRYPTO_EccPrivateKey *zone_key,
780 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls) 780 GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls)
781{ 781{
@@ -932,6 +932,10 @@ namestore_sqlite_zone_to_name (void *cls,
932 "sqlite3_reset"); 932 "sqlite3_reset");
933 return GNUNET_SYSERR; 933 return GNUNET_SYSERR;
934 } 934 }
935 LOG (GNUNET_ERROR_TYPE_DEBUG,
936 "Performing reverse lookup for `%s'\n",
937 GNUNET_NAMESTORE_z2s (value_zone));
938
935 return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls); 939 return get_record_and_call_iterator (plugin, stmt, zone, iter, iter_cls);
936} 940}
937 941