1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

r18177: Some build- and memleak-fixes for the (not build by default) ADS GPO

routines.

Guenther
(This used to be commit 0ef504a0a6)
This commit is contained in:
Günther Deschner 2006-09-06 13:20:06 +00:00 committed by Gerald (Jerry) Carter
parent 171a5cd5c0
commit b5f6cbbe1b
2 changed files with 31 additions and 13 deletions

View File

@ -445,7 +445,7 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads,
struct GROUP_POLICY_OBJECT *gpo_list; struct GROUP_POLICY_OBJECT *gpo_list;
const char *attrs[] = {"distinguishedName", "userAccountControl", NULL}; const char *attrs[] = {"distinguishedName", "userAccountControl", NULL};
char *filter, *dn; char *filter, *dn;
void *res = NULL; LDAPMessage *res = NULL;
uint32 uac; uint32 uac;
return ADS_ERROR_NT(NT_STATUS_NOT_IMPLEMENTED); return ADS_ERROR_NT(NT_STATUS_NOT_IMPLEMENTED);
@ -473,15 +473,18 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads,
} }
if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) { if (!ads_pull_uint32(ads, res, "userAccountControl", &uac)) {
ads_memfree(ads, dn);
return ADS_ERROR(LDAP_NO_MEMORY); return ADS_ERROR(LDAP_NO_MEMORY);
} }
if (!(uac & UF_WORKSTATION_TRUST_ACCOUNT)) { if (!(uac & UF_WORKSTATION_TRUST_ACCOUNT)) {
ads_memfree(ads, dn);
return ADS_ERROR(LDAP_NO_SUCH_OBJECT); return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
} }
status = ads_get_gpo_list(ads, mem_ctx, dn, GPO_LIST_FLAG_MACHINE, &gpo_list); status = ads_get_gpo_list(ads, mem_ctx, dn, GPO_LIST_FLAG_MACHINE, &gpo_list);
if (!ADS_ERR_OK(status)) { if (!ADS_ERR_OK(status)) {
ads_memfree(ads, dn);
return status; return status;
} }
@ -489,8 +492,10 @@ ADS_STATUS gpo_password_policy(ADS_STRUCT *ads,
cse_gpo_name_to_guid_string("Security"), cse_gpo_name_to_guid_string("Security"),
GPO_LIST_FLAG_MACHINE); GPO_LIST_FLAG_MACHINE);
if (!ADS_ERR_OK(status)) { if (!ADS_ERR_OK(status)) {
ads_memfree(ads, dn);
return status; return status;
} }
ads_memfree(ads, dn);
return ADS_ERROR(LDAP_SUCCESS); return ADS_ERROR(LDAP_SUCCESS);
} }

View File

@ -47,7 +47,7 @@ static int net_ads_gpo_effective(int argc, const char **argv)
ADS_STRUCT *ads; ADS_STRUCT *ads;
ADS_STATUS status; ADS_STATUS status;
const char *attrs[] = {"distinguishedName", "userAccountControl", NULL}; const char *attrs[] = {"distinguishedName", "userAccountControl", NULL};
void *res = NULL; LDAPMessage *res = NULL;
const char *filter; const char *filter;
char *dn = NULL; char *dn = NULL;
struct GROUP_POLICY_OBJECT *gpo_list; struct GROUP_POLICY_OBJECT *gpo_list;
@ -68,7 +68,8 @@ static int net_ads_gpo_effective(int argc, const char **argv)
goto out; goto out;
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }
@ -132,18 +133,20 @@ static int net_ads_gpo_list(int argc, const char **argv)
{ {
ADS_STRUCT *ads; ADS_STRUCT *ads;
ADS_STATUS status; ADS_STATUS status;
void *res = NULL; LDAPMessage *res = NULL;
int num_reply = 0; int num_reply = 0;
void *msg = NULL; void *msg = NULL;
struct GROUP_POLICY_OBJECT gpo; struct GROUP_POLICY_OBJECT gpo;
TALLOC_CTX *mem_ctx; TALLOC_CTX *mem_ctx;
char *dn;
mem_ctx = talloc_init("net_ads_gpo_list"); mem_ctx = talloc_init("net_ads_gpo_list");
if (mem_ctx == NULL) { if (mem_ctx == NULL) {
return -1; return -1;
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }
@ -161,8 +164,12 @@ static int net_ads_gpo_list(int argc, const char **argv)
/* dump the results */ /* dump the results */
for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) { for (msg = ads_first_entry(ads, res); msg; msg = ads_next_entry(ads, msg)) {
status = ads_parse_gpo(ads, mem_ctx, msg, ads_get_dn(ads, msg), &gpo); if ((dn = ads_get_dn(ads, msg)) == NULL) {
goto out;
}
status = ads_parse_gpo(ads, mem_ctx, msg, dn, &gpo);
if (!ADS_ERR_OK(status)) { if (!ADS_ERR_OK(status)) {
d_printf("parse failed: %s\n", ads_errstr(status)); d_printf("parse failed: %s\n", ads_errstr(status));
@ -174,6 +181,7 @@ static int net_ads_gpo_list(int argc, const char **argv)
} }
out: out:
ads_memfree(ads, dn);
ads_msgfree(ads, res); ads_msgfree(ads, res);
talloc_destroy(mem_ctx); talloc_destroy(mem_ctx);
@ -188,7 +196,7 @@ static int net_ads_gpo_apply(int argc, const char **argv)
ADS_STRUCT *ads; ADS_STRUCT *ads;
ADS_STATUS status; ADS_STATUS status;
const char *attrs[] = {"distinguishedName", "userAccountControl", NULL}; const char *attrs[] = {"distinguishedName", "userAccountControl", NULL};
void *res = NULL; LDAPMessage *res = NULL;
const char *filter; const char *filter;
char *dn = NULL; char *dn = NULL;
struct GROUP_POLICY_OBJECT *gpo_list; struct GROUP_POLICY_OBJECT *gpo_list;
@ -209,7 +217,8 @@ static int net_ads_gpo_apply(int argc, const char **argv)
goto out; goto out;
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }
@ -280,7 +289,8 @@ static int net_ads_gpo_get_link(int argc, const char **argv)
return -1; return -1;
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }
@ -319,7 +329,8 @@ static int net_ads_gpo_add_link(int argc, const char **argv)
gpo_opt = atoi(argv[2]); gpo_opt = atoi(argv[2]);
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }
@ -351,7 +362,8 @@ static int net_ads_gpo_delete_link(int argc, const char **argv)
return -1; return -1;
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }
@ -385,7 +397,8 @@ static int net_ads_gpo_get_gpo(int argc, const char **argv)
return -1; return -1;
} }
if (!(ads = ads_startup())) { status = ads_startup(False, &ads);
if (!ADS_ERR_OK(status)) {
goto out; goto out;
} }