Skip to content

added environment variable expansion in config file#539

Open
sergey-safarov wants to merge 1 commit into
irontec:masterfrom
sergey-safarov:gh529
Open

added environment variable expansion in config file#539
sergey-safarov wants to merge 1 commit into
irontec:masterfrom
sergey-safarov:gh529

Conversation

@sergey-safarov

Copy link
Copy Markdown
Contributor

This PR add environment variables expansion in sngrep config file.

Use case example
You have logged into remote server using ssh as normal user (not root user).
Then you will need to use sudo -i command to get root user permission.
To save pcap files in normal user folder (not root folder) required to configure in /etc/sngreprc file next string

set savepath /home/${SUDO_USER}

PR tested locally.

Related to GH #529

@Kaian

Kaian commented Jun 30, 2026

Copy link
Copy Markdown
Member

Hi @sergey-safarov!

Apologies for the long silence. I recently became a father and have been focusing on family during this time.

I get the idea, but if we're only doing this for a single setting, I would prefer to do it where settings are initializated rather than the function used to set all settings, and always try to expand the setting (we can check if there are expansion tags inside the function )

diff --git a/src/option.c b/src/option.c
index 28f011a..aaf4cb3 100644
--- a/src/option.c
+++ b/src/option.c
@@ -98,6 +98,12 @@ init_options(int no_config)
         }
     }
 
+    // Expand environment macros in save path
+    const char *save_path = setting_get_value(SETTING_SAVEPATH);
+    char expanded_value[MAX_SETTING_LEN];
+    setting_expand_env_macros(save_path, expanded_value, sizeof(expanded_value));
+    setting_set_value(SETTING_SAVEPATH, expanded_value);
+
     return 0;
 }

What do you think?

Thanks for your time and contribution!

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants