mirror of
https://github.com/samba-team/samba.git
synced 2025-08-22 13:49:27 +03:00
s3:net: Refactor ads_group_delete(), allocate a talloc context
ADS_STRUCT will be allocated in the talloc context. Signed-off-by: Samuel Cabrero <scabrero@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
committed by
Jeremy Allison
parent
66a72fbe01
commit
356aa3e357
@ -1253,39 +1253,48 @@ static int ads_group_add(struct net_context *c, int argc, const char **argv)
|
|||||||
|
|
||||||
static int ads_group_delete(struct net_context *c, int argc, const char **argv)
|
static int ads_group_delete(struct net_context *c, int argc, const char **argv)
|
||||||
{
|
{
|
||||||
ADS_STRUCT *ads;
|
TALLOC_CTX *tmp_ctx = talloc_stackframe();
|
||||||
ADS_STATUS rc;
|
ADS_STRUCT *ads = NULL;
|
||||||
|
ADS_STATUS status;
|
||||||
LDAPMessage *res = NULL;
|
LDAPMessage *res = NULL;
|
||||||
char *groupdn;
|
char *groupdn = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (argc < 1 || c->display_usage) {
|
if (argc < 1 || c->display_usage) {
|
||||||
|
TALLOC_FREE(tmp_ctx);
|
||||||
return net_ads_group_usage(c, argc, argv);
|
return net_ads_group_usage(c, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ADS_ERR_OK(ads_startup(c, false, &ads))) {
|
status = ads_startup(c, false, &ads);
|
||||||
return -1;
|
if (!ADS_ERR_OK(status)) {
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = ads_find_user_acct(ads, &res, argv[0]);
|
status = ads_find_user_acct(ads, &res, argv[0]);
|
||||||
if (!ADS_ERR_OK(rc) || ads_count_replies(ads, res) != 1) {
|
if (!ADS_ERR_OK(status) || ads_count_replies(ads, res) != 1) {
|
||||||
d_printf(_("Group %s does not exist.\n"), argv[0]);
|
d_printf(_("Group %s does not exist.\n"), argv[0]);
|
||||||
ads_msgfree(ads, res);
|
goto out;
|
||||||
ads_destroy(&ads);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
groupdn = ads_get_dn(ads, talloc_tos(), res);
|
|
||||||
|
groupdn = ads_get_dn(ads, tmp_ctx, res);
|
||||||
|
if (groupdn == NULL) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = ads_del_dn(ads, groupdn);
|
||||||
|
if (!ADS_ERR_OK(status)) {
|
||||||
|
d_fprintf(stderr, _("Error deleting group %s: %s\n"), argv[0],
|
||||||
|
ads_errstr(status));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
d_printf(_("Group %s deleted\n"), argv[0]);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
out:
|
||||||
ads_msgfree(ads, res);
|
ads_msgfree(ads, res);
|
||||||
rc = ads_del_dn(ads, groupdn);
|
|
||||||
TALLOC_FREE(groupdn);
|
|
||||||
if (ADS_ERR_OK(rc)) {
|
|
||||||
d_printf(_("Group %s deleted\n"), argv[0]);
|
|
||||||
ads_destroy(&ads);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
d_fprintf(stderr, _("Error deleting group %s: %s\n"), argv[0],
|
|
||||||
ads_errstr(rc));
|
|
||||||
ads_destroy(&ads);
|
ads_destroy(&ads);
|
||||||
return -1;
|
TALLOC_FREE(tmp_ctx);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_ads_group(struct net_context *c, int argc, const char **argv)
|
int net_ads_group(struct net_context *c, int argc, const char **argv)
|
||||||
|
Reference in New Issue
Block a user