};
STAILQ_HEAD(sudo_role_list, sudo_role);
+static void
+sudo_role_free(struct sudo_role *role)
+{
+ debug_decl(sudo_role_free, SUDOERS_DEBUG_UTIL)
+
+ if (role != NULL) {
+ free(role->cn);
+ free(role->notbefore);
+ free(role->notafter);
+ str_list_free(role->cmnds);
+ str_list_free(role->hosts);
+ str_list_free(role->users);
+ str_list_free(role->runasusers);
+ str_list_free(role->runasgroups);
+ str_list_free(role->options);
+ free(role);
+ }
+
+ debug_return;
+}
+
static struct sudo_role *
sudo_role_alloc(void)
{
if (role->cmnds == NULL || role->hosts == NULL ||
role->users == NULL || role->runasusers == NULL ||
role->runasgroups == NULL || role->options == NULL) {
- str_list_free(role->cmnds);
- str_list_free(role->hosts);
- str_list_free(role->users);
- str_list_free(role->runasusers);
- str_list_free(role->runasgroups);
- str_list_free(role->options);
- free(role);
+ sudo_role_free(role);
role = NULL;
}
}
debug_return_ptr(role);
}
-static void
-sudo_role_free(struct sudo_role *role)
-{
- debug_decl(sudo_role_free, SUDOERS_DEBUG_UTIL)
-
- if (role != NULL) {
- free(role->cn);
- free(role->notbefore);
- free(role->notafter);
- str_list_free(role->cmnds);
- str_list_free(role->hosts);
- str_list_free(role->users);
- str_list_free(role->runasusers);
- str_list_free(role->runasgroups);
- str_list_free(role->options);
- free(role);
- }
-
- debug_return;
-}
-
/*
* Allocate a struct cvtsudoers_string, store str in it and
* insert into the specified strlist.
if (role->cn != NULL && strcmp(role->cn, "defaults") == 0) {
ldif_store_options(role->options);
sudo_role_free(role);
+ role = NULL;
} else if (STAILQ_EMPTY(role->users) ||
STAILQ_EMPTY(role->hosts) || STAILQ_EMPTY(role->cmnds)) {
/* Incomplete role. */
sudo_warnx(U_("ignoring incomplete sudoRole: cn: %s"),
role->cn ? role->cn : "UNKNOWN");
sudo_role_free(role);
+ role = NULL;
} else {
/* Cache users, hosts, runasusers and runasgroups. */
if (str_list_cache(usercache, &role->users) == -1 ||
in_role = false;
}
if (len == -1) {
- free(role);
+ sudo_role_free(role);
+ role = NULL;
break;
}
mismatch = false;
}
}
}
+ sudo_role_free(role);
free(line);
/* Convert from roles to sudoers data structures. */