static void filter_userspecs(struct cvtsudoers_config *conf);
static void filter_defaults(struct cvtsudoers_config *conf);
static void alias_remove_unused(void);
+static void alias_prune(struct cvtsudoers_config *conf);
int
main(int argc, char *argv[])
/* Apply filters. */
filter_userspecs(conf);
filter_defaults(conf);
- if (filters != NULL)
+ if (filters != NULL) {
alias_remove_unused();
+ if (conf->prune_matches && conf->expand_aliases)
+ alias_prune(conf);
+ }
switch (output_format) {
case format_json:
struct passwd *pw = NULL;
/* An upper case filter entry may be a User_Alias */
+ /* XXX - doesn't handle nested aliases */
if (m->type == ALIAS && !conf->expand_aliases) {
if (strcmp(m->name, s->str) == 0) {
matched = true;
shost = shosts[n++];
/* An upper case filter entry may be a Host_Alias */
+ /* XXX - doesn't handle nested aliases */
if (m->type == ALIAS && !conf->expand_aliases) {
if (strcmp(m->name, s->str) == 0) {
matched = true;
debug_return;
}
+/*
+ * Prune out non-matching entries from user and host aliases.
+ */
+int
+alias_prune_helper(void *v, void *cookie)
+{
+ struct alias *a = v;
+ struct cvtsudoers_config *conf = cookie;
+
+ /* XXX - misue of these functions */
+ switch (a->type) {
+ case USERALIAS:
+ userlist_matches_filter(&a->members, conf);
+ break;
+ case HOSTALIAS:
+ hostlist_matches_filter(&a->members, conf);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+/*
+ * Prune out non-matching entries from within aliases.
+ */
+static void
+alias_prune(struct cvtsudoers_config *conf)
+{
+ debug_decl(alias_prune, SUDOERS_DEBUG_ALIAS)
+
+ alias_apply(alias_prune_helper, conf);
+
+ debug_return;
+}
+
/*
* Convert back to sudoers.
*/
break;
case ALIAS:
if ((a = alias_get(m->name, USERALIAS)) != NULL) {
+ /* XXX */
int rc = userlist_matches(pw, &a->members);
if (rc != UNSPEC)
matched = m->negated ? !rc : rc;
break;
case ALIAS:
if ((a = alias_get(m->name, HOSTALIAS)) != NULL) {
+ /* XXX */
int rc = hostlist_matches_int(pw, lhost, shost, &a->members);
if (rc != UNSPEC)
matched = m->negated ? !rc : rc;