README: add link for automatic readme display
[sudo-osx-update.git] / patches / 0001-Add-BSM-auditing-support.patch.txt
blob7d6efc9b61b3851db9fbdd3d0bfc0cd840ec6efb
1 Subject: [PATCH] Add BSM auditing support
3 At this point the only needed change for Apple is to avoid calling
4 au_to_exec_args with a NULL argument and two missing audit_failure
5 calls (and two comments).
6 ---
7  bsm_audit.c | 10 ++++++----
8  check.c     |  4 +++-
9  sudo.c      |  6 +++++-
10  3 files changed, 14 insertions(+), 6 deletions(-)
12 diff --git a/bsm_audit.c b/bsm_audit.c
13 index 4aebe031..8f315f43 100644
14 --- a/bsm_audit.c
15 +++ b/bsm_audit.c
16 @@ -167,10 +167,12 @@ bsm_audit_failure(char **exec_args, char const *const fmt, va_list ap)
17         if (tok == NULL)
18                 error(1, "au_to_subject: failed");
19         au_write(aufd, tok);
20 -       tok = au_to_exec_args(exec_args);
21 -       if (tok == NULL)
22 -               error(1, "au_to_exec_args: failed");
23 -       au_write(aufd, tok);
24 +       if (exec_args != NULL) {
25 +               tok = au_to_exec_args(exec_args);
26 +               if (tok == NULL)
27 +                       error(1, "au_to_exec_args: failed");
28 +               au_write(aufd, tok);
29 +       }
30         (void) vsnprintf(text, sizeof(text), fmt, ap);
31         tok = au_to_text(text);
32         if (tok == NULL)
33 diff --git a/check.c b/check.c
34 index a3433638..4c9ed85b 100644
35 --- a/check.c
36 +++ b/check.c
37 @@ -759,9 +759,11 @@ get_authpw()
38         if ((pw = sudo_getpwnam(def_runas_default)) == NULL)
39             log_fatal(0, "unknown user: %s", def_runas_default);
40      } else if (def_targetpw) {
41 -       if (runas_pw->pw_name == NULL)
42 +       if (runas_pw->pw_name == NULL) {
43 +           audit_failure(NULL, "unknown uid");
44             log_fatal(NO_MAIL|MSG_ONLY, "unknown uid: %u",
45                 (unsigned int) runas_pw->pw_uid);
46 +       }
47         pw_addref(runas_pw);
48         pw = runas_pw;
49      } else {
50 diff --git a/sudo.c b/sudo.c
51 index 1db99f4b..041b0e75 100644
52 --- a/sudo.c
53 +++ b/sudo.c
54 @@ -331,12 +331,14 @@ main(argc, argv, envp)
56      /* This goes after sudoers is parsed since it may have timestamp options. */
57      if (sudo_mode == MODE_KILL || sudo_mode == MODE_INVALIDATE) {
58 +       /* Not an audit event. */
59         remove_timestamp((sudo_mode == MODE_KILL));
60         goto done;
61      }
63      /* Is root even allowed to run sudo? */
64      if (user_uid == 0 && !def_root_sudo) {
65 +       /* Not an audit event. */
66         (void) fprintf(stderr,
67             "Sorry, %s has been configured to not allow root to run it.\n",
68             getprogname());
69 @@ -603,8 +605,10 @@ init_vars(envp)
70      int nohostname;
72      /* Sanity check command from user. */
73 -    if (user_cmnd == NULL && strlen(NewArgv[0]) >= PATH_MAX)
74 +    if (user_cmnd == NULL && strlen(NewArgv[0]) >= PATH_MAX) {
75 +       audit_failure(NULL, "pathname too long");
76         errorx(1, "%s: File name too long", NewArgv[0]);
77 +    }
79  #ifdef HAVE_TZSET
80      (void) tzset();            /* set the timezone if applicable */
81 -- 
82 1.8.3