From 4af84225403336cf5c8effbc601f11607cdfaa5c Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Wed, 11 Oct 2023 15:22:03 +0800 Subject: [PATCH 1/3] add func set_machine_vars and sh_get_home_dir --- bash-5.1/r_variables/src/lib.rs | 56 ++++++++++++++++----------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index d4364a9..48a28fa 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -167,6 +167,33 @@ unsafe extern "C" fn create_variable_tables() { } } +unsafe extern "C" fn set_machine_vars() { + + let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; + //set_if_not 下文会实现 + temp_var = set_if_not( + b"HOSTTYPE\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + get_host_type() as *mut libc::c_char + ); + + temp_var = set_if_not( + b"OSTYPE\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + get_os_type() as *mut libc::c_char + ); + + temp_var = set_if_not( + b"MACHTYPE\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + get_mach_type() as *mut libc::c_char + ); + + temp_var = set_if_not( + b"HOSTNAME\0" as *const u8 as *const libc::c_char as *mut libc::c_char, + current_host_name + ); + + +} + #[no_mangle] pub unsafe extern "C" fn sh_get_home_dir() -> *mut libc::c_char { @@ -176,32 +203,3 @@ pub unsafe extern "C" fn sh_get_home_dir() -> *mut libc::c_char { } return current_user.home_dir; } - -unsafe extern "C" fn set_home_var() { - let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; - // find_variable 下文会实现 - temp_var = find_variable(b"HOME\0" as *const u8 as *const libc::c_char); - if temp_var.is_null() { - temp_var =bind_variable( - b"HOME\0" as *const u8 as *const libc::c_char, - sh_get_home_dir(), - 0 as libc::c_int); - } -} - -unsafe extern "C" fn set_shell_var() { - let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; - // find_variable 下文会实现 - temp_var = find_variable(b"SHELL\0" as *const u8 as *const libc::c_char); - if temp_var.is_null() { - if (current_user.shell).is_null() { - // get_current_user_info in file of shell.c - get_current_user_info(); - } - temp_var =bind_variable( - b"SHELL\0" as *const u8 as *const libc::c_char, - current_user.shell, - 0 as libc::c_int); - } -} - -- Gitee From cd15a1081aa974257f136af0f4fd0740da21705e Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Wed, 11 Oct 2023 15:31:06 +0800 Subject: [PATCH 2/3] load variable nameref_invalid_value and nameref_maxloop_value --- bash-5.1/r_variables/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index 48a28fa..2e050e8 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -134,6 +134,28 @@ macro_rules! vc_istempenv { } } +#[no_mangle] +pub static mut nameref_invalid_value: SHELL_VAR = SHELL_VAR { + + name: 0 as *const libc::c_char as *mut libc::c_char, + value: 0 as *const libc::c_char as *mut libc::c_char, + exportstr: 0 as *const libc::c_char as *mut libc::c_char, + dynamic_value: None, + assign_func: None, + attributes: 0, + context: 0, + +}; + +static mut nameref_maxloop_value: SHELL_VAR = SHELL_VAR { + name: 0 as *const libc::c_char as *mut libc::c_char, + value: 0 as *const libc::c_char as *mut libc::c_char, + exportstr: 0 as *const libc::c_char as *mut libc::c_char, + dynamic_value: None, + assign_func: None, + attributes: 0, + context: 0, +}; static mut last_table_searched: *mut HASH_TABLE = 0 as *const HASH_TABLE as *mut HASH_TABLE; -- Gitee From 3e5edd42c6118e7827d7d4a183e861a67708f632 Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Wed, 11 Oct 2023 15:40:19 +0800 Subject: [PATCH 3/3] load EXECUTION_FAILURE FV_NODYNAMIC marco --- bash-5.1/r_variables/src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bash-5.1/r_variables/src/lib.rs b/bash-5.1/r_variables/src/lib.rs index 2e050e8..68343ff 100644 --- a/bash-5.1/r_variables/src/lib.rs +++ b/bash-5.1/r_variables/src/lib.rs @@ -134,6 +134,29 @@ macro_rules! vc_istempenv { } } +#[macro_export] +macro_rules! FV_NODYNAMIC { + () => { + 0x04 + }; +} + +#[macro_export] +macro_rules! EXECUTION_FAILURE { + () => { + 1 as libc::c_int + }; +} + + +#[macro_export] +macro_rules! DEFAULT_PATH_VALUE { + () => { + b"/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.\0" + as *const u8 as *const libc::c_char as *mut libc::c_char + } +} + #[no_mangle] pub static mut nameref_invalid_value: SHELL_VAR = SHELL_VAR { @@ -156,6 +179,7 @@ static mut nameref_maxloop_value: SHELL_VAR = SHELL_VAR { attributes: 0, context: 0, }; + static mut last_table_searched: *mut HASH_TABLE = 0 as *const HASH_TABLE as *mut HASH_TABLE; @@ -189,6 +213,7 @@ unsafe extern "C" fn create_variable_tables() { } } + unsafe extern "C" fn set_machine_vars() { let mut temp_var: *mut SHELL_VAR = 0 as *mut SHELL_VAR; -- Gitee