@@ -98,23 +98,36 @@ impl Sudoers {
98
98
& mut self ,
99
99
hostname : & system:: Hostname ,
100
100
requesting_user : & User ,
101
- target_user : & User ,
101
+ target_user : Option < & User > ,
102
102
) {
103
103
let customisers = std:: mem:: take ( & mut self . customisers . non_cmnd ) ;
104
104
105
105
let host_matcher = & match_token ( hostname) ;
106
- let user_matcher = & match_user ( requesting_user) ;
107
- let runas_matcher = & match_user ( target_user) ;
108
-
109
106
let host_aliases = get_aliases ( & self . aliases . host , host_matcher) ;
107
+
108
+ let user_matcher = & match_user ( requesting_user) ;
110
109
let user_aliases = get_aliases ( & self . aliases . user , user_matcher) ;
111
- let runas_aliases = get_aliases ( & self . aliases . runas , runas_matcher) ;
110
+
111
+ let runas_matcher;
112
+ let runas_matcher_aliases = if let Some ( target_user) = target_user {
113
+ runas_matcher = match_user ( target_user) ;
114
+ let runas_aliases = get_aliases ( & self . aliases . runas , & runas_matcher) ;
115
+ Some ( ( runas_matcher, runas_aliases) )
116
+ } else {
117
+ None
118
+ } ;
112
119
113
120
let match_scope = |scope| match scope {
114
121
ConfigScope :: Generic => true ,
115
122
ConfigScope :: Host ( list) => find_item ( & list, host_matcher, & host_aliases) . is_some ( ) ,
116
123
ConfigScope :: User ( list) => find_item ( & list, user_matcher, & user_aliases) . is_some ( ) ,
117
- ConfigScope :: RunAs ( list) => find_item ( & list, runas_matcher, & runas_aliases) . is_some ( ) ,
124
+ ConfigScope :: RunAs ( list) => {
125
+ if let Some ( ( runas_matcher, runas_aliases) ) = & runas_matcher_aliases {
126
+ find_item ( & list, runas_matcher, runas_aliases) . is_some ( )
127
+ } else {
128
+ false
129
+ }
130
+ }
118
131
ConfigScope :: Command ( _list) => {
119
132
unreachable ! ( "command-specific defaults are filtered out" )
120
133
}
@@ -150,7 +163,7 @@ impl Sudoers {
150
163
on_host : & system:: Hostname ,
151
164
request : Request < User , Group > ,
152
165
) -> Judgement {
153
- self . specify_host_user_runas ( on_host, am_user, request. user ) ;
166
+ self . specify_host_user_runas ( on_host, am_user, Some ( request. user ) ) ;
154
167
self . specify_command ( request. command , request. arguments ) ;
155
168
156
169
// exception: if user is root or does not switch users, NOPASSWD is implied
@@ -219,7 +232,7 @@ impl Sudoers {
219
232
invoking_user : & User ,
220
233
hostname : & system:: Hostname ,
221
234
) -> Authorization {
222
- self . specify_host_user_runas ( hostname, invoking_user, invoking_user ) ;
235
+ self . specify_host_user_runas ( hostname, invoking_user, None ) ;
223
236
224
237
// exception: if user is root, NOPASSWD is implied
225
238
let skip_passwd = invoking_user. is_root ( ) ;
@@ -285,7 +298,7 @@ impl Sudoers {
285
298
am_user : & User ,
286
299
target_user : & User ,
287
300
) -> Option < PathBuf > {
288
- self . specify_host_user_runas ( on_host, am_user, target_user) ;
301
+ self . specify_host_user_runas ( on_host, am_user, Some ( target_user) ) ;
289
302
if self . settings . env_editor ( ) {
290
303
for key in [ "SUDO_EDITOR" , "VISUAL" , "EDITOR" ] {
291
304
if let Some ( var) = std:: env:: var_os ( key) {
0 commit comments