[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27894 - gnunet-gtk/src/setup
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27894 - gnunet-gtk/src/setup |
Date: |
Wed, 10 Jul 2013 18:11:32 +0200 |
Author: grothoff
Date: 2013-07-10 18:11:32 +0200 (Wed, 10 Jul 2013)
New Revision: 27894
Modified:
gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-fix #2683 --- check record type combinations are allowed
Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c 2013-07-10 15:53:47 UTC (rev
27893)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c 2013-07-10 16:11:32 UTC (rev
27894)
@@ -572,6 +572,60 @@
/**
+ * Check if adding a record of the given type is Ok given the other
+ * records already present for the given name.
+ *
+ * @param rd_count size of the 'rd' array
+ * @param rd existing records
+ * @param n_type new record to be added
+ * @return GNUNET_OK if adding this record is OK, GNUNET_NO if not
+ */
+static int
+check_record_permitted (unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ gint n_type)
+{
+ unsigned int i;
+
+ for (i=0;i<rd_count;i++)
+ {
+ switch (rd[i].record_type)
+ {
+ case GNUNET_DNSPARSER_TYPE_CNAME:
+ return GNUNET_NO;
+ case GNUNET_DNSPARSER_TYPE_NS:
+ if ( (GNUNET_DNSPARSER_TYPE_A == n_type) ||
+ (GNUNET_DNSPARSER_TYPE_AAAA == n_type) )
+ return GNUNET_OK;
+ return GNUNET_NO;
+ case GNUNET_NAMESTORE_TYPE_PKEY:
+ return GNUNET_NO;
+ default:
+ break;
+ }
+ }
+ if (0 == rd_count)
+ return GNUNET_OK;
+ switch (n_type)
+ {
+ case GNUNET_DNSPARSER_TYPE_CNAME:
+ return GNUNET_NO;
+ case GNUNET_DNSPARSER_TYPE_NS:
+ for (i=0;i<rd_count;i++)
+ if ( (GNUNET_DNSPARSER_TYPE_A != rd[i].record_type) &&
+ (GNUNET_DNSPARSER_TYPE_AAAA != rd[i].record_type) )
+ return GNUNET_NO;
+ return GNUNET_OK;
+ case GNUNET_NAMESTORE_TYPE_PKEY:
+ return GNUNET_NO;
+ default:
+ break;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* Function called upon completion of an operation.
*
* @param cls the 'struct OperationContext' of the operation that completed
@@ -740,6 +794,19 @@
struct OperationContext *oc;
GNUNET_CONTAINER_DLL_remove (moc_head, moc_tail, moc);
+ if (GNUNET_OK !=
+ check_record_permitted (rd_count, rd,
+ edc->record_type))
+ {
+ show_error_message (_("Record combination not permitted"),
+ _("Given the existing records, adding a new record of
this type is not allowed."));
+ GNUNET_CRYPTO_ecc_key_free (moc->pk);
+ GNUNET_free (moc->data);
+ GNUNET_free (moc);
+ free_edit_dialog_context (edc);
+ return;
+ }
+
memcpy (rd_new, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
rd_new[rd_count] = moc->rd;
/* FIXME: sanity-check merge... */
@@ -1047,6 +1114,40 @@
/**
+ * Check if, with the given record info, we are allowed to add
+ * another record of the given type.
+ *
+ * @param ri existing records
+ * @param n_type type of the new record
+ * @return GNUNET_OK if this is allowed
+ */
+static int
+check_permissions (struct RecordInfo *ri,
+ guint n_type)
+{
+ struct GNUNET_NAMESTORE_RecordData rd[ri->rd_count];
+
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_NAMESTORE_records_deserialize (ri->data_size,
+ ri->data,
+ ri->rd_count,
+ rd));
+ if (GNUNET_OK !=
+ check_record_permitted (ri->rd_count,
+ rd,
+ n_type))
+ {
+ show_error_message (_("Record combination not permitted"),
+ _("Given the existing records, adding a new record of
this type is not allowed.\n"
+ "CNAME and PKEY records cannot co-exist with other
records.\n"
+ "NS records in GADS can only co-exist with A and AAAA
records.\n"));
+ return GNUNET_NO;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* User selected 'edit' in the popup menu. Edit the
* selected row.
*
@@ -1088,6 +1189,7 @@
(off >= ri->rd_count) )
{
GNUNET_break (0);
+ g_free (n_name);
return;
}
launch_edit_dialog (n_type, n_name,
@@ -1154,7 +1256,8 @@
}
GNUNET_CRYPTO_hash (name_str, strlen (name_str), &name_hash);
ri = GNUNET_CONTAINER_multihashmap_get (n2r, &name_hash);
- launch_edit_dialog (type, name_str, ri, UINT_MAX);
+ if (GNUNET_OK == check_permissions (ri, type))
+ launch_edit_dialog (type, name_str, ri, UINT_MAX);
g_free (name_str);
g_free (new_text);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27894 - gnunet-gtk/src/setup,
gnunet <=