diff options
author | Gerald Carter <jerry@samba.org> | 2007-04-11 12:32:58 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:19:18 -0500 |
commit | d1491cc5005c216588e6dfe957a2247132b6c9ef (patch) | |
tree | 9815a69e5f5fcf4caeaa0dbba57b639bfeb44b2c /source3/nsswitch/idmap_ad.c | |
parent | 59f23e9319643eae1100a26ac95626ae1f2bcf81 (diff) | |
download | samba-d1491cc5005c216588e6dfe957a2247132b6c9ef.tar.gz samba-d1491cc5005c216588e6dfe957a2247132b6c9ef.tar.bz2 samba-d1491cc5005c216588e6dfe957a2247132b6c9ef.zip |
r22173: BUG 4491, 4501: Additional fixes for protecting against
crashes in allocate_id().
BUG 4501: Fix segv in idmap_ad caused by resetting the
entry iterator when parsing search results.
(This used to be commit bd6ebbfb9fb9d95bdf41eab1fd134170fcf6b6bf)
Diffstat (limited to 'source3/nsswitch/idmap_ad.c')
-rw-r--r-- | source3/nsswitch/idmap_ad.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/source3/nsswitch/idmap_ad.c b/source3/nsswitch/idmap_ad.c index eff3545d15..87f73f99f0 100644 --- a/source3/nsswitch/idmap_ad.c +++ b/source3/nsswitch/idmap_ad.c @@ -166,7 +166,6 @@ static NTSTATUS idmap_ad_initialize(struct idmap_domain *dom, const char *params char *config_option; const char *range = NULL; const char *schema_mode = NULL; - ADS_STRUCT *ads; if ( (ctx = talloc_zero(dom, struct idmap_ad_context)) == NULL ) { DEBUG(0, ("Out of memory!\n")); @@ -261,6 +260,7 @@ static NTSTATUS idmap_ad_unixids_to_sids(struct idmap_domain *dom, struct id_map NULL, /* gidnumber */ NULL }; LDAPMessage *res = NULL; + LDAPMessage *entry = NULL; char *filter = NULL; int idx = 0; int bidx = 0; @@ -339,7 +339,7 @@ again: } filter = talloc_asprintf_append(filter, ")"); CHECK_ALLOC_DONE(filter); - DEBUG(10, ("Filter: [%s]\n", filter)); + rc = ads_search_retry(ads, &res, filter, attrs); if (!ADS_ERR_OK(rc)) { DEBUG(1, ("ERROR: ads search returned: %s\n", ads_errstr(rc))); @@ -351,8 +351,8 @@ again: DEBUG(10, ("No IDs found\n")); } - for (i = 0; i < count; i++) { - LDAPMessage *entry = NULL; + entry = res; + for (i = 0; (i < count) && entry; i++) { DOM_SID sid; enum id_type type; struct id_map *map; @@ -360,13 +360,14 @@ again: uint32_t atype; if (i == 0) { /* first entry */ - entry = ads_first_entry(ads, res); + entry = ads_first_entry(ads, entry); } else { /* following ones */ entry = ads_next_entry(ads, entry); } - if ( ! entry) { + + if ( !entry ) { DEBUG(2, ("ERROR: Unable to fetch ldap entries from results\n")); - continue; + break; } /* first check if the SID is present */ @@ -467,6 +468,7 @@ static NTSTATUS idmap_ad_sids_to_unixids(struct idmap_domain *dom, struct id_map NULL, /* attr_gidnumber */ NULL }; LDAPMessage *res = NULL; + LDAPMessage *entry = NULL; char *filter = NULL; int idx = 0; int bidx = 0; @@ -524,8 +526,8 @@ again: DEBUG(10, ("No IDs found\n")); } - for (i = 0; i < count; i++) { - LDAPMessage *entry = NULL; + entry = res; + for (i = 0; (i < count) && entry; i++) { DOM_SID sid; enum id_type type; struct id_map *map; @@ -533,13 +535,14 @@ again: uint32_t atype; if (i == 0) { /* first entry */ - entry = ads_first_entry(ads, res); + entry = ads_first_entry(ads, entry); } else { /* following ones */ entry = ads_next_entry(ads, entry); } - if ( ! entry) { + + if ( !entry ) { DEBUG(2, ("ERROR: Unable to fetch ldap entries from results\n")); - continue; + break; } /* first check if the SID is present */ |