From 3d8cf815e6b152afcefe7078b8349c68350dade9 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Mon, 3 May 2021 08:02:27 -0500 Subject: [PATCH 1/2] Add function to find and return a host from a host list. (cherry picked from commit e863f7d31891bf593f7ab06fba3ed8b937bca486) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ base/hosts.c | 40 ++++++++++++++++++++++++++++++---------- base/hosts.h | 4 ++++ 3 files changed, 86 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3826ce3cd..465a62be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,58 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +<<<<<<< HEAD +======= +## [21.04.1] (unreleased) + +### Added +- Possibility to use lcrypt with `$6$` (sha512) for authentication [484](https://github.com/greenbone/gvm-libs/pull/484) +- Add function to find and return a host from a host list. [490](https://github.com/greenbone/gvm-libs/pull/490) + +### Changed +### Fixed +- Unify GLib log domains [#479](https://github.com/greenbone/gvm-libs/pull/479) + +### Removed + +[21.04.1]: https://github.com/greenbone/gvm-libs/compare/v21.4.0...gvm-libs-21.04 + + +## [21.04.0] (2021-04-15) + +### Added +- Use dedicated port list for alive detection (Boreas only) if supplied via OSP. [#391](https://github.com/greenbone/gvm-libs/pull/391) +- Allow to re allocate the finish flag in the host queue for alive tests. + [#407](https://github.com/greenbone/gvm-libs/pull/407) + [#410](https://github.com/greenbone/gvm-libs/pull/410) +- Add multiple severities for nvti [#317](https://github.com/greenbone/gvm-libs/pull/317) [#472](https://github.com/greenbone/gvm-libs/pull/472) +- Add support for new OSP element for defining alive test methods via separate subelements. [#409](https://github.com/greenbone/gvm-libs/pull/409) +- Add v3 handling to get_cvss_score_from_base_metrics. [#411](https://github.com/greenbone/gvm-libs/pull/411) +- Add severity_date tag in epoch time format. [#412](https://github.com/greenbone/gvm-libs/pull/412) +- Make more scanner preferences available to openvas-nasl. [#413](https://github.com/greenbone/gvm-libs/pull/413) +- Use memory purge redis command when initializing new kb. [#452](https://github.com/greenbone/gvm-libs/pull/452) + +### Changed +- Add separators for a new (ip address) field in ERRMSG and DEADHOST messages. [#376](https://github.com/greenbone/gvm-libs/pull/376) +- Continuously send dead hosts to ospd-openvas to enable a smooth progress bar if only ICMP is chosen as alive test. [#389](https://github.com/greenbone/gvm-libs/pull/389) +- Retry if response via tls1.3 is still not received. [#394](https://github.com/greenbone/gvm-libs/pull/394) +- Replace current implementation of alive test arp ping with version using libnet. [#423](https://github.com/greenbone/gvm-libs/pull/423) +- Let setup_log_handlers return an error if it does not have write access to some log file or log dir instead of aborting immediately. + [#447](https://github.com/greenbone/gvm-libs/pull/447) + [#451](https://github.com/greenbone/gvm-libs/pull/451) +- Fix openvas preference name. The option was rename to "allow_simultaneous_ips". [#461](https://github.com/greenbone/gvm-libs/pull/461) +- Do not start the sniffer thread when only consider alive is chosen for alive test. [#466](https://github.com/greenbone/gvm-libs/pull/466)] + +### Fixed +- Fix finish_signal_on_queue for boreas. [#464](https://github.com/greenbone/gvm-libs/pull/464) + +### Removed +- Remove handling of severity class from auth [#402](https://github.com/greenbone/gvm-libs/pull/402) +- Remove version from the nvticache name. [#386](https://github.com/greenbone/gvm-libs/pull/386) + +[21.04.0]: https://github.com/greenbone/gvm-libs/compare/gvm-libs-20.08...v21.4.0 + +>>>>>>> e863f7d... Add function to find and return a host from a host list. ## [20.8.2] (unreleased) ### Added diff --git a/base/hosts.c b/base/hosts.c index 502e4a2d0..aae2e43fd 100644 --- a/base/hosts.c +++ b/base/hosts.c @@ -1899,26 +1899,24 @@ gvm_hosts_duplicated (const gvm_hosts_t *hosts) } /** - * @brief Returns whether a host has an equal host in a hosts collection. - * eg. 192.168.10.1 has an equal in list created from - * "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't. + * @brief Find the gvm_host_t from a gvm_hosts_t structure. * * @param[in] host The host object. * @param[in] addr Optional pointer to ip address. Could be used so that host * isn't resolved multiple times when type is HOST_TYPE_NAME. * @param[in] hosts Hosts collection. * - * @return 1 if host has equal in hosts, 0 otherwise. + * @return Pointer to host if found. NULL if error or host not found */ -int -gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr, - const gvm_hosts_t *hosts) +gvm_host_t * +gvm_host_find_in_hosts (const gvm_host_t *host, const struct in6_addr *addr, + const gvm_hosts_t *hosts) { char *host_str; size_t i; if (host == NULL || hosts == NULL) - return 0; + return NULL; host_str = gvm_host_value_str (host); @@ -1931,7 +1929,7 @@ gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr, { g_free (host_str); g_free (tmp); - return 1; + return current_host; } g_free (tmp); @@ -1944,12 +1942,34 @@ gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr, if (memcmp (addr->s6_addr, &tmpaddr.s6_addr, 16) == 0) { g_free (host_str); - return 1; + return current_host; } } } g_free (host_str); + return NULL; +} + +/** + * @brief Returns whether a host has an equal host in a hosts collection. + * eg. 192.168.10.1 has an equal in list created from + * "192.168.10.1-5, 192.168.10.10-20" string while 192.168.10.7 doesn't. + * + * @param[in] host The host object. + * @param[in] addr Optional pointer to ip address. Could be used so that host + * isn't resolved multiple times when type is HOST_TYPE_NAME. + * @param[in] hosts Hosts collection. + * + * @return 1 if host has equal in hosts, 0 otherwise. + */ +int +gvm_host_in_hosts (const gvm_host_t *host, const struct in6_addr *addr, + const gvm_hosts_t *hosts) +{ + if (gvm_host_find_in_hosts (host, addr, hosts)) + return 1; + return 0; } diff --git a/base/hosts.h b/base/hosts.h index d6859f9af..91b19337f 100644 --- a/base/hosts.h +++ b/base/hosts.h @@ -162,6 +162,10 @@ int gvm_host_in_hosts (const gvm_host_t *, const struct in6_addr *, const gvm_hosts_t *); +gvm_host_t * +gvm_host_find_in_hosts (const gvm_host_t *, const struct in6_addr *, + const gvm_hosts_t *); + gchar * gvm_host_type_str (const gvm_host_t *); From ab1f9ef4c781bee7921b2b0a482ce96d7a224326 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Tue, 4 May 2021 16:02:53 +0200 Subject: [PATCH 2/2] Fix conflicts in changelog --- CHANGELOG.md | 53 +--------------------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 465a62be8..462c9edb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,58 +4,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -<<<<<<< HEAD -======= -## [21.04.1] (unreleased) - -### Added -- Possibility to use lcrypt with `$6$` (sha512) for authentication [484](https://github.com/greenbone/gvm-libs/pull/484) -- Add function to find and return a host from a host list. [490](https://github.com/greenbone/gvm-libs/pull/490) - -### Changed -### Fixed -- Unify GLib log domains [#479](https://github.com/greenbone/gvm-libs/pull/479) - -### Removed - -[21.04.1]: https://github.com/greenbone/gvm-libs/compare/v21.4.0...gvm-libs-21.04 - - -## [21.04.0] (2021-04-15) - -### Added -- Use dedicated port list for alive detection (Boreas only) if supplied via OSP. [#391](https://github.com/greenbone/gvm-libs/pull/391) -- Allow to re allocate the finish flag in the host queue for alive tests. - [#407](https://github.com/greenbone/gvm-libs/pull/407) - [#410](https://github.com/greenbone/gvm-libs/pull/410) -- Add multiple severities for nvti [#317](https://github.com/greenbone/gvm-libs/pull/317) [#472](https://github.com/greenbone/gvm-libs/pull/472) -- Add support for new OSP element for defining alive test methods via separate subelements. [#409](https://github.com/greenbone/gvm-libs/pull/409) -- Add v3 handling to get_cvss_score_from_base_metrics. [#411](https://github.com/greenbone/gvm-libs/pull/411) -- Add severity_date tag in epoch time format. [#412](https://github.com/greenbone/gvm-libs/pull/412) -- Make more scanner preferences available to openvas-nasl. [#413](https://github.com/greenbone/gvm-libs/pull/413) -- Use memory purge redis command when initializing new kb. [#452](https://github.com/greenbone/gvm-libs/pull/452) - -### Changed -- Add separators for a new (ip address) field in ERRMSG and DEADHOST messages. [#376](https://github.com/greenbone/gvm-libs/pull/376) -- Continuously send dead hosts to ospd-openvas to enable a smooth progress bar if only ICMP is chosen as alive test. [#389](https://github.com/greenbone/gvm-libs/pull/389) -- Retry if response via tls1.3 is still not received. [#394](https://github.com/greenbone/gvm-libs/pull/394) -- Replace current implementation of alive test arp ping with version using libnet. [#423](https://github.com/greenbone/gvm-libs/pull/423) -- Let setup_log_handlers return an error if it does not have write access to some log file or log dir instead of aborting immediately. - [#447](https://github.com/greenbone/gvm-libs/pull/447) - [#451](https://github.com/greenbone/gvm-libs/pull/451) -- Fix openvas preference name. The option was rename to "allow_simultaneous_ips". [#461](https://github.com/greenbone/gvm-libs/pull/461) -- Do not start the sniffer thread when only consider alive is chosen for alive test. [#466](https://github.com/greenbone/gvm-libs/pull/466)] - -### Fixed -- Fix finish_signal_on_queue for boreas. [#464](https://github.com/greenbone/gvm-libs/pull/464) - -### Removed -- Remove handling of severity class from auth [#402](https://github.com/greenbone/gvm-libs/pull/402) -- Remove version from the nvticache name. [#386](https://github.com/greenbone/gvm-libs/pull/386) - -[21.04.0]: https://github.com/greenbone/gvm-libs/compare/gvm-libs-20.08...v21.4.0 - ->>>>>>> e863f7d... Add function to find and return a host from a host list. ## [20.8.2] (unreleased) ### Added @@ -63,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Ensure that new kb taken by the scanner are always clean. [#469](https://github.com/greenbone/gvm-libs/pull/469) - Validate for max_scan_hosts scanner preference. [#482](https://github.com/greenbone/gvm-libs/pull/482) - Possibility to use lcrypt with `$6$` (sha512) for authentication [484](https://github.com/greenbone/gvm-libs/pull/484) +- Add function to find and return a host from a host list. Backport of [PR 490](https://github.com/greenbone/gvm-libs/pull/490). [494](https://github.com/greenbone/gvm-libs/pull/494). ### Changed Use a char pointer instead of an zero-lenght array as kb_redis struct member. [443](https://github.com/greenbone/gvm-libs/pull/443)