Skip to content

Commit 3c80b29

Browse files
authored
Merge branch 'main' into builtin-notus
2 parents 782fac0 + 3e9e42b commit 3c80b29

File tree

49 files changed

+2646
-1931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2646
-1931
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ message ("-- Configuring the Scanner...")
88

99
# VERSION: Always include major, minor and patch level.
1010
project (openvas
11-
VERSION 23.40.4
11+
VERSION 23.41.2
1212
LANGUAGES C)
1313

1414
if (POLICY CMP0005)

charts/openvasd/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ version: 0.1.0
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "23.40.4"
24+
appVersion: "23.41.2"

misc/openvas-krb5.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,14 @@ okrb5_gss_free_context (struct OKrb5GSSContext *context)
413413
}
414414
if (context->gss_ctx != GSS_C_NO_CONTEXT)
415415
{
416-
gss_delete_sec_context (&min_stat, &context->gss_ctx, GSS_C_NO_BUFFER);
416+
gss_delete_sec_context (&min_stat, &context->gss_ctx,
417+
GSS_C_NO_BUFFER);
417418
}
418419
if (context->gss_target != GSS_C_NO_NAME)
419420
{
420421
gss_release_name (&min_stat, &context->gss_target);
421422
}
422-
if (context->gss_mech != NULL)
423+
if (context->gss_mech != NULL && context->gss_mech != gss_mech_spnego)
423424
{
424425
gss_release_oid (&min_stat, &context->gss_mech);
425426
}
@@ -482,7 +483,7 @@ o_krb5_gss_prepare_context (const OKrb5Credential *creds,
482483
(char *) target->host_name.data, (char *) creds->realm.data);
483484
}
484485

485-
targetbuf = (gss_buffer_desc){
486+
targetbuf = (gss_buffer_desc) {
486487
.value = target_principal_str,
487488
.length = strlen (target_principal_str),
488489
};

nasl/exec.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "nasl_func.h"
1616
#include "nasl_global_ctxt.h"
1717
#include "nasl_init.h"
18+
#include "nasl_krb5.h" /* for nasl_okrb5_clean */
1819
#include "nasl_lex_ctxt.h"
1920
#include "nasl_tree.h"
2021
#include "nasl_var.h"
@@ -1706,7 +1707,7 @@ exec_nasl_script (struct script_infos *script_infos, int mode)
17061707
}
17071708
else if (!(mode & NASL_EXEC_PARSE_ONLY))
17081709
{
1709-
char *p;
1710+
char *p, *name_aux;
17101711

17111712
bzero (&tc, sizeof (tc));
17121713
tc.type = CONST_INT;
@@ -1719,14 +1720,18 @@ exec_nasl_script (struct script_infos *script_infos, int mode)
17191720
add_named_var_to_ctxt (lexic, "description", &tc);
17201721

17211722
tc.type = CONST_DATA;
1722-
p = strrchr (name, '/');
1723+
// for preserving the const qualifier during assginment
1724+
name_aux = g_strdup (name);
1725+
p = strrchr (name_aux, '/');
17231726
if (p == NULL)
1724-
p = (char *) name;
1727+
p = (char *) name_aux;
17251728
else
17261729
p++;
1730+
17271731
tc.x.str_val = p;
17281732
tc.size = strlen (p);
17291733
add_named_var_to_ctxt (lexic, "SCRIPT_NAME", &tc);
1734+
g_free (name_aux);
17301735

17311736
truc = (lex_ctxt *) ctx.tree;
17321737
if ((ret = nasl_exec (lexic, ctx.tree)) == NULL)
@@ -1736,6 +1741,7 @@ exec_nasl_script (struct script_infos *script_infos, int mode)
17361741

17371742
if ((pf = get_func_ref_by_name (lexic, "on_exit")) != NULL)
17381743
nasl_func_call (lexic, pf, NULL);
1744+
17391745
}
17401746

17411747
if (g_chdir (old_dir) != 0)
@@ -1745,6 +1751,7 @@ exec_nasl_script (struct script_infos *script_infos, int mode)
17451751
}
17461752
g_free (old_dir);
17471753

1754+
nasl_okrb5_clean ();
17481755
nasl_clean_ctx (&ctx);
17491756
free_lex_ctxt (lexic);
17501757
return err;

nasl/nasl_krb5.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
#include "nasl_tree.h"
1313
#include "nasl_var.h"
1414

15+
#include <gvm/base/networking.h>
16+
#include <netinet/in.h>
1517
#include <stdio.h>
18+
#include <string.h>
19+
#include <unistd.h>
1620

1721
#define NASL_PRINT_KRB_ERROR(lexic, credential, result) \
1822
do \
@@ -35,19 +39,22 @@ static OKrb5ErrorCode last_okrb5_result;
3539
// cached_gss_context is used on cases that require an already existing session.
3640
// NASL does currently not have the concept of a pointer nor struct so we need
3741
// to store it as a global variable.
38-
//
42+
//
3943
// We use one context per run, this means that per run (target + oid) there is
4044
// only on credential allowed making it safe to be cached in that fashion.
4145
static struct OKrb5GSSContext *cached_gss_context = NULL;
4246

43-
// Is used for `krb5_gss_update_context_out` and is essential a
44-
// cache for the data from `krb5_gss_update_context`.
47+
// Is used for `krb5_gss_update_context_out` and is essential a
48+
// cache for the data from `krb5_gss_update_context`.
4549
static struct OKrb5Slice *to_application = NULL;
4650

4751
// Is used for `krb5_gss_update_context_needs_more` which indicates to the
48-
// script author that `krb5_gss_update_context` is not satisfied yet.
52+
// script author that `krb5_gss_update_context` is not satisfied yet.
4953
static bool gss_update_context_more = false;
5054

55+
// Stores the path to the generated krb5 config file for cleanup.
56+
static char *generated_config_path = NULL;
57+
5158
#define SET_SLICE_FROM_LEX_OR_ENV(lexic, slice, name, env_name) \
5259
do \
5360
{ \
@@ -56,6 +63,10 @@ static bool gss_update_context_more = false;
5663
{ \
5764
okrb5_set_slice_from_str (slice, getenv (env_name)); \
5865
} \
66+
else \
67+
{ \
68+
setenv (env_name, get_str_var_by_name (lexic, name), 1); \
69+
} \
5970
} \
6071
while (0)
6172

@@ -71,7 +82,6 @@ static bool gss_update_context_more = false;
7182
} \
7283
while (0)
7384

74-
7585
static OKrb5Credential
7686
build_krb5_credential (lex_ctxt *lexic)
7787
{
@@ -84,9 +94,27 @@ build_krb5_credential (lex_ctxt *lexic)
8494
"KRB5_CONFIG");
8595
if (credential.config_path.len == 0)
8696
{
87-
okrb5_set_slice_from_str (credential.config_path, "/etc/krb5.conf");
97+
char *ip_str = addr6_as_str (lexic->script_infos->ip);
98+
for (int i = 0; ip_str[i] != '\0'; i++)
99+
{
100+
if (ip_str[i] == '.' || ip_str[i] == ':')
101+
{
102+
ip_str[i] = '_';
103+
}
104+
}
105+
char default_config_path[256];
106+
snprintf (default_config_path, sizeof (default_config_path),
107+
"/tmp/krb5_%s.conf", ip_str);
108+
setenv ("KRB5_CONFIG", default_config_path, 1);
109+
okrb5_set_slice_from_str (credential.config_path, default_config_path);
88110
}
89111

112+
// Store path for cleanup
113+
if (generated_config_path != NULL)
114+
free (generated_config_path);
115+
generated_config_path =
116+
strndup (credential.config_path.data, credential.config_path.len);
117+
90118
PERROR_SET_SLICE_FROM_LEX_OR_ENV (lexic, credential.realm, "realm",
91119
"KRB5_REALM");
92120
PERROR_SET_SLICE_FROM_LEX_OR_ENV (lexic, credential.kdc, "kdc", "KRB5_KDC");
@@ -240,7 +268,6 @@ nasl_okrb5_is_failure (lex_ctxt *lexic)
240268
return retc;
241269
}
242270

243-
244271
tree_cell *
245272
nasl_okrb5_gss_init (lex_ctxt *lexic)
246273
{
@@ -277,7 +304,6 @@ nasl_okrb5_gss_prepare_context (lex_ctxt *lexic)
277304
return retc;
278305
}
279306

280-
281307
tree_cell *
282308
nasl_okrb5_gss_update_context (lex_ctxt *lexic)
283309
{
@@ -322,6 +348,13 @@ nasl_okrb5_clean (void)
322348
if (cached_gss_context != NULL)
323349
{
324350
okrb5_gss_free_context (cached_gss_context);
351+
cached_gss_context = NULL;
352+
}
353+
if (generated_config_path != NULL)
354+
{
355+
unlink (generated_config_path);
356+
free (generated_config_path);
357+
generated_config_path = NULL;
325358
}
326359
}
327360

rust/crates/greenbone-scanner-framework/src/entry/response/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ macro_rules! internal_server_error {
4242
}};
4343
}
4444

45-
pub type StreamResult<'a, T, E> = Box<dyn Stream<Item = Result<T, E>> + Unpin + Send + 'a>;
45+
pub type StreamResult<T, E> = Pin<Box<dyn Stream<Item = Result<T, E>> + Send>>;
4646

4747
pub trait BodyKindError {
4848
fn into_body_kind(self) -> BodyKind;
@@ -100,7 +100,7 @@ impl BodyKind {
100100
/// If it is an empty stgream it will return an BodyKind::Stream with an empty stream
101101
pub async fn from_result_stream<T, E>(
102102
status_code: StatusCode,
103-
mut input: StreamResult<'static, T, E>,
103+
mut input: StreamResult<T, E>,
104104
) -> Self
105105
where
106106
T: Default + serde::Serialize + Send + 'static,

rust/crates/greenbone-scanner-framework/src/get_scans.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
};
1313

1414
pub trait GetScans: Send + Sync {
15-
fn get_scans(&self, client_id: String) -> StreamResult<'static, String, GetScansError>;
15+
fn get_scans(&self, client_id: String) -> StreamResult<String, GetScansError>;
1616
}
1717

1818
pub struct GetScansHandler<T> {
@@ -110,6 +110,7 @@ impl From<GetScansError> for BodyKind {
110110

111111
#[cfg(test)]
112112
mod tests {
113+
113114
use entry::test_utilities;
114115
use futures::stream;
115116
use http_body_util::{BodyExt, Empty};
@@ -127,15 +128,15 @@ mod tests {
127128
}
128129

129130
impl GetScans for Test {
130-
fn get_scans(&self, client_id: String) -> StreamResult<'static, String, GetScansError> {
131+
fn get_scans(&self, client_id: String) -> StreamResult<String, GetScansError> {
131132
let ise = ClientHash::from("internal_server_error").to_string();
132133
if ise == client_id {
133-
return Box::new(stream::iter(vec![Err(GetScansError::External(Box::new(
134+
return Box::pin(stream::iter(vec![Err(GetScansError::External(Box::new(
134135
io::Error::other("oh no"),
135136
)))]));
136137
}
137138

138-
Box::new(stream::iter(vec![Ok(String::default())]))
139+
Box::pin(stream::iter(vec![Ok(String::default())]))
139140
}
140141
}
141142

rust/crates/greenbone-scanner-framework/src/get_scans_id.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::{
1212
};
1313

1414
pub trait GetScansId: MapScanID {
15-
fn get_scans_id(
16-
&self,
15+
fn get_scans_id<'a>(
16+
&'a self,
1717
id: String,
18-
) -> Pin<Box<dyn Future<Output = Result<models::Scan, GetScansIDError>> + Send + '_>>;
18+
) -> Pin<Box<dyn Future<Output = Result<models::Scan, GetScansIDError>> + Send + 'a>>;
1919
}
2020

2121
pub struct GetScansIdHandler<T> {

rust/crates/greenbone-scanner-framework/src/get_scans_id_results.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub trait GetScansIdResults: MapScanID {
1717
id: String,
1818
from: Option<usize>,
1919
to: Option<usize>,
20-
) -> StreamResult<'static, models::Result, GetScansIDResultsError>;
20+
) -> StreamResult<models::Result, GetScansIDResultsError>;
2121
}
2222

2323
pub struct GetScansIdResultsHandler<T> {
@@ -163,10 +163,10 @@ mod tests {
163163
client_id: String,
164164
from: Option<usize>,
165165
to: Option<usize>,
166-
) -> StreamResult<'static, models::Result, GetScansIDResultsError> {
166+
) -> StreamResult<models::Result, GetScansIDResultsError> {
167167
let ise = ClientHash::from("internal_server_error").to_string();
168168
if ise == client_id {
169-
return Box::new(stream::iter(vec![Err(GetScansError::External(Box::new(
169+
return Box::pin(stream::iter(vec![Err(GetScansError::External(Box::new(
170170
io::Error::other("oh no"),
171171
)))]));
172172
}
@@ -186,7 +186,7 @@ mod tests {
186186
})
187187
.collect();
188188

189-
Box::new(stream::iter(result))
189+
Box::pin(stream::iter(result))
190190
}
191191
}
192192

rust/crates/greenbone-scanner-framework/src/get_vts.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::{
1010
};
1111

1212
pub trait GetVts: Send + Sync {
13-
fn get_oids(&self, client_id: String) -> StreamResult<'static, String, GetVTsError>;
13+
fn get_oids(&self, client_id: String) -> StreamResult<String, GetVTsError>;
1414

15-
fn get_vts(&self, client_id: String) -> StreamResult<'static, VTData, GetVTsError>;
15+
fn get_vts(&self, client_id: String) -> StreamResult<VTData, GetVTsError>;
1616
}
1717

1818
pub struct GetVTsHandler<T> {
@@ -127,7 +127,7 @@ mod tests {
127127
}
128128

129129
impl GetVts for Test {
130-
fn get_oids(&self, client_id: String) -> StreamResult<'static, String, GetVTsError> {
130+
fn get_oids(&self, client_id: String) -> StreamResult<String, GetVTsError> {
131131
let ok = ClientHash::from("ok").to_string();
132132
let not_found = ClientHash::from("not_found").to_string();
133133
let unknown = "unknown".to_string();
@@ -141,11 +141,11 @@ mod tests {
141141
))))]
142142
};
143143
//stream::iter(result)
144-
Box::new(stream::iter(result))
144+
Box::pin(stream::iter(result))
145145
}
146146

147-
fn get_vts(&self, _: String) -> StreamResult<'static, VTData, GetVTsError> {
148-
Box::new(stream::iter(vec![Ok(VTData::default())]))
147+
fn get_vts(&self, _: String) -> StreamResult<VTData, GetVTsError> {
148+
Box::pin(stream::iter(vec![Ok(VTData::default())]))
149149
}
150150
}
151151

0 commit comments

Comments
 (0)