"for gid %d!\n", gids[i]));
continue;
}
- add_sid_to_array_unique( result, &unix_group_sid,
- &result->sids, &result->num_sids );
+ if (!add_sid_to_array_unique( result, &unix_group_sid,
+ &result->sids, &result->num_sids )) {
+ result->sam_account = NULL; /* Don't free on error exit. */
+ TALLOC_FREE(result);
+ return NT_STATUS_NO_MEMORY;
+ }
}
/* For now we throw away the gids and convert via sid_to_gid
for (i=0; i<num_aliases; i++) {
DOM_SID alias_sid;
sid_compose(&alias_sid, domain_sid, aliases[i]);
- add_sid_to_array_unique(token, &alias_sid,
+ if (!add_sid_to_array_unique(token, &alias_sid,
&token->user_sids,
- &token->num_sids);
- if (token->user_sids == NULL) {
+ &token->num_sids)) {
DEBUG(0, ("add_sid_to_array failed\n"));
TALLOC_FREE(tmp_ctx);
return NT_STATUS_NO_MEMORY;
/* Add Administrators if the user beloongs to Domain Admins */
if ( nt_token_check_sid( &domadm, token ) ) {
- add_sid_to_array(token, &global_sid_Builtin_Administrators,
- &token->user_sids, &token->num_sids);
+ if (!add_sid_to_array(token, &global_sid_Builtin_Administrators,
+ &token->user_sids, &token->num_sids)) {
+ return NT_STATUS_NO_MEMORY;
+ }
}
return NT_STATUS_OK;
/* Add the user and primary group sid */
- add_sid_to_array(result, user_sid,
- &result->user_sids, &result->num_sids);
+ if (!add_sid_to_array(result, user_sid,
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
/* For guest, num_groupsids may be zero. */
if (num_groupsids) {
- add_sid_to_array(result, &groupsids[0],
- &result->user_sids, &result->num_sids);
+ if (!add_sid_to_array(result, &groupsids[0],
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
}
/* Add in BUILTIN sids */
- add_sid_to_array(result, &global_sid_World,
- &result->user_sids, &result->num_sids);
- add_sid_to_array(result, &global_sid_Network,
- &result->user_sids, &result->num_sids);
+ if (!add_sid_to_array(result, &global_sid_World,
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
+ if (!add_sid_to_array(result, &global_sid_Network,
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
if (is_guest) {
- add_sid_to_array(result, &global_sid_Builtin_Guests,
- &result->user_sids, &result->num_sids);
+ if (!add_sid_to_array(result, &global_sid_Builtin_Guests,
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
} else {
- add_sid_to_array(result, &global_sid_Authenticated_Users,
- &result->user_sids, &result->num_sids);
+ if (!add_sid_to_array(result, &global_sid_Authenticated_Users,
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
}
/* Now the SIDs we got from authentication. These are the ones from
* first group sid as primary above. */
for (i=1; i<num_groupsids; i++) {
- add_sid_to_array_unique(result, &groupsids[i],
- &result->user_sids, &result->num_sids);
+ if (!add_sid_to_array_unique(result, &groupsids[i],
+ &result->user_sids, &result->num_sids)) {
+ return NULL;
+ }
}
/* Deal with the BUILTIN\Administrators group. If the SID can
"ignoring it\n", sid_string_static(sid)));
continue;
}
- add_gid_to_array_unique(server_info, gid, &server_info->groups,
- &server_info->n_groups);
+ if (!add_gid_to_array_unique(server_info, gid, &server_info->groups,
+ &server_info->n_groups)) {
+ TALLOC_FREE(mem_ctx);
+ return NT_STATUS_NO_MEMORY;
+ }
}
debug_nt_user_token(DBGC_AUTH, 10, server_info->ptok);
DOM_SID user_sid;
enum lsa_SidType type;
gid_t *gids;
- DOM_SID primary_group_sid;
DOM_SID *group_sids;
DOM_SID unix_group_sid;
size_t num_group_sids;
goto unix_user;
}
- result = pdb_enum_group_memberships(tmp_ctx, sam_acct,
+ result = pdb_enum_group_memberships(mem_ctx, sam_acct,
&group_sids, &gids,
&num_group_sids);
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
- group_sids = talloc_array(tmp_ctx, DOM_SID, num_group_sids);
+ /* group_sids can be realloced - must be done on mem_ctx not tmp_ctx. */
+ group_sids = talloc_array(mem_ctx, DOM_SID, num_group_sids);
if (group_sids == NULL) {
DEBUG(1, ("talloc_array failed\n"));
result = NT_STATUS_NO_MEMORY;
uint32 dummy;
- sid_copy(&primary_group_sid, &user_sid);
- sid_split_rid(&primary_group_sid, &dummy);
- sid_append_rid(&primary_group_sid, DOMAIN_GROUP_RID_USERS);
+ num_group_sids = 1;
+ group_sids = talloc_array(mem_ctx, DOM_SID, num_group_sids);
+ if (group_sids == NULL) {
+ DEBUG(1, ("talloc_array failed\n"));
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ sid_copy(&group_sids[0], &user_sid);
+ sid_split_rid(&group_sids[0], &dummy);
+ sid_append_rid(&group_sids[0], DOMAIN_GROUP_RID_USERS);
- if (!sid_to_gid(&primary_group_sid, gid)) {
+ if (!sid_to_gid(&group_sids[0], gid)) {
DEBUG(1, ("sid_to_gid(%s) failed\n",
- sid_string_static(&primary_group_sid)));
+ sid_string_static(&group_sids[0])));
goto done;
}
- num_group_sids = 1;
- group_sids = &primary_group_sid;
gids = gid;
*found_username = talloc_strdup(mem_ctx, username);
"for gid %d!\n", gids[i]));
continue;
}
- add_sid_to_array_unique( mem_ctx, &unix_group_sid,
- &group_sids, &num_group_sids );
+ if (!add_sid_to_array_unique( mem_ctx, &unix_group_sid,
+ &group_sids, &num_group_sids )) {
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
*token = create_local_nt_token(mem_ctx, &user_sid,
TALLOC_FREE(result);
return NT_STATUS_INVALID_PARAMETER;
}
- add_sid_to_array(result, &sid, &result->sids,
- &result->num_sids);
+ if (!add_sid_to_array(result, &sid, &result->sids,
+ &result->num_sids)) {
+ TALLOC_FREE(result);
+ return NT_STATUS_NO_MEMORY;
+ }
}
/* Copy 'other' sids. We need to do sid filtering here to
*/
for (i = 0; i < info3->num_other_sids; i++) {
- add_sid_to_array(result, &info3->other_sids[i].sid,
- &result->sids,
- &result->num_sids);
+ if (!add_sid_to_array(result, &info3->other_sids[i].sid,
+ &result->sids,
+ &result->num_sids)) {
+ TALLOC_FREE(result);
+ return NT_STATUS_NO_MEMORY;
+ }
}
result->login_server = unistr2_tdup(result,
*p_num_alias_rids += 1;
}
- SAFE_FREE(alias_sids);
+ TALLOC_FREE(alias_sids);
return NT_STATUS_OK;
}
goto failed;
}
string_to_sid(&alias, (char *)el->values[0].data);
- add_sid_to_array_unique(NULL, &alias, sids, num);
- if (sids == NULL) {
+ if (!add_sid_to_array_unique(NULL, &alias, sids, num)) {
status = NT_STATUS_NO_MEMORY;
goto failed;
}
for (i=0;i<el->num_values;i++) {
DOM_SID sid;
string_to_sid(&sid, (const char *)el->values[i].data);
- add_sid_to_array_unique(NULL, &sid, sids, num);
- if (sids == NULL) {
+ if (!add_sid_to_array_unique(NULL, &sid, sids, num)) {
talloc_free(dn);
return NT_STATUS_NO_MEMORY;
}
if (!string_to_sid(&alias, string_sid))
continue;
- add_sid_to_array_unique(NULL, &alias, sids, num);
-
- if (sids == NULL)
+ if (!add_sid_to_array_unique(NULL, &alias, sids, num)) {
return NT_STATUS_NO_MEMORY;
+ }
}
SAFE_FREE(dbuf.dptr);
if (!string_to_sid(&member, member_string))
continue;
- add_sid_to_array(NULL, &member, closure->sids, closure->num);
+ if (!add_sid_to_array(NULL, &member, closure->sids, closure->num)) {
+ /* talloc fail. */
+ break;
+ }
}
return 0;
return 0;
}
- add_sid_to_array( NULL, &sid, &priv->sids.list, &priv->sids.count );
+ if (!add_sid_to_array( NULL, &sid, &priv->sids.list, &priv->sids.count )) {
+ return 0;
+ }
return 0;
}
groups = NULL;
/* Add in primary group first */
- add_gid_to_array_unique(mem_ctx, primary_gid, &groups, &ngrp);
+ if (!add_gid_to_array_unique(mem_ctx, primary_gid, &groups, &ngrp)) {
+ SAFE_FREE(temp_groups);
+ return False;
+ }
- for (i=0; i<max_grp; i++)
- add_gid_to_array_unique(mem_ctx, temp_groups[i],
- &groups, &ngrp);
+ for (i=0; i<max_grp; i++) {
+ if (!add_gid_to_array_unique(mem_ctx, temp_groups[i],
+ &groups, &ngrp)) {
+ SAFE_FREE(temp_groups);
+ return False;
+ }
+ }
*p_ngroups = ngrp;
*ret_groups = groups;
Add a gid to an array of gids if it's not already there.
****************************************************************************/
-void add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
+BOOL add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
gid_t **gids, size_t *num_gids)
{
int i;
/*
* A former call to this routine has failed to allocate memory
*/
- return;
+ return False;
}
for (i=0; i<*num_gids; i++) {
- if ((*gids)[i] == gid)
- return;
- }
-
- if (mem_ctx != NULL) {
- *gids = TALLOC_REALLOC_ARRAY(mem_ctx, *gids, gid_t, *num_gids+1);
- } else {
- *gids = SMB_REALLOC_ARRAY(*gids, gid_t, *num_gids+1);
+ if ((*gids)[i] == gid) {
+ return True;
+ }
}
+ *gids = TALLOC_REALLOC_ARRAY(mem_ctx, *gids, gid_t, *num_gids+1);
if (*gids == NULL) {
- return;
+ *num_gids = 0;
+ return False;
}
(*gids)[*num_gids] = gid;
*num_gids += 1;
+ return True;
}
/****************************************************************************
goto error;
}
- if (mem_ctx != NULL) {
- *array = TALLOC(mem_ctx, element_size * (*array_size));
- } else {
- *array = SMB_MALLOC(element_size * (*array_size));
- }
-
+ *array = TALLOC(mem_ctx, element_size * (*array_size));
if (*array == NULL) {
goto error;
}
goto error;
}
- if (mem_ctx != NULL) {
- *array = TALLOC_REALLOC(mem_ctx, *array,
- element_size * (*array_size));
- } else {
- *array = SMB_REALLOC(*array,
- element_size * (*array_size));
- }
+ *array = TALLOC_REALLOC(mem_ctx, *array,
+ element_size * (*array_size));
if (*array == NULL) {
goto error;
Add SID to an array SIDs
********************************************************************/
-void add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
+BOOL add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
DOM_SID **sids, size_t *num)
{
- if (mem_ctx != NULL) {
- *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID,
+ *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID,
(*num)+1);
- } else {
- *sids = SMB_REALLOC_ARRAY(*sids, DOM_SID, (*num)+1);
- }
-
if (*sids == NULL) {
- return;
+ *num = 0;
+ return False;
}
sid_copy(&((*sids)[*num]), sid);
*num += 1;
- return;
+ return True;
}
Add SID to an array SIDs ensuring that it is not already there
********************************************************************/
-void add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
+BOOL add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
DOM_SID **sids, size_t *num_sids)
{
size_t i;
for (i=0; i<(*num_sids); i++) {
if (sid_compare(sid, &(*sids)[i]) == 0)
- return;
+ return True;
}
- add_sid_to_array(mem_ctx, sid, sids, num_sids);
+ return add_sid_to_array(mem_ctx, sid, sids, num_sids);
}
/********************************************************************
return;
}
-void add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
+BOOL add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
uint32 rid, uint32 **pp_rids, size_t *p_num)
{
size_t i;
for (i=0; i<*p_num; i++) {
if ((*pp_rids)[i] == rid)
- return;
+ return True;
}
*pp_rids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_rids, uint32, *p_num+1);
- if (*pp_rids == NULL)
- return;
+ if (*pp_rids == NULL) {
+ *p_num = 0;
+ return False;
+ }
(*pp_rids)[*p_num] = rid;
*p_num += 1;
+ return True;
}
BOOL is_null_sid(const DOM_SID *sid)
*strings = TALLOC_REALLOC_ARRAY(mem_ctx, *strings, const char *, (*num)+1);
- if ((*strings == NULL) || (dup_str == NULL))
+ if ((*strings == NULL) || (dup_str == NULL)) {
+ *num = 0;
return False;
+ }
(*strings)[*num] = dup_str;
*num += 1;
num_groups = 0;
/* always add the primary group to the sid array */
- add_sid_to_array(mem_ctx, primary_group, user_sids, &num_groups);
+ if (!add_sid_to_array(mem_ctx, primary_group, user_sids, &num_groups)) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
if (count > 0) {
for (msg = ads_first_entry(ads, res); msg;
continue;
}
- add_sid_to_array(mem_ctx, &group_sid, user_sids,
- &num_groups);
+ if (!add_sid_to_array(mem_ctx, &group_sid, user_sids,
+ &num_groups)) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
}
num_groups = 0;
/* always add the primary group to the sid array */
- add_sid_to_array(mem_ctx, primary_group, user_sids, &num_groups);
+ if (!add_sid_to_array(mem_ctx, primary_group, user_sids, &num_groups)) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
count = ads_pull_sids_from_extendeddn(ads, mem_ctx, res, "memberOf",
ADS_EXTENDED_DN_HEX_STRING,
continue;
}
- add_sid_to_array(mem_ctx, &group_sids[i], user_sids,
- &num_groups);
+ if (!add_sid_to_array(mem_ctx, &group_sids[i], user_sids,
+ &num_groups)) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
*user_sids = NULL;
num_groups = 0;
- add_sid_to_array(mem_ctx, &primary_group, user_sids, &num_groups);
+ if (!add_sid_to_array(mem_ctx, &primary_group, user_sids, &num_groups)) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
for (i=0;i<count;i++) {
continue;
}
- add_sid_to_array_unique(mem_ctx, &sids[i],
- user_sids, &num_groups);
+ if (!add_sid_to_array_unique(mem_ctx, &sids[i],
+ user_sids, &num_groups)) {
+ status = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
*p_num_groups = (uint32)num_groups;
DEBUG(0, ("Could not parse sid %s\n", p));
return False;
}
- add_sid_to_array(mem_ctx, &sid, sids, num_sids);
+ if (!add_sid_to_array(mem_ctx, &sid, sids, num_sids)) {
+ return False;
+ }
p = q;
}
return True;
DEBUGADD(10, (" rid %d\n", alias_rids[i]));
sid_copy(&sid, &domain->sid);
sid_append_rid(&sid, alias_rids[i]);
- add_sid_to_array(state->mem_ctx, &sid, &sids, &num_sids);
+ if (!add_sid_to_array(state->mem_ctx, &sid, &sids, &num_sids)) {
+ return WINBINDD_ERROR;
+ }
}
state->sids = NULL;
state->num_sids = 0;
- add_sid_to_array(mem_ctx, &state->user_sid, &state->sids,
- &state->num_sids);
+ if (!add_sid_to_array(mem_ctx, &state->user_sid, &state->sids,
+ &state->num_sids)) {
+ DEBUG(0, ("Out of memory\n"));
+ state->cont(state->private_data, False, NULL, 0);
+ return;
+ }
if (sids_str && !parse_sidlist(mem_ctx, sids_str, &state->sids,
&state->num_sids)) {
return;
}
- for (i=0; i<num_aliases; i++)
- add_sid_to_array(state->mem_ctx, &aliases[i],
- &state->sids, &state->num_sids);
+ for (i=0; i<num_aliases; i++) {
+ if (!add_sid_to_array(state->mem_ctx, &aliases[i],
+ &state->sids, &state->num_sids)) {
+ DEBUG(0, ("Out of memory\n"));
+ state->cont(state->private_data, False, NULL, 0);
+ return;
+ }
+ }
if (state->local_alias_domain != NULL) {
struct winbindd_domain *local_domain = state->local_alias_domain;
{
*addrs = TALLOC_REALLOC_ARRAY(mem_ctx, *addrs, struct sockaddr_in, (*num)+1);
- if (*addrs == NULL)
+ if (*addrs == NULL) {
+ *num = 0;
return False;
+ }
(*addrs)[*num].sin_family = PF_INET;
putip((char *)&((*addrs)[*num].sin_addr), (char *)&ip);
for (i=0; i<num_dcs; i++) {
- add_string_to_array(mem_ctx, dcs[i].name,
- &dcnames, &num_dcnames);
- add_sockaddr_to_array(mem_ctx, dcs[i].ip, 445,
- &addrs, &num_addrs);
+ if (!add_string_to_array(mem_ctx, dcs[i].name,
+ &dcnames, &num_dcnames)) {
+ return False;
+ }
+ if (!add_sockaddr_to_array(mem_ctx, dcs[i].ip, 445,
+ &addrs, &num_addrs)) {
+ return False;
+ }
- add_string_to_array(mem_ctx, dcs[i].name,
- &dcnames, &num_dcnames);
- add_sockaddr_to_array(mem_ctx, dcs[i].ip, 139,
- &addrs, &num_addrs);
+ if (!add_string_to_array(mem_ctx, dcs[i].name,
+ &dcnames, &num_dcnames)) {
+ return False;
+ }
+ if (!add_sockaddr_to_array(mem_ctx, dcs[i].ip, 139,
+ &addrs, &num_addrs)) {
+ return False;
+ }
}
if ((num_dcnames == 0) || (num_dcnames != num_addrs))
int num_addrs = 0;
int dummy = 0;
- add_sockaddr_to_array(mem_ctx, domain->dcaddr.sin_addr, 445, &addrs, &num_addrs);
- add_sockaddr_to_array(mem_ctx, domain->dcaddr.sin_addr, 139, &addrs, &num_addrs);
+ if (!add_sockaddr_to_array(mem_ctx, domain->dcaddr.sin_addr, 445, &addrs, &num_addrs)) {
+ set_domain_offline(domain);
+ return NT_STATUS_NO_MEMORY;
+ }
+ if (!add_sockaddr_to_array(mem_ctx, domain->dcaddr.sin_addr, 139, &addrs, &num_addrs)) {
+ set_domain_offline(domain);
+ return NT_STATUS_NO_MEMORY;
+ }
/* 5 second timeout. */
if (!open_any_socket_out(addrs, num_addrs, 5000, &dummy, &fd)) {
struct getgroups_state *s =
(struct getgroups_state *)private_data;
- if (success)
- add_gid_to_array_unique(NULL, gid,
+ if (success) {
+ if (!add_gid_to_array_unique(NULL, gid,
&s->token_gids,
- &s->num_token_gids);
+ &s->num_token_gids)) {
+ return;
+ }
+ }
if (s->i < s->num_token_sids) {
const DOM_SID *sid = &s->token_sids[s->i];
for (i=0; i<num_aliases_query; i++) {
size_t na = *num_aliases;
- add_rid_to_array_unique(mem_ctx, alias_rids_query[i],
- alias_rids, &na);
+ if (!add_rid_to_array_unique(mem_ctx, alias_rids_query[i],
+ alias_rids, &na)) {
+ return NT_STATUS_NO_MEMORY;
+ }
*num_aliases = na;
}
/* always add the primary group to the sid array */
sid_compose(&primary_group, &info3->dom_sid.sid, info3->user_rid);
- add_sid_to_array(mem_ctx, &primary_group, user_sids, &num_groups);
+ if (!add_sid_to_array(mem_ctx, &primary_group, user_sids, &num_groups)) {
+ SAFE_FREE(info3);
+ return NT_STATUS_NO_MEMORY;
+ }
for (i=0; i<info3->num_groups; i++) {
sid_copy(&group_sid, &info3->dom_sid.sid);
sid_append_rid(&group_sid, info3->gids[i].g_rid);
- add_sid_to_array(mem_ctx, &group_sid, user_sids,
- &num_groups);
+ if (!add_sid_to_array(mem_ctx, &group_sid, user_sids,
+ &num_groups)) {
+ SAFE_FREE(info3);
+ return NT_STATUS_NO_MEMORY;
+ }
}
SAFE_FREE(info3);
return ret;
}
-static void add_uid_to_array_unique(TALLOC_CTX *mem_ctx,
+static BOOL add_uid_to_array_unique(TALLOC_CTX *mem_ctx,
uid_t uid, uid_t **pp_uids, size_t *p_num)
{
size_t i;
for (i=0; i<*p_num; i++) {
if ((*pp_uids)[i] == uid)
- return;
+ return True;
}
*pp_uids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_uids, uid_t, *p_num+1);
if (*pp_uids == NULL)
- return;
+ return False;
(*pp_uids)[*p_num] = uid;
*p_num += 1;
+ return True;
}
static BOOL get_memberuids(TALLOC_CTX *mem_ctx, gid_t gid, uid_t **pp_uids, size_t *p_num)
char **gr;
struct passwd *pwd;
BOOL winbind_env;
+ BOOL ret = False;
*pp_uids = NULL;
*p_num = 0;
if ((grp = getgrgid(gid)) == NULL) {
/* allow winbindd lookups, but only if they weren't already disabled */
- if (!winbind_env) {
- winbind_on();
- }
-
- return False;
+ goto done;
}
/* Primary group members */
setpwent();
while ((pwd = getpwent()) != NULL) {
if (pwd->pw_gid == gid) {
- add_uid_to_array_unique(mem_ctx, pwd->pw_uid,
- pp_uids, p_num);
+ if (!add_uid_to_array_unique(mem_ctx, pwd->pw_uid,
+ pp_uids, p_num)) {
+ goto done;
+ }
}
}
endpwent();
if (pw == NULL)
continue;
- add_uid_to_array_unique(mem_ctx, pw->pw_uid, pp_uids, p_num);
+ if (!add_uid_to_array_unique(mem_ctx, pw->pw_uid, pp_uids, p_num)) {
+ goto done;
+ }
}
+ ret = True;
+
+ done:
+
/* allow winbindd lookups, but only if they weren't already disabled */
if (!winbind_env) {
winbind_on();
}
- return True;
+ return ret;
}
NTSTATUS pdb_default_enum_group_members(struct pdb_methods *methods,
sid_peek_rid(&sid, &rid);
- add_rid_to_array_unique(mem_ctx, rid, pp_member_rids,
- p_num_members);
+ if (!add_rid_to_array_unique(mem_ctx, rid, pp_member_rids,
+ p_num_members)) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
}
goto done;
}
- add_rid_to_array_unique(mem_ctx, rid, pp_member_rids,
- p_num_members);
+ if (!add_rid_to_array_unique(mem_ctx, rid, pp_member_rids,
+ p_num_members)) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
ret = NT_STATUS_OK;
/* We need to add the primary group as the first gid/sid */
- add_gid_to_array_unique(mem_ctx, primary_gid, pp_gids, &num_gids);
+ if (!add_gid_to_array_unique(mem_ctx, primary_gid, pp_gids, &num_gids)) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
/* This sid will be replaced later */
- add_sid_to_array_unique(mem_ctx, &global_sid_NULL, pp_sids, &num_sids);
+ if (!add_sid_to_array_unique(mem_ctx, &global_sid_NULL, pp_sids, &num_sids)) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
for (entry = ldap_first_entry(conn->ldap_struct, result);
entry != NULL;
if (gid == primary_gid) {
sid_copy(&(*pp_sids)[0], &sid);
} else {
- add_gid_to_array_unique(mem_ctx, gid, pp_gids,
- &num_gids);
- add_sid_to_array_unique(mem_ctx, &sid, pp_sids,
- &num_sids);
+ if (!add_gid_to_array_unique(mem_ctx, gid, pp_gids,
+ &num_gids)) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+ if (!add_sid_to_array_unique(mem_ctx, &sid, pp_sids,
+ &num_sids)) {
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
}
}
if (!string_to_sid(&member, values[i]))
continue;
- add_sid_to_array(NULL, &member, pp_members, &num_members);
+ if (!add_sid_to_array(NULL, &member, pp_members, &num_members)) {
+ ldap_value_free(values);
+ ldap_msgfree(result);
+ return NT_STATUS_NO_MEMORY;
+ }
}
*p_num_members = num_members;
if (!sid_peek_check_rid(domain_sid, &sid, &rid))
continue;
- add_rid_to_array_unique(mem_ctx, rid, pp_alias_rids,
- p_num_alias_rids);
+ if (!add_rid_to_array_unique(mem_ctx, rid, pp_alias_rids,
+ p_num_alias_rids)) {
+ ldap_msgfree(result);
+ return NT_STATUS_NO_MEMORY;
+ }
}
ldap_msgfree(result);
printf("%s is not a legal SID\n", argv[i]);
return NT_STATUS_INVALID_PARAMETER;
}
- add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids);
+ if (!add_sid_to_array(mem_ctx, &tmp_sid, &sids, &num_sids)) {
+ return NT_STATUS_NO_MEMORY;
+ }
}
sid2 = TALLOC_ARRAY(mem_ctx, DOM_SID2, num_sids);
}
if (conn->ngroups && conn->groups) {
- SAFE_FREE(conn->groups);
+ TALLOC_FREE(conn->groups);
conn->ngroups = 0;
}
sid_string_static(sid)));
continue;
}
- add_gid_to_array_unique(NULL, gid, &conn->groups,
- &conn->ngroups);
+ if (!add_gid_to_array_unique(NULL, gid, &conn->groups,
+ &conn->ngroups)) {
+ DEBUG(0, ("add_gid_to_array_unique failed\n"));
+ conn_free(conn);
+ *status = NT_STATUS_NO_MEMORY;
+ return NULL;
+ }
}
}