Blame SOURCES/vim-crypto-warning.patch

acc9da
diff --git a/src/config.h.in b/src/config.h.in
acc9da
index 7d61220..ca0b1a8 100644
acc9da
--- a/src/config.h.in
acc9da
+++ b/src/config.h.in
acc9da
@@ -478,3 +478,12 @@
acc9da
 
acc9da
 /* Define to inline symbol or empty */
acc9da
 #undef inline
acc9da
+
acc9da
+/* Do we need FIPS warning? */
acc9da
+#undef HAVE_FIPS_WARNING
acc9da
+
acc9da
+/* Link to system-fips file */
acc9da
+#undef SYSTEM_FIPS_FILE_LINK
acc9da
+
acc9da
+/* Link to fips_enabled file */
acc9da
+#undef FIPS_ENABLED_FILE_LINK
acc9da
diff --git a/src/configure.ac b/src/configure.ac
acc9da
index 1e7d444..5e45762 100644
acc9da
--- a/src/configure.ac
acc9da
+++ b/src/configure.ac
acc9da
@@ -525,6 +525,38 @@ else
acc9da
   AC_MSG_RESULT(yes)
acc9da
 fi
acc9da
 
acc9da
+dnl Checking if we want FIPS warning
acc9da
+
acc9da
+AC_MSG_CHECKING(--enable-fips-warning)
acc9da
+AC_ARG_ENABLE([fips-warning],
acc9da
+              AS_HELP_STRING([--enable-fips-warning], [Enable FIPS warning]),
acc9da
+              ,[enable_fips_warning="no"])
acc9da
+
acc9da
+if test "$enable_fips_warning" = "yes"; then
acc9da
+  AC_MSG_RESULT(yes)
acc9da
+  AC_DEFINE([HAVE_FIPS_WARNING])
acc9da
+
acc9da
+  dnl Setting path for system-fips file
acc9da
+
acc9da
+  AC_MSG_CHECKING(--with-system-fips-file argument)
acc9da
+  AC_ARG_WITH([system-fips-file], [  --with-system-fips-file=PATH       Link to system-fips file (default: /etc/system-fips)],
acc9da
+	with_system_fips_file=$withval,
acc9da
+       with_system_fips_file="/etc/system-fips")
acc9da
+  AC_MSG_RESULT([$with_system_fips_file])
acc9da
+  AC_DEFINE_UNQUOTED([SYSTEM_FIPS_FILE_LINK], ["$with_system_fips_file"])
acc9da
+
acc9da
+  dnl Setting link to fips_enabled file
acc9da
+
acc9da
+  AC_MSG_CHECKING(--with-fips-enabled-file argument)
acc9da
+  AC_ARG_WITH([fips-enabled-file], [  --with-fips-enabled-file=PATH       Link to fibs_enabled file (default: /proc/sys/crypto/fips_enabled)],
acc9da
+	with_fips_enabled_file=$withval,
acc9da
+       with_fips_enabled_file="/proc/sys/crypto/fips_enabled")
acc9da
+  AC_MSG_RESULT([$with_fips_enabled_file])
acc9da
+  AC_DEFINE_UNQUOTED([FIPS_ENABLED_FILE_LINK], ["$with_fips_enabled_file"])
acc9da
+else
acc9da
+  AC_MSG_RESULT(no)
acc9da
+fi
acc9da
+
acc9da
 dnl Check for Lua feature.
acc9da
 AC_MSG_CHECKING(--enable-luainterp argument)
acc9da
 AC_ARG_ENABLE(luainterp,
acc9da
diff --git a/src/crypt.c b/src/crypt.c
acc9da
index dfbf02c..c935bc0 100644
acc9da
--- a/src/crypt.c
acc9da
+++ b/src/crypt.c
acc9da
@@ -501,6 +501,21 @@ crypt_check_method(int method)
acc9da
 	msg_scroll = TRUE;
acc9da
 	MSG(_("Warning: Using a weak encryption method; see :help 'cm'"));
acc9da
     }
acc9da
+#ifdef HAVE_FIPS_WARNING
acc9da
+    FILE *fips_enable_fd = fopen(FIPS_ENABLED_FILE_LINK, "r");
acc9da
+    if (fips_enable_fd == NULL)
acc9da
+      return;
acc9da
+
acc9da
+    int enabled = fgetc(fips_enable_fd);
acc9da
+
acc9da
+    if ( access(SYSTEM_FIPS_FILE_LINK, F_OK) != -1 && enabled == '1')
acc9da
+    {
acc9da
+	msg_scroll = TRUE;
acc9da
+	MSG(_("Warning: This cryptography is not FIPS 140-2 compliant."));
acc9da
+    }
acc9da
+
acc9da
+    fclose(fips_enable_fd);
acc9da
+#endif
acc9da
 }
acc9da
 
acc9da
     void