From 99763104a281294afef3cd35d229a83485f9d6ec Mon Sep 17 00:00:00 2001 From: Wvader <34067397+wvader@users.noreply.github.com> Date: Wed, 2 Nov 2022 19:13:01 +0000 Subject: [PATCH] printAugTree --- main.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index a85f8cf..7084ad2 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,7 @@ static void testGet() { aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD); r = aug_load_file(aug, "/etc/hosts"); - r = aug_source(aug, "/files/etc/hosts/1", &s); + r = aug_source(aug, "/files/etc/hosts/1/ipaddr", NULL); std::cout << "The value read from node: " << s << std::endl; @@ -53,17 +53,15 @@ static void readHostsFile() { /// Get the tree of the /etc/hosts file printed in the console /// Implementation based on https://github.com/Nexenta/node-augeas/blob/756276c432cc9e506836800ac9d217bedbbef55c/libaugeas.cc#L784 -static void readHostsTree() { +static void printAugTree(const std::string& matchPath, const std::string& filePath) { struct augeas *aug; int r; FILE *out = tmpfile(); aug = aug_init(root, loadpath, AUG_NO_STDINC | AUG_NO_LOAD); - const std::string matchPath = "/files/etc/hosts/*"; - - r = aug_load_file(aug, "/etc/hosts"); - r = aug_print(aug, out,"/files/etc/hosts/*"); + r = aug_load_file(aug, filePath.c_str()); + r = aug_print(aug, out,matchPath.c_str()); std::map stdBindList; std::map ::iterator pos; @@ -101,15 +99,14 @@ static void readHostsTree() { } aug_close(aug); - - - } int main(int argc, char *argv[]) { - testGet(); - readHostsTree(); + //testGet(); + printAugTree("/files/etc/hosts/*", "/etc/hosts"); + printAugTree("/files/etc/ssh/sshd_config/*", "/etc/ssh/sshd_config"); + return 0; } \ No newline at end of file