Skip to content

Commit f278cb8

Browse files
committed
sudoers_audit_open: Only unset close function if no servers configured.
Previously, we were always zeroing out the audit close function, which prevented the exit status from being logged. This fixes sending exit records to the log server when I/O logging is not being performed. Also remove an invalid free from log_server_exit() that was never called due to the bug described above and make audit_details local to log_server_accept(). Thanks to Joshua Rogers for finding the invalid free which led me to other the bug.
1 parent a320db9 commit f278cb8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

plugins/sudoers/audit.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <sudoers.h>
3333
#ifdef SUDOERS_LOG_CLIENT
3434
# include <log_client.h>
35+
# include <strlist.h>
3536
#endif
3637

3738
#ifdef HAVE_BSM_AUDIT
@@ -44,9 +45,6 @@
4445
# include <solaris_audit.h>
4546
#endif
4647

47-
#ifdef SUDOERS_LOG_CLIENT
48-
static struct log_details audit_details;
49-
#endif
5048
char *audit_msg = NULL;
5149

5250
/* sudoers_audit is declared at the end of this file. */
@@ -191,7 +189,7 @@ sudoers_audit_open(unsigned int version, sudo_conv_t conversation,
191189
if (ret == true) {
192190
/* Unset close function if we don't need it to avoid extra process. */
193191
#ifdef SUDOERS_LOG_CLIENT
194-
if (client_closure == NULL)
192+
if (SLIST_EMPTY(&def_log_servers))
195193
#endif
196194
sudoers_audit.close = NULL;
197195
} else {
@@ -284,6 +282,8 @@ log_server_accept(const struct sudoers_context *ctx, struct eventlog *evlog)
284282
ret = true;
285283
}
286284
} else {
285+
struct log_details audit_details;
286+
287287
if (!init_log_details(&audit_details, evlog))
288288
goto done;
289289

@@ -292,6 +292,9 @@ log_server_accept(const struct sudoers_context *ctx, struct eventlog *evlog)
292292
SEND_ACCEPT, NULL);
293293
if (client_closure != NULL)
294294
ret = true;
295+
296+
/* Only the log_servers string list is dynamically allocated. */
297+
str_list_free(audit_details.log_servers);
295298
}
296299

297300
done:
@@ -317,8 +320,6 @@ log_server_exit(int status_type, int status)
317320
}
318321
log_server_close(client_closure, exit_status, error);
319322
client_closure = NULL;
320-
free(audit_details.evlog);
321-
audit_details.evlog = NULL;
322323
}
323324

324325
debug_return;

0 commit comments

Comments
 (0)