]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Add parent option in password plugin
authorlongpanda <admin@ventoy.net>
Sat, 15 May 2021 00:57:26 +0000 (08:57 +0800)
committerlongpanda <admin@ventoy.net>
Sat, 15 May 2021 00:57:26 +0000 (08:57 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_plugin.c

index bb61fbbbfa65ddf9afee06a2af8cae325b0c530c..8e2527bf0af602096c9edde78f6b380f429b8648 100644 (file)
@@ -906,8 +906,12 @@ typedef struct vtoy_password
     grub_uint8_t md5[16];
 }vtoy_password;
 
+#define vtoy_menu_pwd_file   0
+#define vtoy_menu_pwd_parent 1
+
 typedef struct menu_password
 {
+    int type;
     int pathlen;
     char isopath[256];
 
index f44a4ea466c4756601639ac42adf459faba07971..900142c49bb6aa390827bc2db555fa9efdd15756 100644 (file)
@@ -876,13 +876,21 @@ static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
                     continue;
                 }
 
+                type = vtoy_menu_pwd_file;
                 iso = vtoy_json_get_string_ex(pCNode->pstChild, "file");
+                if (!iso)
+                {
+                    type = vtoy_menu_pwd_parent;
+                    iso = vtoy_json_get_string_ex(pCNode->pstChild, "parent");                    
+                }                
+                
                 pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
                 if (iso && pwd && iso[0] == '/')
                 {
                     node = grub_zalloc(sizeof(menu_password));
                     if (node)
                     {
+                        node->type = type;
                         node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
 
                         if (ventoy_plugin_parse_pwdstr((char *)pwd, &(node->password)))
@@ -959,8 +967,7 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
                     continue;
                 }
 
-                iso = vtoy_json_get_string_ex(pCNode->pstChild, "file");
-                if (iso)
+                if ((iso = vtoy_json_get_string_ex(pCNode->pstChild, "file")) != NULL)
                 {
                     pos = grub_strchr(iso, '*');
                     if (pos || 0 == ventoy_plugin_check_path(isodisk, iso))
@@ -982,6 +989,26 @@ static int ventoy_plugin_pwd_check(VTOY_JSON *json, const char *isodisk)
                         grub_printf("<%s%s> not found\n", isodisk, iso);
                     }
                 }
+                else if ((iso = vtoy_json_get_string_ex(pCNode->pstChild, "parent")) != NULL)
+                {
+                    if (ventoy_is_dir_exist("%s%s", isodisk, iso))
+                    {
+                        pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
+                        if (0 == ventoy_plugin_parse_pwdstr((char *)pwd, NULL))
+                        {
+                            grub_printf("dir:<%s> [%s]\n", iso, (pos ? "*" : "OK"));
+                            grub_printf("pwd:<%s>\n\n", pwd);
+                        }
+                        else
+                        {
+                            grub_printf("Invalid password for <%s>\n", iso);
+                        }
+                    }
+                    else
+                    {
+                        grub_printf("<%s%s> not found\n", isodisk, iso);
+                    }
+                }
                 else
                 {
                     grub_printf("No file item found in json.\n");
@@ -2525,9 +2552,24 @@ static const vtoy_password * ventoy_plugin_get_password(const char *isopath)
         len = (int)grub_strlen(isopath);    
         for (node = g_pwd_head; node; node = node->next)
         {
-            if (node->pathlen == len && ventoy_strncmp(node->isopath, isopath, len) == 0)
+            if (node->type == vtoy_menu_pwd_file)
+            {
+                if (node->pathlen == len && ventoy_strncmp(node->isopath, isopath, len) == 0)
+                {
+                    return &(node->password);
+                }
+            }
+        }
+
+        for (node = g_pwd_head; node; node = node->next)
+        {   
+            if (node->type == vtoy_menu_pwd_parent)
             {
-                return &(node->password);
+                if (node->pathlen < len && (isopath[node->pathlen] == '/') &&
+                    ventoy_strncmp(node->isopath, isopath, node->pathlen) == 0)
+                {
+                    return &(node->password);
+                }
             }
         }
     }