mirror of
https://github.com/ventoy/Ventoy.git
synced 2025-03-30 09:13:45 -04:00
Add parent option in password plugin
This commit is contained in:
parent
672632a0c2
commit
f7b3bd1729
@ -906,8 +906,12 @@ typedef struct vtoy_password
|
|||||||
grub_uint8_t md5[16];
|
grub_uint8_t md5[16];
|
||||||
}vtoy_password;
|
}vtoy_password;
|
||||||
|
|
||||||
|
#define vtoy_menu_pwd_file 0
|
||||||
|
#define vtoy_menu_pwd_parent 1
|
||||||
|
|
||||||
typedef struct menu_password
|
typedef struct menu_password
|
||||||
{
|
{
|
||||||
|
int type;
|
||||||
int pathlen;
|
int pathlen;
|
||||||
char isopath[256];
|
char isopath[256];
|
||||||
|
|
||||||
|
@ -876,13 +876,21 @@ static int ventoy_plugin_pwd_entry(VTOY_JSON *json, const char *isodisk)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type = vtoy_menu_pwd_file;
|
||||||
iso = vtoy_json_get_string_ex(pCNode->pstChild, "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");
|
pwd = vtoy_json_get_string_ex(pCNode->pstChild, "pwd");
|
||||||
if (iso && pwd && iso[0] == '/')
|
if (iso && pwd && iso[0] == '/')
|
||||||
{
|
{
|
||||||
node = grub_zalloc(sizeof(menu_password));
|
node = grub_zalloc(sizeof(menu_password));
|
||||||
if (node)
|
if (node)
|
||||||
{
|
{
|
||||||
|
node->type = type;
|
||||||
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
|
node->pathlen = grub_snprintf(node->isopath, sizeof(node->isopath), "%s", iso);
|
||||||
|
|
||||||
if (ventoy_plugin_parse_pwdstr((char *)pwd, &(node->password)))
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
iso = vtoy_json_get_string_ex(pCNode->pstChild, "file");
|
if ((iso = vtoy_json_get_string_ex(pCNode->pstChild, "file")) != NULL)
|
||||||
if (iso)
|
|
||||||
{
|
{
|
||||||
pos = grub_strchr(iso, '*');
|
pos = grub_strchr(iso, '*');
|
||||||
if (pos || 0 == ventoy_plugin_check_path(isodisk, 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);
|
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
|
else
|
||||||
{
|
{
|
||||||
grub_printf("No file item found in json.\n");
|
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);
|
len = (int)grub_strlen(isopath);
|
||||||
for (node = g_pwd_head; node; node = node->next)
|
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)
|
||||||
{
|
{
|
||||||
return &(node->password);
|
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)
|
||||||
|
{
|
||||||
|
if (node->pathlen < len && (isopath[node->pathlen] == '/') &&
|
||||||
|
ventoy_strncmp(node->isopath, isopath, node->pathlen) == 0)
|
||||||
|
{
|
||||||
|
return &(node->password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user