]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: switch from fnmatch to g_pattern_match_simple
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 20 Dec 2019 16:02:49 +0000 (16:02 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 3 Jan 2020 15:42:13 +0000 (15:42 +0000)
The g_pattern_match function_simple is an acceptably close
approximation of fnmatch for libvirt's needs.

In contrast to fnmatch(), the '/' character can be matched
by the wildcards, there are no '[...]' character ranges and
'*' and '?' can not be escaped to include them literally in
a pattern.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_firmware.c
src/remote/libvirtd.conf.in
src/rpc/virnetsaslcontext.c
src/rpc/virnettlscontext.c
src/util/virlog.c
tests/virconfdata/libvirtd.conf
tests/virconfdata/libvirtd.out
tools/virt-login-shell-helper.c

index f62ce90ac92a087c7953f83b93eff504eaf21558..6a76d355f5774b9d29ca925226c71fb3b09c2889 100644 (file)
@@ -20,8 +20,6 @@
 
 #include <config.h>
 
-#include <fnmatch.h>
-
 #include "qemu_firmware.h"
 #include "qemu_interop_config.h"
 #include "configmake.h"
@@ -921,7 +919,7 @@ qemuFirmwareMatchesMachineArch(const qemuFirmware *fw,
             continue;
 
         for (j = 0; j < fw->targets[i]->nmachines; j++) {
-            if (fnmatch(fw->targets[i]->machines[j], machine, 0) == 0)
+            if (g_pattern_match_simple(fw->targets[i]->machines[j], machine))
                 return true;
         }
     }
index f984ce04780ecfaaf64e2bdc0dc3b9089f6f9907..34741183cc3391992a90dd73c92c43c8c89c04f1 100644 (file)
 #
 #    "C=GB,ST=London,L=London,O=Red Hat,CN=*"
 #
-# See the POSIX fnmatch function for the format of the wildcards.
+# See the g_pattern_match function for the format of the wildcards:
+#
+# https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html
 #
 # NB If this is an empty list, no client can connect, so comment out
 # entirely rather than using empty list to disable these checks
 #
 #    "*@EXAMPLE.COM"
 #
-# See the POSIX fnmatch function for the format of the wildcards.
+# See the g_pattern_match function for the format of the wildcards.
+#
+# https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html
 #
 # NB If this is an empty list, no client can connect, so comment out
 # entirely rather than using empty list to disable these checks
index 01ff41b7789f74e4dc501c52e6a380ff99a8ff4a..e7ed8f43906ed3a1260ae31c8a379b39f1eea051 100644 (file)
@@ -20,8 +20,6 @@
 
 #include <config.h>
 
-#include <fnmatch.h>
-
 #include "virnetsaslcontext.h"
 #include "virnetmessage.h"
 
@@ -155,17 +153,10 @@ int virNetSASLContextCheckIdentity(virNetSASLContextPtr ctxt,
     }
 
     while (*wildcards) {
-        int rv = fnmatch(*wildcards, identity, 0);
-        if (rv == 0) {
+        if (g_pattern_match_simple(*wildcards, identity)) {
             ret = 1;
             goto cleanup; /* Successful match */
         }
-        if (rv != FNM_NOMATCH) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Malformed TLS whitelist regular expression '%s'"),
-                           *wildcards);
-            goto cleanup;
-        }
 
         wildcards++;
     }
index 08944f67713b066fcac3010a1c586bcc3481040f..44f0dfce77565ae19c557d4aa6c6cb65e5196f2c 100644 (file)
@@ -21,7 +21,6 @@
 #include <config.h>
 
 #include <unistd.h>
-#include <fnmatch.h>
 
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
@@ -361,15 +360,8 @@ virNetTLSContextCheckCertDNWhitelist(const char *dname,
                                      const char *const*wildcards)
 {
     while (*wildcards) {
-        int ret = fnmatch(*wildcards, dname, 0);
-        if (ret == 0) /* Successful match */
+        if (g_pattern_match_simple(*wildcards, dname))
             return 1;
-        if (ret != FNM_NOMATCH) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Malformed TLS whitelist regular expression '%s'"),
-                           *wildcards);
-            return -1;
-        }
 
         wildcards++;
     }
index 6bae56e2e3be5de4aa6fb382c36f992dda41f401..aa98024e1c2fd3b568105fb0e9e8be5d262a9dc9 100644 (file)
@@ -36,7 +36,6 @@
 #if HAVE_SYS_UN_H
 # include <sys/un.h>
 #endif
-#include <fnmatch.h>
 
 #include "virerror.h"
 #include "virlog.h"
@@ -488,7 +487,7 @@ virLogSourceUpdate(virLogSourcePtr source)
         size_t i;
 
         for (i = 0; i < virLogNbFilters; i++) {
-            if (fnmatch(virLogFilters[i]->match, source->name, 0) == 0) {
+            if (g_pattern_match_simple(virLogFilters[i]->match, source->name)) {
                 priority = virLogFilters[i]->priority;
                 break;
             }
@@ -1338,7 +1337,7 @@ virLogFilterNew(const char *match,
         return NULL;
     }
 
-    /* We must treat 'foo' as equiv to '*foo*' for fnmatch
+    /* We must treat 'foo' as equiv to '*foo*' for g_pattern_match
      * todo substring matches, so add 2 extra bytes
      */
     if (VIR_ALLOC_N_QUIET(mdup, mlen + 3) < 0)
index 602aa08d927abcf0dc1b665fb375dc1598ef2607..791d6c972b1b284dc9b1fde8daf6a87b1faa3876 100644 (file)
@@ -183,7 +183,9 @@ tls_no_verify_certificate = 1
 #
 #    "C=GB,ST=London,L=London,O=Red Hat,CN=*"
 #
-# See the POSIX fnmatch function for the format of the wildcards.
+# See the g_pattern_match function for the format of the wildcards.
+#
+# https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html
 #
 # NB If this is an empty list, no client can connect, so comment out
 # entirely rather than using empty list to disable these checks
@@ -200,7 +202,9 @@ tls_allowed_dn_list = ["DN1", "DN2"]
 #
 #    "*@EXAMPLE.COM"
 #
-# See the POSIX fnmatch function for the format of the wildcards.
+# See the g_pattern_match function for the format of the wildcards.
+#
+# https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html
 #
 # NB If this is an empty list, no client can connect, so comment out
 # entirely rather than using empty list to disable these checks
index d3f2bd20a7bf385273423259d43decf20ad930c0..cfdd23fd215ec010078da1de51bf19f0b8cfea1d 100644 (file)
@@ -147,7 +147,9 @@ tls_no_verify_certificate = 1
 #
 #    "C=GB,ST=London,L=London,O=Red Hat,CN=*"
 #
-# See the POSIX fnmatch function for the format of the wildcards.
+# See the g_pattern_match function for the format of the wildcards.
+#
+# https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html
 #
 # NB If this is an empty list, no client can connect, so comment out
 # entirely rather than using empty list to disable these checks
@@ -162,7 +164,9 @@ tls_allowed_dn_list = [ "DN1", "DN2" ]
 #
 #    "*@EXAMPLE.COM"
 #
-# See the POSIX fnmatch function for the format of the wildcards.
+# See the g_pattern_match function for the format of the wildcards.
+#
+# https://developer.gnome.org/glib/stable/glib-Glob-style-pattern-matching.html
 #
 # NB If this is an empty list, no client can connect, so comment out
 # entirely rather than using empty list to disable these checks
index cdd64d9a59553804724ad9fe638a63ca8ce7d2fc..d9db883ee63bc6bc4e1160846fa6053172c0475e 100644 (file)
@@ -19,7 +19,6 @@
  */
 #include <config.h>
 
-#include <fnmatch.h>
 #include <getopt.h>
 #include <signal.h>
 #include <stdarg.h>
@@ -67,14 +66,14 @@ static int virLoginShellAllowedUser(virConfPtr conf,
             for (i = 0; i < ngroups; i++) {
                 if (!(gname = virGetGroupName(groups[i])))
                     continue;
-                if (fnmatch(entry, gname, 0) == 0) {
+                if (g_pattern_match_simple(entry, gname)) {
                     ret = 0;
                     goto cleanup;
                 }
                 VIR_FREE(gname);
             }
         } else {
-            if (fnmatch(entry, name, 0) == 0) {
+            if (g_pattern_match_simple(entry, name)) {
                 ret = 0;
                 goto cleanup;
             }