]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Keep auth_request_fields const for most of the code
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 3 Aug 2020 15:51:33 +0000 (18:51 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 27 Aug 2020 06:20:17 +0000 (06:20 +0000)
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.

src/auth/auth-request-fields.c
src/auth/auth-request.h
src/auth/test-auth.h

index 18781398b04d0393661084ecc8c644c73ace7e44..0b85c04628c8244eb0aa7f59019d77be8253c05a 100644 (file)
@@ -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"
index 55506188e6e8ec6b1422d478b510f1815854781a..9a1f2cd55cfcb5201c5b5fb604459a008d230ef6 100644 (file)
@@ -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;
index 413fb3650ae4f6f7727e1f0a1b382891d4fd386e..849dceb302b299f538e82f9f80c09dab60b8d2ed 100644 (file)
@@ -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"