From 90222cb9c035d5d02feb184fe9a136336cb2c8e0 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Fri, 12 Jan 2024 11:59:31 +0000 Subject: [PATCH 1/5] cleanup(libsinsp): use string_view in parse_dirfd Signed-off-by: Luca Guerra --- userspace/libsinsp/parsers.cpp | 54 +++++++++------------ userspace/libsinsp/parsers.h | 2 +- userspace/libsinsp/sinsp_filtercheck_fd.cpp | 3 +- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index 3c3f04ee8d..897e913a11 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -2307,8 +2307,7 @@ void sinsp_parser::parse_execve_exit(sinsp_evt *evt) /* If the pathname is `` here we shouldn't have problems during `parse_dirfd`. * It doesn't start with "/" so it is not considered an absolute path. */ - std::string sdir; - parse_dirfd(evt, pathname.data(), dirfd, &sdir); + std::string sdir = parse_dirfd(evt, pathname, dirfd); /* (4) In this case, we were not able to recover the pathname from the kernel or * we are not able to recover information about `dirfd` in our `sinsp` state. @@ -2514,11 +2513,11 @@ void sinsp_parser::parse_execve_exit(sinsp_evt *evt) * - if we have no information about `dirfd` -> sdir = "". * - if `dirfd` has a valid vaule for us -> sdir = path + "/" at the end. */ -void sinsp_parser::parse_dirfd(sinsp_evt *evt, const char* name, int64_t dirfd, OUT std::string* sdir) +std::string sinsp_parser::parse_dirfd(sinsp_evt *evt, std::string_view name, int64_t dirfd) { bool is_absolute = false; /* This should never happen but just to be sure. */ - if(name != NULL) + if(name.data() != nullptr) { is_absolute = (name[0] == '/'); } @@ -2532,40 +2531,33 @@ void sinsp_parser::parse_dirfd(sinsp_evt *evt, const char* name, int64_t dirfd, // Some processes (e.g. irqbalance) actually do this: they pass an invalid fd and // and absolute path, and openat succeeds. // - *sdir = "."; + return "."; } - else if(dirfd == PPM_AT_FDCWD) + + if(dirfd == PPM_AT_FDCWD) { if(evt->m_tinfo != NULL) { - *sdir = evt->m_tinfo->get_cwd(); - } - else - { - *sdir = ""; + return evt->m_tinfo->get_cwd(); } + + return ""; } - else + + evt->m_fdinfo = evt->m_tinfo->get_fd(dirfd); + + if(evt->m_fdinfo == NULL) { - evt->m_fdinfo = evt->m_tinfo->get_fd(dirfd); + return ""; + } - if(evt->m_fdinfo == NULL) - { - *sdir = ""; - } - else - { - if(evt->m_fdinfo->m_name[evt->m_fdinfo->m_name.length()] == '/') - { - *sdir = evt->m_fdinfo->m_name; - } - else - { - tdirstr = evt->m_fdinfo->m_name + '/'; - *sdir = tdirstr; - } - } + if(evt->m_fdinfo->m_name[evt->m_fdinfo->m_name.length()] == '/') + { + return evt->m_fdinfo->m_name; } + + tdirstr = evt->m_fdinfo->m_name + '/'; + return tdirstr; } void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) @@ -2682,7 +2674,7 @@ void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) int64_t dirfd = enter_evt->get_param(0)->as(); - parse_dirfd(evt, name.data(), dirfd, &sdir); + sdir = parse_dirfd(evt, name, dirfd); } else if(etype == PPME_SYSCALL_OPENAT_2_X || etype == PPME_SYSCALL_OPENAT2_X) { @@ -2724,7 +2716,7 @@ void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) } } - parse_dirfd(evt, name.data(), dirfd, &sdir); + sdir = parse_dirfd(evt, name, dirfd); } else if (etype == PPME_SYSCALL_OPEN_BY_HANDLE_AT_X) { diff --git a/userspace/libsinsp/parsers.h b/userspace/libsinsp/parsers.h index 58da3fdd76..2022037dc0 100644 --- a/userspace/libsinsp/parsers.h +++ b/userspace/libsinsp/parsers.h @@ -45,7 +45,7 @@ class sinsp_parser // // Combine the openat arguments into a full file name // - static void parse_dirfd(sinsp_evt *evt, const char* name, int64_t dirfd, OUT std::string* sdir); + std::string parse_dirfd(sinsp_evt *evt, std::string_view name, int64_t dirfd); void set_track_connection_status(bool enabled); bool get_track_connection_status() { return m_track_connection_status; } diff --git a/userspace/libsinsp/sinsp_filtercheck_fd.cpp b/userspace/libsinsp/sinsp_filtercheck_fd.cpp index 548a170d26..4d12d5e50a 100644 --- a/userspace/libsinsp/sinsp_filtercheck_fd.cpp +++ b/userspace/libsinsp/sinsp_filtercheck_fd.cpp @@ -214,7 +214,6 @@ bool sinsp_filter_check_fd::extract_fdname_from_creator(sinsp_evt *evt, OUT uint { sinsp_evt enter_evt; const sinsp_evt_param *parinfo; - std::string sdir; if(etype == PPME_SYSCALL_OPENAT_X) { @@ -235,7 +234,7 @@ bool sinsp_filter_check_fd::extract_fdname_from_creator(sinsp_evt *evt, OUT uint parinfo = etype == PPME_SYSCALL_OPENAT_X ? enter_evt.get_param(0) : evt->get_param(1); int64_t dirfd = parinfo->as(); - sinsp_parser::parse_dirfd(evt, name.data(), dirfd, &sdir); + std::string sdir = m_inspector->get_parser()->parse_dirfd(evt, name, dirfd); if(fd_nameraw) { From 5553369a143c79562bcd8361dbbe9687787dc380 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Fri, 12 Jan 2024 12:36:02 +0000 Subject: [PATCH 2/5] cleanup(libsinsp): use native comparison operators for string_view Signed-off-by: Luca Guerra --- userspace/libsinsp/parsers.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index 897e913a11..cb070169da 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -2313,10 +2313,8 @@ void sinsp_parser::parse_execve_exit(sinsp_evt *evt) * we are not able to recover information about `dirfd` in our `sinsp` state. * Fallback to ``. */ - if((!(flags & PPM_EXVAT_AT_EMPTY_PATH) && strncmp(pathname.data(), "", 5) == 0) || - sdir.compare("") == 0) + if((!(flags & PPM_EXVAT_AT_EMPTY_PATH) && pathname == "") || sdir == "") { - /* we copy also the string terminator `\0`. */ fullpath = ""; } /* (3) In this case we have already obtained the `exepath` and it is `sdir`, we just need @@ -2618,7 +2616,7 @@ void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) enter_evt_name = enter_evt->get_param(0)->as(); enter_evt_flags = enter_evt->get_param(1)->as(); - if(enter_evt_name.data() != nullptr && strncmp(enter_evt_name.data(), "", 5) != 0) + if(enter_evt_name.data() != nullptr && enter_evt_name != "") { name = enter_evt_name; @@ -2652,7 +2650,7 @@ void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) enter_evt_name = enter_evt->get_param(0)->as(); enter_evt_flags = 0; - if(enter_evt_name.data() != nullptr && strncmp(enter_evt_name.data(), "", 5) != 0) + if(enter_evt_name.data() != nullptr && enter_evt_name != "") { name = enter_evt_name; @@ -2702,7 +2700,7 @@ void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) enter_evt_flags = enter_evt->get_param(2)->as(); int64_t enter_evt_dirfd = enter_evt->get_param(0)->as(); - if(enter_evt_name.data() != nullptr && strncmp(enter_evt_name.data(), "", 5) != 0) + if(enter_evt_name.data() != nullptr && enter_evt_name != "") { name = enter_evt_name; From b4cebd06fb4431ac7fb79418ea9e0610f0dbdd0d Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Fri, 12 Jan 2024 12:43:19 +0000 Subject: [PATCH 3/5] fix(libsinsp): use std::string in add_filename(_raw) Signed-off-by: Luca Guerra --- userspace/libsinsp/fdinfo.cpp | 8 ++++---- userspace/libsinsp/fdinfo.h | 4 ++-- userspace/libsinsp/parsers.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/userspace/libsinsp/fdinfo.cpp b/userspace/libsinsp/fdinfo.cpp index b60bbf7666..bb7ae1b8ff 100644 --- a/userspace/libsinsp/fdinfo.cpp +++ b/userspace/libsinsp/fdinfo.cpp @@ -169,14 +169,14 @@ template<> std::string sinsp_fdinfo_t::tostring_clean() return m_tstr; } -template<> void sinsp_fdinfo_t::add_filename_raw(const char* rawpath) +template<> void sinsp_fdinfo_t::add_filename_raw(std::string_view rawpath) { - m_name_raw = rawpath; + m_name_raw = std::string(rawpath); } -template<> void sinsp_fdinfo_t::add_filename(const char* fullpath) +template<> void sinsp_fdinfo_t::add_filename(std::string_view fullpath) { - m_name = fullpath; + m_name = std::string(fullpath); } template<> bool sinsp_fdinfo_t::set_net_role_by_guessing(sinsp* inspector, diff --git a/userspace/libsinsp/fdinfo.h b/userspace/libsinsp/fdinfo.h index f640cefac6..fd59b4c5e4 100644 --- a/userspace/libsinsp/fdinfo.h +++ b/userspace/libsinsp/fdinfo.h @@ -369,8 +369,8 @@ class SINSP_PUBLIC sinsp_fdinfo FLAGS_CONNECTION_FAILED = (1 << 16), }; - void add_filename_raw(const char* rawpath); - void add_filename(const char* fullpath); + void add_filename_raw(std::string_view rawpath); + void add_filename(std::string_view fullpath); inline bool is_transaction() const { diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index cb070169da..6fa7c404e7 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -2762,8 +2762,8 @@ void sinsp_parser::parse_open_openat_creat_exit(sinsp_evt *evt) fdi.m_mount_id = 0; fdi.m_dev = dev; fdi.m_ino = ino; - fdi.add_filename_raw(name.data()); - fdi.add_filename(fullpath.c_str()); + fdi.add_filename_raw(name); + fdi.add_filename(fullpath); // // Add the fd to the table. @@ -5637,7 +5637,7 @@ void sinsp_parser::parse_memfd_create_exit(sinsp_evt *evt, scap_fd_type type) Suppose you create a memfd named libstest resulting in a fd.name libstest while on disk (e.g. ls -l /proc/$PID/fd/$FD_NUM) it may look like /memfd:libstest (deleted) */ - std::string name = std::string(evt->get_param(1)->as()); + auto name = evt->get_param(1)->as(); /* flags */ flags = evt->get_param(2)->as(); @@ -5645,7 +5645,7 @@ void sinsp_parser::parse_memfd_create_exit(sinsp_evt *evt, scap_fd_type type) if(fd >= 0) { fdi.m_type = type; - fdi.add_filename(name.c_str()); + fdi.add_filename(name); fdi.m_openflags = flags; } From 4162d37177b50eb38b2fbac2ba9a4cae1f24b428 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Fri, 12 Jan 2024 13:58:49 +0000 Subject: [PATCH 4/5] cleanup(libsinsp): use string instead of character buffer Signed-off-by: Luca Guerra --- userspace/libsinsp/parsers.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index 6fa7c404e7..f2ac2735be 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -5679,12 +5679,7 @@ void sinsp_parser::parse_pidfd_open_exit(sinsp_evt *evt) { // note: approximating equivalent filename as in: // https://man7.org/linux/man-pages/man2/pidfd_getfd.2.html - char fname[SCAP_MAX_PATH_SIZE]; - snprintf(fname, - sizeof(fname), - "%s/proc/%lld", - scap_get_host_root(), - (long long) pid); + std::string fname = std::string(scap_get_host_root()) + "/proc/" + std::to_string(pid); fdi.m_type = scap_fd_type::SCAP_FD_PIDFD; fdi.add_filename(fname); fdi.m_openflags = flags; From d8cdad2483509053f8a12bbdc70930701335d426 Mon Sep 17 00:00:00 2001 From: Luca Guerra Date: Fri, 12 Jan 2024 16:51:34 +0000 Subject: [PATCH 5/5] cleanup(libsinsp): use string_view in user/group functions Signed-off-by: Luca Guerra --- userspace/libsinsp/parsers.cpp | 4 +-- userspace/libsinsp/test/user.ut.cpp | 8 ++--- userspace/libsinsp/threadinfo.cpp | 4 +-- userspace/libsinsp/user.cpp | 46 +++++++++++++---------------- userspace/libsinsp/user.h | 17 ++++++----- 5 files changed, 37 insertions(+), 42 deletions(-) diff --git a/userspace/libsinsp/parsers.cpp b/userspace/libsinsp/parsers.cpp index f2ac2735be..ff84de049d 100644 --- a/userspace/libsinsp/parsers.cpp +++ b/userspace/libsinsp/parsers.cpp @@ -5310,10 +5310,10 @@ void sinsp_parser::parse_user_evt(sinsp_evt *evt) if (evt->m_pevt->type == PPME_USER_ADDED_E) { - m_inspector->m_usergroup_manager.add_user(container_id.data(), -1, uid, gid, name.data(), home.data(), shell.data()); + m_inspector->m_usergroup_manager.add_user(std::string(container_id), -1, uid, gid, name, home, shell); } else { - m_inspector->m_usergroup_manager.rm_user(container_id.data(), uid); + m_inspector->m_usergroup_manager.rm_user(std::string(container_id), uid); } } diff --git a/userspace/libsinsp/test/user.ut.cpp b/userspace/libsinsp/test/user.ut.cpp index 1a14e7b726..a7421da9e2 100644 --- a/userspace/libsinsp/test/user.ut.cpp +++ b/userspace/libsinsp/test/user.ut.cpp @@ -89,7 +89,7 @@ TEST_F(usergroup_manager_test, system_lookup) sinsp_usergroup_manager mgr(&m_inspector); - mgr.add_user(container_id, -1, 0, 0, nullptr, nullptr, nullptr); + mgr.add_user(container_id, -1, 0, 0, {}, {}, {}); auto* user = mgr.get_user(container_id, 0); ASSERT_NE(user, nullptr); ASSERT_EQ(user->uid, 0); @@ -105,7 +105,7 @@ TEST_F(usergroup_manager_test, system_lookup) #endif ASSERT_EQ(std::string(user->shell).empty(), false); - mgr.add_group(container_id, -1, 0, nullptr); + mgr.add_group(container_id, -1, 0, {}); auto* group = mgr.get_group(container_id, 0); ASSERT_NE(group, nullptr); ASSERT_EQ(group->gid, 0); @@ -196,7 +196,7 @@ TEST_F(usergroup_manager_host_root_test, host_root_lookup) sinsp_usergroup_manager mgr(&m_inspector); - mgr.add_user(container_id, -1, 0, 0, nullptr, nullptr, nullptr); + mgr.add_user(container_id, -1, 0, 0, {}, {}, {}); auto* user = mgr.get_user(container_id, 0); ASSERT_NE(user, nullptr); ASSERT_EQ(user->uid, 0); @@ -205,7 +205,7 @@ TEST_F(usergroup_manager_host_root_test, host_root_lookup) ASSERT_STREQ(user->homedir, "/toor"); ASSERT_STREQ(user->shell, "/bin/ash"); - mgr.add_group(container_id, -1, 0, nullptr); + mgr.add_group(container_id, -1, 0, {}); auto* group = mgr.get_group(container_id, 0); ASSERT_NE(group, nullptr); ASSERT_EQ(group->gid, 0); diff --git a/userspace/libsinsp/threadinfo.cpp b/userspace/libsinsp/threadinfo.cpp index d3a06ed0c5..a3c2d8e222 100644 --- a/userspace/libsinsp/threadinfo.cpp +++ b/userspace/libsinsp/threadinfo.cpp @@ -516,7 +516,7 @@ void sinsp_threadinfo::set_user(uint32_t uid) if (!user) { auto notify = m_inspector->is_live() || m_inspector->is_syscall_plugin(); - user = m_inspector->m_usergroup_manager.add_user(m_container_id, m_pid, uid, m_group.gid, NULL, NULL, NULL, notify); + user = m_inspector->m_usergroup_manager.add_user(m_container_id, m_pid, uid, m_group.gid, {}, {}, {}, notify); } if (user) { @@ -538,7 +538,7 @@ void sinsp_threadinfo::set_group(uint32_t gid) if (!group) { auto notify = m_inspector->is_live() || m_inspector->is_syscall_plugin(); - group = m_inspector->m_usergroup_manager.add_group(m_container_id, m_pid, gid, NULL, notify); + group = m_inspector->m_usergroup_manager.add_group(m_container_id, m_pid, gid, {}, notify); } if (group) { diff --git a/userspace/libsinsp/user.cpp b/userspace/libsinsp/user.cpp index c337017436..67971c4ed4 100644 --- a/userspace/libsinsp/user.cpp +++ b/userspace/libsinsp/user.cpp @@ -242,22 +242,18 @@ scap_userinfo *sinsp_usergroup_manager::userinfo_map_insert( userinfo_map &map, uint32_t uid, uint32_t gid, - const char *name, - const char *home, - const char *shell) + std::string_view name, + std::string_view home, + std::string_view shell) { - ASSERT(name); - ASSERT(home); - ASSERT(shell); - auto &usr = map[uid]; usr.uid = uid; usr.gid = gid; // In case the node is configured to use NIS, // some struct passwd* fields may be set to NULL. - strlcpy(usr.name, (name != nullptr) ? name : "", MAX_CREDENTIALS_STR_LEN); - strlcpy(usr.homedir, (home != nullptr) ? home : "", SCAP_MAX_PATH_SIZE); - strlcpy(usr.shell, (shell != nullptr) ? shell : "", SCAP_MAX_PATH_SIZE); + strlcpy(usr.name, (name.data() != nullptr) ? std::string(name).c_str() : "", MAX_CREDENTIALS_STR_LEN); + strlcpy(usr.homedir, (home.data() != nullptr) ? std::string(home).c_str() : "", SCAP_MAX_PATH_SIZE); + strlcpy(usr.shell, (shell.data() != nullptr) ? std::string(shell).c_str() : "", SCAP_MAX_PATH_SIZE); return &usr; } @@ -265,18 +261,16 @@ scap_userinfo *sinsp_usergroup_manager::userinfo_map_insert( scap_groupinfo *sinsp_usergroup_manager::groupinfo_map_insert( groupinfo_map &map, uint32_t gid, - const char *name) + std::string_view name) { - ASSERT(name); - auto &grp = map[gid]; grp.gid = gid; - strlcpy(grp.name, (name != nullptr) ? name : "", MAX_CREDENTIALS_STR_LEN); + strlcpy(grp.name, (name.data() != nullptr) ? std::string(name).c_str() : "", MAX_CREDENTIALS_STR_LEN); return &grp; } -scap_userinfo *sinsp_usergroup_manager::add_user(const string &container_id, int64_t pid, uint32_t uid, uint32_t gid, const char *name, const char *home, const char *shell, bool notify) +scap_userinfo *sinsp_usergroup_manager::add_user(const std::string &container_id, int64_t pid, uint32_t uid, uint32_t gid, std::string_view name, std::string_view home, std::string_view shell, bool notify) { if (!m_import_users) { @@ -289,11 +283,11 @@ scap_userinfo *sinsp_usergroup_manager::add_user(const string &container_id, int if(usr) { // Update user if it was already there - if (name) + if (name.data() != nullptr) { - strlcpy(usr->name, name, MAX_CREDENTIALS_STR_LEN); - strlcpy(usr->homedir, home, SCAP_MAX_PATH_SIZE); - strlcpy(usr->shell, shell, SCAP_MAX_PATH_SIZE); + strlcpy(usr->name, std::string(name).c_str(), MAX_CREDENTIALS_STR_LEN); + strlcpy(usr->homedir, std::string(home).c_str(), SCAP_MAX_PATH_SIZE); + strlcpy(usr->shell, std::string(shell).c_str(), SCAP_MAX_PATH_SIZE); } return usr; } @@ -305,13 +299,13 @@ scap_userinfo *sinsp_usergroup_manager::add_user(const string &container_id, int return add_container_user(container_id, pid, uid, notify); } -scap_userinfo *sinsp_usergroup_manager::add_host_user(uint32_t uid, uint32_t gid, const char *name, const char *home, const char *shell, bool notify) +scap_userinfo *sinsp_usergroup_manager::add_host_user(uint32_t uid, uint32_t gid, std::string_view name, std::string_view home, std::string_view shell, bool notify) { libsinsp_logger()->format(sinsp_logger::SEV_DEBUG, "adding host user: name: %s", name); scap_userinfo *retval{nullptr}; - if (name) + if (name.data() != nullptr) { retval = userinfo_map_insert( m_userlist[""], @@ -411,7 +405,7 @@ bool sinsp_usergroup_manager::rm_user(const string &container_id, uint32_t uid, return res; } -scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, int64_t pid, uint32_t gid, const char *name, bool notify) +scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, int64_t pid, uint32_t gid, std::string_view name, bool notify) { if (!m_import_users) { @@ -423,9 +417,9 @@ scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, i if (gr) { // Update group if it was already there - if (name != nullptr) + if (name.data() != nullptr) { - strlcpy(gr->name, name, MAX_CREDENTIALS_STR_LEN); + strlcpy(gr->name, std::string(name).c_str(), MAX_CREDENTIALS_STR_LEN); } return gr; } @@ -437,13 +431,13 @@ scap_groupinfo *sinsp_usergroup_manager::add_group(const string &container_id, i return add_container_group(container_id, pid, gid, notify); } -scap_groupinfo *sinsp_usergroup_manager::add_host_group(uint32_t gid, const char *name, bool notify) +scap_groupinfo *sinsp_usergroup_manager::add_host_group(uint32_t gid, std::string_view name, bool notify) { libsinsp_logger()->format(sinsp_logger::SEV_DEBUG, "adding host group: name: %s", name); scap_groupinfo *gr = nullptr; - if (name) + if (name.data()) { gr = groupinfo_map_insert(m_grouplist[""], gid, name); } diff --git a/userspace/libsinsp/user.h b/userspace/libsinsp/user.h index 0c883bb493..fd939affd6 100644 --- a/userspace/libsinsp/user.h +++ b/userspace/libsinsp/user.h @@ -121,8 +121,8 @@ class sinsp_usergroup_manager // Note: pid is an unused parameter when container_id is an empty string // ie: it is only used when adding users/groups from containers. - scap_userinfo *add_user(const std::string &container_id, int64_t pid, uint32_t uid, uint32_t gid, const char *name, const char *home, const char *shell, bool notify = false); - scap_groupinfo *add_group(const std::string &container_id, int64_t pid, uint32_t gid, const char *name, bool notify = false); + scap_userinfo *add_user(const std::string &container_id, int64_t pid, uint32_t uid, uint32_t gid, std::string_view name, std::string_view home, std::string_view shell, bool notify = false); + scap_groupinfo *add_group(const std::string &container_id, int64_t pid, uint32_t gid, std::string_view name, bool notify = false); bool rm_user(const std::string &container_id, uint32_t uid, bool notify = false); bool rm_group(const std::string &container_id, uint32_t gid, bool notify = false); @@ -135,10 +135,10 @@ class sinsp_usergroup_manager bool m_import_users; private: - scap_userinfo *add_host_user(uint32_t uid, uint32_t gid, const char *name, const char *home, const char *shell, bool notify); + scap_userinfo *add_host_user(uint32_t uid, uint32_t gid, std::string_view name, std::string_view home, std::string_view shell, bool notify); scap_userinfo *add_container_user(const std::string &container_id, int64_t pid, uint32_t uid, bool notify); - scap_groupinfo *add_host_group(uint32_t gid, const char *name, bool notify); + scap_groupinfo *add_host_group(uint32_t gid, std::string_view name, bool notify); scap_groupinfo *add_container_group(const std::string &container_id, int64_t pid, uint32_t gid, bool notify); bool user_to_sinsp_event(const scap_userinfo *user, sinsp_evt* evt, const std::string &container_id, uint16_t ev_type); @@ -156,13 +156,14 @@ class sinsp_usergroup_manager userinfo_map &map, uint32_t uid, uint32_t gid, - const char *name, - const char *home, - const char *shell); + std::string_view name, + std::string_view home, + std::string_view shell); + scap_groupinfo *groupinfo_map_insert( groupinfo_map &map, uint32_t gid, - const char *name); + std::string_view name); std::unordered_map m_userlist; std::unordered_map m_grouplist;