From: Timo Sirainen Date: Mon, 3 Aug 2020 15:51:33 +0000 (+0300) Subject: auth: Keep auth_request_fields const for most of the code X-Git-Tag: 2.3.13~310 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97749d387f8098575c2e71dcc2c407bc627d17a1;p=thirdparty%2Fdovecot%2Fcore.git auth: Keep auth_request_fields const for most of the code This way there's a compiler warning/error if anything outside auth-request-fields.c attempts to modify them. It makes it easier to keep the values synced with events. --- diff --git a/src/auth/auth-request-fields.c b/src/auth/auth-request-fields.c index 18781398b0..0b85c04628 100644 --- a/src/auth/auth-request-fields.c +++ b/src/auth/auth-request-fields.c @@ -1,5 +1,7 @@ /* Copyright (c) 2002-2020 Dovecot authors, see the included COPYING file */ +#define AUTH_REQUEST_FIELDS_CONST + #include "auth-common.h" #include "str.h" #include "strescape.h" diff --git a/src/auth/auth-request.h b/src/auth/auth-request.h index 55506188e6..9a1f2cd55c 100644 --- a/src/auth/auth-request.h +++ b/src/auth/auth-request.h @@ -1,6 +1,10 @@ #ifndef AUTH_REQUEST_H #define AUTH_REQUEST_H +#ifndef AUTH_REQUEST_FIELDS_CONST +# define AUTH_REQUEST_FIELDS_CONST const +#endif + #include "array.h" #include "net.h" #include "var-expand.h" @@ -121,7 +125,11 @@ struct auth_request { time_t delay_until; pid_t session_pid; - struct auth_request_fields fields; + /* These are const for most of the code, so they don't try to modify + the fields directly. Only auth-request-fields.c and unit tests have + the fields writable. This way it's more difficult to make them + out-of-sync with events. */ + AUTH_REQUEST_FIELDS_CONST struct auth_request_fields fields; struct timeout *to_abort, *to_penalty; unsigned int policy_penalty; diff --git a/src/auth/test-auth.h b/src/auth/test-auth.h index 413fb3650a..849dceb302 100644 --- a/src/auth/test-auth.h +++ b/src/auth/test-auth.h @@ -3,6 +3,8 @@ #ifndef TEST_AUTH_H #define TEST_AUTH_H 1 +#define AUTH_REQUEST_FIELDS_CONST + #include "lib.h" #include "test-common.h"