aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-10 16:11:32 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-10 16:11:32 +0000
commitc209fbf6e9d7d0a9f685893ccf6598b92f586a2a (patch)
tree5b9979bf4bc2b88d14de62295fc672b7c8ac22a9
parent03c0c96010a94747b774def37aaed903ed21d5b9 (diff)
downloadgnunet-gtk-c209fbf6e9d7d0a9f685893ccf6598b92f586a2a.tar.gz
gnunet-gtk-c209fbf6e9d7d0a9f685893ccf6598b92f586a2a.zip
-fix #2683 --- check record type combinations are allowed
-rw-r--r--src/setup/gnunet-setup-gns.c105
1 files changed, 104 insertions, 1 deletions
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index a08033ee..fcabc7d9 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -572,6 +572,60 @@ GNUNET_setup_gns_qr_saveas_button_clicked_cb (GtkButton *button,
572 572
573 573
574/** 574/**
575 * Check if adding a record of the given type is Ok given the other
576 * records already present for the given name.
577 *
578 * @param rd_count size of the 'rd' array
579 * @param rd existing records
580 * @param n_type new record to be added
581 * @return GNUNET_OK if adding this record is OK, GNUNET_NO if not
582 */
583static int
584check_record_permitted (unsigned int rd_count,
585 const struct GNUNET_NAMESTORE_RecordData *rd,
586 gint n_type)
587{
588 unsigned int i;
589
590 for (i=0;i<rd_count;i++)
591 {
592 switch (rd[i].record_type)
593 {
594 case GNUNET_DNSPARSER_TYPE_CNAME:
595 return GNUNET_NO;
596 case GNUNET_DNSPARSER_TYPE_NS:
597 if ( (GNUNET_DNSPARSER_TYPE_A == n_type) ||
598 (GNUNET_DNSPARSER_TYPE_AAAA == n_type) )
599 return GNUNET_OK;
600 return GNUNET_NO;
601 case GNUNET_NAMESTORE_TYPE_PKEY:
602 return GNUNET_NO;
603 default:
604 break;
605 }
606 }
607 if (0 == rd_count)
608 return GNUNET_OK;
609 switch (n_type)
610 {
611 case GNUNET_DNSPARSER_TYPE_CNAME:
612 return GNUNET_NO;
613 case GNUNET_DNSPARSER_TYPE_NS:
614 for (i=0;i<rd_count;i++)
615 if ( (GNUNET_DNSPARSER_TYPE_A != rd[i].record_type) &&
616 (GNUNET_DNSPARSER_TYPE_AAAA != rd[i].record_type) )
617 return GNUNET_NO;
618 return GNUNET_OK;
619 case GNUNET_NAMESTORE_TYPE_PKEY:
620 return GNUNET_NO;
621 default:
622 break;
623 }
624 return GNUNET_OK;
625}
626
627
628/**
575 * Function called upon completion of an operation. 629 * Function called upon completion of an operation.
576 * 630 *
577 * @param cls the 'struct OperationContext' of the operation that completed 631 * @param cls the 'struct OperationContext' of the operation that completed
@@ -740,6 +794,19 @@ merge_with_existing_records (void *cls,
740 struct OperationContext *oc; 794 struct OperationContext *oc;
741 795
742 GNUNET_CONTAINER_DLL_remove (moc_head, moc_tail, moc); 796 GNUNET_CONTAINER_DLL_remove (moc_head, moc_tail, moc);
797 if (GNUNET_OK !=
798 check_record_permitted (rd_count, rd,
799 edc->record_type))
800 {
801 show_error_message (_("Record combination not permitted"),
802 _("Given the existing records, adding a new record of this type is not allowed."));
803 GNUNET_CRYPTO_ecc_key_free (moc->pk);
804 GNUNET_free (moc->data);
805 GNUNET_free (moc);
806 free_edit_dialog_context (edc);
807 return;
808 }
809
743 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); 810 memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
744 rd_new[rd_count] = moc->rd; 811 rd_new[rd_count] = moc->rd;
745 /* FIXME: sanity-check merge... */ 812 /* FIXME: sanity-check merge... */
@@ -1047,6 +1114,40 @@ launch_edit_dialog (gint n_type,
1047 1114
1048 1115
1049/** 1116/**
1117 * Check if, with the given record info, we are allowed to add
1118 * another record of the given type.
1119 *
1120 * @param ri existing records
1121 * @param n_type type of the new record
1122 * @return GNUNET_OK if this is allowed
1123 */
1124static int
1125check_permissions (struct RecordInfo *ri,
1126 guint n_type)
1127{
1128 struct GNUNET_NAMESTORE_RecordData rd[ri->rd_count];
1129
1130 GNUNET_break (GNUNET_OK ==
1131 GNUNET_NAMESTORE_records_deserialize (ri->data_size,
1132 ri->data,
1133 ri->rd_count,
1134 rd));
1135 if (GNUNET_OK !=
1136 check_record_permitted (ri->rd_count,
1137 rd,
1138 n_type))
1139 {
1140 show_error_message (_("Record combination not permitted"),
1141 _("Given the existing records, adding a new record of this type is not allowed.\n"
1142 "CNAME and PKEY records cannot co-exist with other records.\n"
1143 "NS records in GADS can only co-exist with A and AAAA records.\n"));
1144 return GNUNET_NO;
1145 }
1146 return GNUNET_OK;
1147}
1148
1149
1150/**
1050 * User selected 'edit' in the popup menu. Edit the 1151 * User selected 'edit' in the popup menu. Edit the
1051 * selected row. 1152 * selected row.
1052 * 1153 *
@@ -1088,6 +1189,7 @@ GNUNET_setup_gns_popup_edit_button_activate_cb (GtkWidget *widget,
1088 (off >= ri->rd_count) ) 1189 (off >= ri->rd_count) )
1089 { 1190 {
1090 GNUNET_break (0); 1191 GNUNET_break (0);
1192 g_free (n_name);
1091 return; 1193 return;
1092 } 1194 }
1093 launch_edit_dialog (n_type, n_name, 1195 launch_edit_dialog (n_type, n_name,
@@ -1154,7 +1256,8 @@ GNUNET_setup_gns_type_cellrenderercombo_changed_cb (GtkCellRendererCombo *combo,
1154 } 1256 }
1155 GNUNET_CRYPTO_hash (name_str, strlen (name_str), &name_hash); 1257 GNUNET_CRYPTO_hash (name_str, strlen (name_str), &name_hash);
1156 ri = GNUNET_CONTAINER_multihashmap_get (n2r, &name_hash); 1258 ri = GNUNET_CONTAINER_multihashmap_get (n2r, &name_hash);
1157 launch_edit_dialog (type, name_str, ri, UINT_MAX); 1259 if (GNUNET_OK == check_permissions (ri, type))
1260 launch_edit_dialog (type, name_str, ri, UINT_MAX);
1158 g_free (name_str); 1261 g_free (name_str);
1159 g_free (new_text); 1262 g_free (new_text);
1160} 1263}