Skip to content

Commit eb778da

Browse files
committed
sudoers_lookup_check: remove hack for runas.pw when only a group matches
This hack is no longer needed now that init_vars() calls set_runaspw(). Remove two arguments from runaslist_matches() that are now unused.
1 parent 382313e commit eb778da

File tree

5 files changed

+11
-37
lines changed

5 files changed

+11
-37
lines changed

plugins/sudoers/defaults.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ default_binding_matches(const struct sudoers_context *ctx,
745745
debug_return_bool(true);
746746
break;
747747
case DEFAULTS_RUNAS:
748-
if (runaslist_matches(parse_tree, &d->binding->members, NULL, NULL, NULL) == ALLOW)
748+
if (runaslist_matches(parse_tree, &d->binding->members, NULL) == ALLOW)
749749
debug_return_bool(true);
750750
break;
751751
case DEFAULTS_HOST:

plugins/sudoers/display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ display_cmnd_check(struct sudoers_context *ctx,
579579
continue;
580580
}
581581
runas_match = runaslist_matches(parse_tree, cs->runasuserlist,
582-
cs->runasgrouplist, NULL, NULL);
582+
cs->runasgrouplist);
583583
if (runas_match == ALLOW) {
584584
cmnd_match = cmnd_matches(parse_tree, cs->cmnd,
585585
cs->runchroot, NULL);

plugins/sudoers/lookup.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ sudoers_lookup_check(struct sudo_nss *nss, struct sudoers_context *ctx,
231231
struct cmndspec *cs;
232232
struct privilege *priv;
233233
struct userspec *us;
234-
struct member *matching_user;
235234
debug_decl(sudoers_lookup_check, SUDOERS_DEBUG_PARSER);
236235

237236
memset(info, 0, sizeof(*info));
@@ -271,10 +270,8 @@ sudoers_lookup_check(struct sudo_nss *nss, struct sudoers_context *ctx,
271270
date_match = now > cs->notafter ? DENY : ALLOW;
272271
}
273272
if (date_match != DENY) {
274-
matching_user = NULL;
275273
runas_match = runaslist_matches(nss->parse_tree,
276-
cs->runasuserlist, cs->runasgrouplist, &matching_user,
277-
NULL);
274+
cs->runasuserlist, cs->runasgrouplist);
278275
if (runas_match == ALLOW) {
279276
cmnd_match = cmnd_matches(nss->parse_tree, cs->cmnd,
280277
cs->runchroot, info);
@@ -286,16 +283,6 @@ sudoers_lookup_check(struct sudo_nss *nss, struct sudoers_context *ctx,
286283
}
287284

288285
if (SPECIFIED(cmnd_match)) {
289-
/*
290-
* If user is running command as themselves,
291-
* set ctx->runas.pw = ctx->user.pw.
292-
* XXX - hack, want more general solution
293-
*/
294-
if (matching_user && matching_user->type == MYSELF) {
295-
sudo_pw_delref(ctx->runas.pw);
296-
sudo_pw_addref(ctx->user.pw);
297-
ctx->runas.pw = ctx->user.pw;
298-
}
299286
*matching_cs = cs;
300287
*defs = &priv->defaults;
301288
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,

plugins/sudoers/match.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ runas_getgroups(const struct sudoers_context *ctx)
154154
*/
155155
static int
156156
runas_userlist_matches(const struct sudoers_parse_tree *parse_tree,
157-
const struct member_list *user_list, struct member **matching_user)
157+
const struct member_list *user_list)
158158
{
159159
const struct sudoers_context *ctx = parse_tree->ctx;
160160
const char *lhost = parse_tree->lhost ? parse_tree->lhost : ctx->runas.host;
@@ -184,7 +184,7 @@ runas_userlist_matches(const struct sudoers_parse_tree *parse_tree,
184184
a = alias_get(parse_tree, m->name, RUNASALIAS);
185185
if (a != NULL) {
186186
const int rc = runas_userlist_matches(parse_tree,
187-
&a->members, matching_user);
187+
&a->members);
188188
if (SPECIFIED(rc)) {
189189
if (m->negated) {
190190
user_matched = rc == ALLOW ? DENY : ALLOW;
@@ -212,11 +212,6 @@ runas_userlist_matches(const struct sudoers_parse_tree *parse_tree,
212212
user_matched = m->negated ? DENY : ALLOW;
213213
break;
214214
}
215-
if (SPECIFIED(user_matched)) {
216-
if (matching_user != NULL && m->type != ALIAS)
217-
*matching_user = m;
218-
break;
219-
}
220215
}
221216
debug_return_int(user_matched);
222217
}
@@ -228,7 +223,7 @@ runas_userlist_matches(const struct sudoers_parse_tree *parse_tree,
228223
*/
229224
static int
230225
runas_grouplist_matches(const struct sudoers_parse_tree *parse_tree,
231-
const struct member_list *group_list, struct member **matching_group)
226+
const struct member_list *group_list)
232227
{
233228
const struct sudoers_context *ctx = parse_tree->ctx;
234229
int group_matched = UNSPEC;
@@ -246,7 +241,7 @@ runas_grouplist_matches(const struct sudoers_parse_tree *parse_tree,
246241
a = alias_get(parse_tree, m->name, RUNASALIAS);
247242
if (a != NULL) {
248243
const int rc = runas_grouplist_matches(parse_tree,
249-
&a->members, matching_group);
244+
&a->members);
250245
if (SPECIFIED(rc)) {
251246
if (m->negated) {
252247
group_matched = rc == ALLOW ? DENY : ALLOW;
@@ -263,11 +258,6 @@ runas_grouplist_matches(const struct sudoers_parse_tree *parse_tree,
263258
group_matched = m->negated ? DENY : ALLOW;
264259
break;
265260
}
266-
if (SPECIFIED(group_matched)) {
267-
if (matching_group != NULL && m->type != ALIAS)
268-
*matching_group = m;
269-
break;
270-
}
271261
}
272262
}
273263
if (!SPECIFIED(group_matched)) {
@@ -303,8 +293,7 @@ runas_grouplist_matches(const struct sudoers_parse_tree *parse_tree,
303293
*/
304294
int
305295
runaslist_matches(const struct sudoers_parse_tree *parse_tree,
306-
const struct member_list *user_list, const struct member_list *group_list,
307-
struct member **matching_user, struct member **matching_group)
296+
const struct member_list *user_list, const struct member_list *group_list)
308297
{
309298
const struct sudoers_context *ctx = parse_tree->ctx;
310299
struct member_list _user_list = TAILQ_HEAD_INITIALIZER(_user_list);
@@ -319,13 +308,11 @@ runaslist_matches(const struct sudoers_parse_tree *parse_tree,
319308
m_user.negated = false;
320309
TAILQ_INSERT_HEAD(&_user_list, &m_user, entries);
321310
user_list = &_user_list;
322-
matching_user = NULL;
323311
}
324312

325-
user_matched = runas_userlist_matches(parse_tree, user_list, matching_user);
313+
user_matched = runas_userlist_matches(parse_tree, user_list);
326314
if (ISSET(ctx->settings.flags, RUNAS_GROUP_SPECIFIED)) {
327-
group_matched = runas_grouplist_matches(parse_tree, group_list,
328-
matching_group);
315+
group_matched = runas_grouplist_matches(parse_tree, group_list);
329316
}
330317

331318
if (user_matched == DENY || group_matched == DENY)

plugins/sudoers/parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ int cmnd_matches_all(const struct sudoers_parse_tree *parse_tree, const struct m
433433
int cmndlist_matches(const struct sudoers_parse_tree *parse_tree, const struct member_list *list, const char *runchroot, struct cmnd_info *info);
434434
int host_matches(const struct sudoers_parse_tree *parse_tree, const struct passwd *pw, const char *host, const char *shost, const struct member *m);
435435
int hostlist_matches(const struct sudoers_parse_tree *parse_tree, const struct passwd *pw, const struct member_list *list);
436-
int runaslist_matches(const struct sudoers_parse_tree *parse_tree, const struct member_list *user_list, const struct member_list *group_list, struct member **matching_user, struct member **matching_group);
436+
int runaslist_matches(const struct sudoers_parse_tree *parse_tree, const struct member_list *user_list, const struct member_list *group_list);
437437
int user_matches(const struct sudoers_parse_tree *parse_tree, const struct passwd *pw, const struct member *m);
438438
int userlist_matches(const struct sudoers_parse_tree *parse_tree, const struct passwd *pw, const struct member_list *list);
439439
const char *sudo_getdomainname(void);

0 commit comments

Comments
 (0)