#include <c-ctype.h>
#include <extensions.h>
#include "fips.h"
+#include "errno.h"
#define MAX_ELEMENTS 64
static const char *system_priority_file = SYSTEM_PRIORITY_FILE;
static char *system_priority_buf = NULL;
static size_t system_priority_buf_size = 0;
+static time_t system_priority_last_mod = 0;
-void _gnutls_load_system_priorities(void)
+
+static void _gnutls_update_system_priorities(void)
{
+#ifdef HAVE_FMEMOPEN
gnutls_datum_t data;
- const char *p;
int ret;
+ struct stat sb;
- p = secure_getenv("GNUTLS_SYSTEM_PRIORITY_FILE");
- if (p != NULL)
- system_priority_file = p;
+ if (stat(system_priority_file, &sb) < 0) {
+ _gnutls_debug_log("unable to access: %s: %d\n",
+ system_priority_file, errno);
+ return;
+ }
+
+ if (sb.st_mtime == system_priority_last_mod) {
+ _gnutls_debug_log("system priority %s has not changed\n",
+ system_priority_file);
+ return;
+ }
-#ifdef HAVE_FMEMOPEN
ret = gnutls_load_file(system_priority_file, &data);
- if (ret < 0)
+ if (ret < 0) {
+ _gnutls_debug_log("unable to load: %s: %d\n",
+ system_priority_file, ret);
return;
+ }
+ _gnutls_debug_log("cached system priority %s mtime %lld\n",
+ system_priority_file,
+ (unsigned long long)sb.st_mtime);
+ gnutls_free(system_priority_buf);
system_priority_buf = (char*)data.data;
system_priority_buf_size = data.size;
+ system_priority_last_mod = sb.st_mtime;
#endif
- return;
+}
+
+void _gnutls_load_system_priorities(void)
+{
+ const char *p;
+
+ p = secure_getenv("GNUTLS_SYSTEM_PRIORITY_FILE");
+ if (p != NULL)
+ system_priority_file = p;
+
+ _gnutls_update_system_priorities();
}
void _gnutls_unload_system_priorities(void)
#endif
system_priority_buf = NULL;
system_priority_buf_size = 0;
+ system_priority_last_mod = 0;
}
/* Returns the new priorities if SYSTEM is specified in
}
#ifdef HAVE_FMEMOPEN
+ /* Always try to refresh the cached data, to
+ * allow it to be updated without restarting
+ * all applications
+ */
+ _gnutls_update_system_priorities();
fp = fmemopen(system_priority_buf, system_priority_buf_size, "r");
+#else
+ fp = fopen(system_priority_file, "r");
#endif
- if (fp == NULL)
- fp = fopen(system_priority_file, "r");
if (fp == NULL) {/* fail */
ret = NULL;
goto finish;