about summary refs log tree commit diff
path: root/src/core/settings
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2024-02-22 17:21:11 +0100
committerMichael Biebl <biebl@debian.org>2024-02-22 17:21:11 +0100
commitbba2e4b4de668db525cbfdfc35292e5a0b51671a (patch)
tree38d20cddfcc6f71572b9e169deefab5fa96e8d0c /src/core/settings
parent6681f77b757bbc42ce5c8868ee9142b7ebc8c059 (diff)
New upstream version 1.46.0 upstream/1.46.0
Diffstat (limited to 'src/core/settings')
-rw-r--r--src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c2
-rw-r--r--src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c109
-rw-r--r--src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c2
3 files changed, 2 insertions, 111 deletions
diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
index 04e79725..3bcbb71b 100644
--- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
+++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c
@@ -1723,7 +1723,7 @@ make_user_setting(shvarFile *ifcfg)
         else
             g_string_set_size(str, 0);
 
-        if (!nms_ifcfg_rh_utils_user_key_decode(key + NM_STRLEN("NM_USER_"), str))
+        if (!nm_utils_env_var_decode_name(key + NM_STRLEN("NM_USER_"), str))
             continue;
 
         if (!s_user)
diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
index 50e352d3..b4edefbb 100644
--- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
+++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.c
@@ -398,115 +398,6 @@ utils_detect_ifcfg_path(const char *path, gboolean only_ifcfg)
     return utils_get_ifcfg_path(path);
 }
 
-void
-nms_ifcfg_rh_utils_user_key_encode(const char *key, GString *str_buffer)
-{
-    gsize i;
-
-    nm_assert(key);
-    nm_assert(str_buffer);
-
-    for (i = 0; key[i]; i++) {
-        char ch = key[i];
-
-        /* we encode the key in only upper case letters, digits, and underscore.
-         * As we expect lower-case letters to be more common, we encode lower-case
-         * letters as upper case, and upper-case letters with a leading underscore. */
-
-        if (ch >= '0' && ch <= '9') {
-            g_string_append_c(str_buffer, ch);
-            continue;
-        }
-        if (ch >= 'a' && ch <= 'z') {
-            g_string_append_c(str_buffer, ch - 'a' + 'A');
-            continue;
-        }
-        if (ch == '.') {
-            g_string_append(str_buffer, "__");
-            continue;
-        }
-        if (ch >= 'A' && ch <= 'Z') {
-            g_string_append_c(str_buffer, '_');
-            g_string_append_c(str_buffer, ch);
-            continue;
-        }
-        g_string_append_printf(str_buffer, "_%03o", (unsigned) ch);
-    }
-}
-
-gboolean
-nms_ifcfg_rh_utils_user_key_decode(const char *name, GString *str_buffer)
-{
-    gsize i;
-
-    nm_assert(name);
-    nm_assert(str_buffer);
-
-    if (!name[0])
-        return FALSE;
-
-    for (i = 0; name[i];) {
-        char ch = name[i];
-
-        if (ch >= '0' && ch <= '9') {
-            g_string_append_c(str_buffer, ch);
-            i++;
-            continue;
-        }
-        if (ch >= 'A' && ch <= 'Z') {
-            g_string_append_c(str_buffer, ch - 'A' + 'a');
-            i++;
-            continue;
-        }
-
-        if (ch == '_') {
-            ch = name[i + 1];
-            if (ch == '_') {
-                g_string_append_c(str_buffer, '.');
-                i += 2;
-                continue;
-            }
-            if (ch >= 'A' && ch <= 'Z') {
-                g_string_append_c(str_buffer, ch);
-                i += 2;
-                continue;
-            }
-            if (ch >= '0' && ch <= '7') {
-                char     ch2, ch3;
-                unsigned v;
-
-                ch2 = name[i + 2];
-                if (!(ch2 >= '0' && ch2 <= '7'))
-                    return FALSE;
-
-                ch3 = name[i + 3];
-                if (!(ch3 >= '0' && ch3 <= '7'))
-                    return FALSE;
-
-#define OCTAL_VALUE(ch) ((unsigned) ((ch) - '0'))
-                v = (OCTAL_VALUE(ch) << 6) + (OCTAL_VALUE(ch2) << 3) + OCTAL_VALUE(ch3);
-                if (v > 0xFF || v == 0)
-                    return FALSE;
-                ch = (char) v;
-                if ((ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '.')
-                    || (ch >= 'a' && ch <= 'z')) {
-                    /* such characters are not expected to be encoded via
-                     * octal representation. The encoding is invalid. */
-                    return FALSE;
-                }
-                g_string_append_c(str_buffer, ch);
-                i += 4;
-                continue;
-            }
-            return FALSE;
-        }
-
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
 /*****************************************************************************/
 
 const char *const _nm_ethtool_ifcfg_names[] = {
diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
index 07e5e64d..617c5ef6 100644
--- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
+++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
@@ -2604,7 +2604,7 @@ write_user_setting(NMConnection *connection, shvarFile *ifcfg, GError **error)
 
             g_string_set_size(str, 0);
             g_string_append(str, "NM_USER_");
-            nms_ifcfg_rh_utils_user_key_encode(key, str);
+            nm_utils_env_var_encode_name(key, str);
             svSetValue(ifcfg, str->str, nm_setting_user_get_data(s_user, key));
         }
     }