|
1 | 1 | /* |
2 | 2 | * SPDX-License-Identifier: ISC |
3 | 3 | * |
4 | | - * Copyright (c) 2004-2005, 2007-2021 Todd C. Miller <[email protected]> |
| 4 | + * Copyright (c) 2004-2005, 2007-2023 Todd C. Miller <[email protected]> |
5 | 5 | * |
6 | 6 | * Permission to use, copy, modify, and distribute this software for any |
7 | 7 | * purpose with or without fee is hereby granted, provided that the above |
@@ -67,7 +67,7 @@ sudoers_lookup_pseudo(struct sudo_nss_list *snl, struct passwd *pw, |
67 | 67 | struct privilege *priv; |
68 | 68 | struct userspec *us; |
69 | 69 | struct defaults *def; |
70 | | - int nopass, match = DENY; |
| 70 | + int cmnd_match, nopass, match = DENY; |
71 | 71 | enum def_tuple pwcheck; |
72 | 72 | debug_decl(sudoers_lookup_pseudo, SUDOERS_DEBUG_PARSER); |
73 | 73 |
|
@@ -133,26 +133,40 @@ sudoers_lookup_pseudo(struct sudo_nss_list *snl, struct passwd *pw, |
133 | 133 | */ |
134 | 134 | switch (runas_matches_pw(nss->parse_tree, cs, list_pw)) { |
135 | 135 | case DENY: |
136 | | - continue; |
| 136 | + break; |
137 | 137 | case ALLOW: |
| 138 | + /* |
| 139 | + * RunAs user matches list user. |
| 140 | + * Match on command "list" or ALL. |
| 141 | + */ |
| 142 | + cmnd_match = cmnd_matches(nss->parse_tree, |
| 143 | + cs->cmnd, cs->runchroot, NULL); |
| 144 | + if (cmnd_match != UNSPEC) { |
| 145 | + match = cmnd_match; |
| 146 | + goto done; |
| 147 | + } |
138 | 148 | break; |
139 | 149 | default: |
| 150 | + /* |
| 151 | + * RunAs user doesn't match list user. Only allow |
| 152 | + * listing if the user has "sudo ALL" for root. |
| 153 | + */ |
140 | 154 | if (root_pw != NULL && runas_matches_pw(nss->parse_tree, |
141 | 155 | cs, root_pw) == ALLOW) { |
142 | | - break; |
| 156 | + cmnd_match = cmnd_matches_all(nss->parse_tree, |
| 157 | + cs->cmnd, cs->runchroot, NULL); |
| 158 | + if (cmnd_match != UNSPEC) { |
| 159 | + match = cmnd_match; |
| 160 | + goto done; |
| 161 | + } |
143 | 162 | } |
144 | | - continue; |
145 | | - } |
146 | | - |
147 | | - /* Match command: "list" or ALL. */ |
148 | | - if (cmnd_matches(nss->parse_tree, cs->cmnd, cs->runchroot, |
149 | | - NULL) == ALLOW) { |
150 | | - match = ALLOW; |
| 163 | + break; |
151 | 164 | } |
152 | 165 | } |
153 | 166 | } |
154 | 167 | } |
155 | 168 | } |
| 169 | +done: |
156 | 170 | if (root_pw != NULL) |
157 | 171 | sudo_pw_delref(root_pw); |
158 | 172 | if (match == ALLOW || user_uid == 0) { |
|
0 commit comments