@@ -175,16 +175,20 @@ sudoers_reinit_defaults(struct sudoers_context *ctx)
175175 debug_return_bool (true);
176176}
177177
178+ /*
179+ * Initialize sudoers data structures and parse sudoers sources.
180+ * Returns 1 on success and -1 on error.
181+ */
178182int
179183sudoers_init (void * info , sudoers_logger_t logger , char * const envp [])
180184{
181185 struct sudo_nss * nss , * nss_next ;
182186 int oldlocale , sources = 0 ;
183- static int ret = -1 ;
187+ static int ret = 0 ;
184188 debug_decl (sudoers_init , SUDOERS_DEBUG_PLUGIN );
185189
186- /* Only initialize once. */
187- if (snl != NULL )
190+ /* Only initialize once, don't re-initialize on error (-1) . */
191+ if (ret != 0 )
188192 debug_return_int (ret );
189193
190194 bindtextdomain ("sudoers" , LOCALEDIR );
@@ -197,29 +201,29 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
197201
198202 /* Initialize environment functions (including replacements). */
199203 if (!env_init (envp ))
200- debug_return_int ( -1 ) ;
204+ goto done ;
201205
202206 /* Setup defaults data structures. */
203207 if (!init_defaults ()) {
204208 sudo_warnx ("%s" , U_ ("unable to initialize sudoers default values" ));
205- debug_return_int ( -1 ) ;
209+ goto done ;
206210 }
207211
208212 /* Parse info from front-end. */
209213 sudoers_ctx .mode = sudoers_policy_deserialize_info (& sudoers_ctx , info ,
210214 & initial_defaults );
211215 if (ISSET (sudoers_ctx .mode , MODE_ERROR ))
212- debug_return_int ( -1 ) ;
216+ goto done ;
213217
214218 if (!init_vars (& sudoers_ctx , envp ))
215- debug_return_int ( -1 ) ;
219+ goto done ;
216220
217221 /* Parse nsswitch.conf for sudoers order. */
218222 snl = sudo_read_nss ();
219223
220224 /* LDAP or NSS may modify the euid so we need to be root for the open. */
221225 if (!set_perms (NULL , PERM_ROOT ))
222- debug_return_int ( -1 ) ;
226+ goto done ;
223227
224228 /* Use the C locale unless another is specified in sudoers. */
225229 sudoers_setlocale (SUDOERS_LOCALE_SUDOERS , & oldlocale );
@@ -257,7 +261,7 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
257261
258262 /* Set login class if applicable (after sudoers is parsed). */
259263 if (set_loginclass (& sudoers_ctx ))
260- ret = true ;
264+ ret = 1 ;
261265
262266cleanup :
263267 mail_parse_errors (& sudoers_ctx );
@@ -269,6 +273,9 @@ sudoers_init(void *info, sudoers_logger_t logger, char * const envp[])
269273 sudo_warn_set_locale_func (NULL );
270274 sudoers_setlocale (oldlocale , NULL );
271275
276+ done :
277+ if (ret == 0 )
278+ ret = -1 ;
272279 debug_return_int (ret );
273280}
274281
0 commit comments