summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2018-11-01 15:37:42 +0100
committerDaiki Ueno <dueno@redhat.com>2018-11-12 14:08:45 +0100
commit8ada9c280c9044644dfad1f234e3da32f0df86a0 (patch)
treef60f3a15e2d40fe02c27e5487a32a697bdb6ca34
parent0a590e15e17383c5b18650465266da5f4cfd2af1 (diff)
downloadgnutls-8ada9c280c9044644dfad1f234e3da32f0df86a0.tar.gz
db: introduce gnutls_db_set_add_function
This adds a way to store an entry if it is not found in the database, so that the implementation can provide atomic test-and-set. Signed-off-by: Daiki Ueno <dueno@redhat.com>
-rw-r--r--doc/Makefile.am2
-rw-r--r--doc/cha-gtls-app.texi2
-rw-r--r--doc/manpages/Makefile.am1
-rw-r--r--lib/db.c23
-rw-r--r--lib/errors.c1
-rw-r--r--lib/gnutls_int.h1
-rw-r--r--lib/includes/gnutls/gnutls.h.in5
-rw-r--r--lib/libgnutls.map1
-rw-r--r--symbols.last1
9 files changed, 36 insertions, 1 deletions
diff --git a/doc/Makefile.am b/doc/Makefile.am
index bac1e5825c..64095e9b60 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -887,6 +887,8 @@ FUNCS += functions/gnutls_db_get_ptr
FUNCS += functions/gnutls_db_get_ptr.short
FUNCS += functions/gnutls_db_remove_session
FUNCS += functions/gnutls_db_remove_session.short
+FUNCS += functions/gnutls_db_set_add_function
+FUNCS += functions/gnutls_db_set_add_function.short
FUNCS += functions/gnutls_db_set_cache_expiration
FUNCS += functions/gnutls_db_set_cache_expiration.short
FUNCS += functions/gnutls_db_set_ptr
diff --git a/doc/cha-gtls-app.texi b/doc/cha-gtls-app.texi
index 64c662ce00..90accd3d31 100644
--- a/doc/cha-gtls-app.texi
+++ b/doc/cha-gtls-app.texi
@@ -1708,7 +1708,7 @@ A storing server needs to specify callback functions to store, retrieve and dele
registered with the functions below. The stored sessions in the database can be checked using @funcref{gnutls_db_check_entry}
for expiration.
-@showfuncD{gnutls_db_set_retrieve_function,gnutls_db_set_store_function,gnutls_db_set_ptr,gnutls_db_set_remove_function}
+@showfuncE{gnutls_db_set_retrieve_function,gnutls_db_set_store_function,gnutls_db_set_ptr,gnutls_db_set_remove_function,gnutls_db_set_add_function}
@showfuncA{gnutls_db_check_entry}
A server supporting session tickets must generate ticket encryption
diff --git a/doc/manpages/Makefile.am b/doc/manpages/Makefile.am
index 8a6025ccaa..7edbc45400 100644
--- a/doc/manpages/Makefile.am
+++ b/doc/manpages/Makefile.am
@@ -245,6 +245,7 @@ APIMANS += gnutls_db_check_entry_time.3
APIMANS += gnutls_db_get_default_cache_expiration.3
APIMANS += gnutls_db_get_ptr.3
APIMANS += gnutls_db_remove_session.3
+APIMANS += gnutls_db_set_add_function.3
APIMANS += gnutls_db_set_cache_expiration.3
APIMANS += gnutls_db_set_ptr.3
APIMANS += gnutls_db_set_remove_function.3
diff --git a/lib/db.c b/lib/db.c
index e01e5b94c5..414816fcc8 100644
--- a/lib/db.c
+++ b/lib/db.c
@@ -56,6 +56,29 @@ gnutls_db_set_retrieve_function(gnutls_session_t session,
}
/**
+ * gnutls_db_set_add_function:
+ * @session: is a #gnutls_session_t type.
+ * @add_func: is the function.
+ *
+ * Sets the function that will be used to store an entry if it is not
+ * already present in the resumed sessions database. This function returns 0
+ * if the entry is successfully stored, and a negative error code
+ * otherwise. In particular, if the entry is found in the database,
+ * it returns %GNUTLS_E_DB_ENTRY_EXISTS.
+ *
+ * The first argument to @add_func will be null unless
+ * gnutls_db_set_ptr() has been called.
+ *
+ * Since: 3.6.5
+ **/
+void
+gnutls_db_set_add_function(gnutls_session_t session,
+ gnutls_db_add_func add_func)
+{
+ session->internals.db_add_func = add_func;
+}
+
+/**
* gnutls_db_set_remove_function:
* @session: is a #gnutls_session_t type.
* @rem_func: is the function.
diff --git a/lib/errors.c b/lib/errors.c
index e579f46852..a83a49eeab 100644
--- a/lib/errors.c
+++ b/lib/errors.c
@@ -193,6 +193,7 @@ static const gnutls_error_entry error_entries[] = {
("TLS Application data were received, while expecting handshake data."),
GNUTLS_E_GOT_APPLICATION_DATA),
ERROR_ENTRY(N_("Error in Database backend."), GNUTLS_E_DB_ERROR),
+ ERROR_ENTRY(N_("The Database entry already exists."), GNUTLS_E_DB_ENTRY_EXISTS),
ERROR_ENTRY(N_("The certificate type is not supported."),
GNUTLS_E_UNSUPPORTED_CERTIFICATE_TYPE),
ERROR_ENTRY(N_
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index 73fcfcc9c8..42d68d4398 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -1216,6 +1216,7 @@ typedef struct {
gnutls_db_store_func db_store_func;
gnutls_db_retr_func db_retrieve_func;
gnutls_db_remove_func db_remove_func;
+ gnutls_db_add_func db_add_func;
void *db_ptr;
/* post client hello callback (server side only)
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 1c07ff33a5..3a4d01d442 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1783,6 +1783,8 @@ typedef int (*gnutls_db_store_func) (void *, gnutls_datum_t key,
gnutls_datum_t data);
typedef int (*gnutls_db_remove_func) (void *, gnutls_datum_t key);
typedef gnutls_datum_t(*gnutls_db_retr_func) (void *, gnutls_datum_t key);
+typedef int (*gnutls_db_add_func) (void *, gnutls_datum_t key,
+ gnutls_datum_t data);
void gnutls_db_set_cache_expiration(gnutls_session_t session, int seconds);
unsigned gnutls_db_get_default_cache_expiration(void);
@@ -1794,6 +1796,8 @@ void gnutls_db_set_remove_function(gnutls_session_t session,
gnutls_db_remove_func rem_func);
void gnutls_db_set_store_function(gnutls_session_t session,
gnutls_db_store_func store_func);
+void gnutls_db_set_add_function(gnutls_session_t session,
+ gnutls_db_add_func add_func);
void gnutls_db_set_ptr(gnutls_session_t session, void *ptr);
void *gnutls_db_get_ptr(gnutls_session_t session);
int gnutls_db_check_entry(gnutls_session_t session,
@@ -3265,6 +3269,7 @@ void gnutls_fips140_set_mode(gnutls_fips_mode_t mode, unsigned flags);
#define GNUTLS_E_TOO_MANY_MATCHES -425
#define GNUTLS_E_CRL_VERIFICATION_ERROR -426
#define GNUTLS_E_MISSING_EXTENSION -427
+#define GNUTLS_E_DB_ENTRY_EXISTS -428
#define GNUTLS_E_UNIMPLEMENTED_FEATURE -1250
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index cfa87a6b26..a4aaf11ca1 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -1255,6 +1255,7 @@ GNUTLS_3_6_5
gnutls_record_send_early_data;
gnutls_record_recv_early_data;
gnutls_db_check_entry_expire_time;
+ gnutls_db_set_add_function;
} GNUTLS_3_6_4;
GNUTLS_FIPS140_3_4 {
diff --git a/symbols.last b/symbols.last
index f966ae1a42..1cb4050933 100644
--- a/symbols.last
+++ b/symbols.last
@@ -142,6 +142,7 @@ gnutls_db_check_entry_time@GNUTLS_3_4
gnutls_db_get_default_cache_expiration@GNUTLS_3_4
gnutls_db_get_ptr@GNUTLS_3_4
gnutls_db_remove_session@GNUTLS_3_4
+gnutls_db_set_add_function@GNUTLS_3_6_5
gnutls_db_set_cache_expiration@GNUTLS_3_4
gnutls_db_set_ptr@GNUTLS_3_4
gnutls_db_set_remove_function@GNUTLS_3_4