Skip to content

Commit e0d912d

Browse files
committed
Use C99 designated struct initializers.
This is less error-prone and would have avoided GitHub issue #325.
1 parent 45aeedd commit e0d912d

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

plugins/sudoers/sudoers.h

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ struct group_list {
7878

7979
/*
8080
* Parse configuration settings.
81-
* Do not change the order without updating SUDOERS_PARSER_CONFIG_INITIALIZER.
8281
*/
8382
struct sudoers_parser_config {
8483
const char *sudoers_path;
@@ -91,26 +90,30 @@ struct sudoers_parser_config {
9190
gid_t sudoers_gid;
9291
};
9392
#define SUDOERS_PARSER_CONFIG_INITIALIZER { \
94-
NULL, /* sudoers_path */ \
95-
false, /* strict */ \
96-
1, /* verbose level 1 */ \
97-
true, /* recovery */ \
98-
false, /* ignore_perms */ \
99-
SUDOERS_MODE, \
100-
SUDOERS_UID, \
101-
SUDOERS_GID \
93+
.sudoers_path = NULL, \
94+
.strict = false, \
95+
.verbose = 1, \
96+
.recovery = true, \
97+
.ignore_perms = false, \
98+
.sudoers_mode = SUDOERS_MODE, \
99+
.sudoers_uid = SUDOERS_UID, \
100+
.sudoers_gid = SUDOERS_GID \
102101
}
103102

104103
/*
105104
* Settings passed in from the sudo front-end.
106-
* Do not change the order without updating SUDOERS_CONTEXT_INITIALIZER.
107105
*/
108106
struct sudoers_plugin_settings {
109107
const char *plugin_dir;
110108
const char *ldap_conf;
111109
const char *ldap_secret;
112110
unsigned int flags;
113111
};
112+
#define SUDOERS_PLUGIN_SETTINGS_INITIALIZER { \
113+
.plugin_dir = _PATH_SUDO_PLUGIN_DIR, \
114+
.ldap_conf = _PATH_LDAP_CONF, \
115+
.ldap_secret = _PATH_LDAP_SECRET \
116+
}
114117

115118
/*
116119
* Info pertaining to the invoking user.
@@ -183,11 +186,6 @@ struct sudoers_runas_context {
183186
#endif
184187
};
185188

186-
#define SUDOERS_CONTEXT_INITIALIZER { \
187-
SUDOERS_PARSER_CONFIG_INITIALIZER, \
188-
{ _PATH_SUDO_PLUGIN_DIR, _PATH_LDAP_CONF, _PATH_LDAP_SECRET } \
189-
}
190-
191189
/*
192190
* Global configuration for the sudoers module.
193191
*/
@@ -205,6 +203,10 @@ struct sudoers_context {
205203
unsigned int mode;
206204
char uuid_str[37];
207205
};
206+
#define SUDOERS_CONTEXT_INITIALIZER { \
207+
SUDOERS_PARSER_CONFIG_INITIALIZER, \
208+
SUDOERS_PLUGIN_SETTINGS_INITIALIZER, \
209+
}
208210

209211
/*
210212
* sudo_get_gidlist() type values

0 commit comments

Comments
 (0)