static void tldap_msg_received(struct tevent_req *subreq)
{
+ TALLOC_CTX *frame = talloc_stackframe();
struct tldap_context *ld = tevent_req_callback_data(
subreq, struct tldap_context);
struct tevent_req *req;
uint8_t type;
bool ok;
- received = read_ldap_recv(subreq, talloc_tos(), &inbuf, &err);
+ received = read_ldap_recv(subreq, frame, &inbuf, &err);
TALLOC_FREE(subreq);
ld->read_req = NULL;
if (received == -1) {
goto fail;
}
- data = asn1_init(talloc_tos(), ASN1_MAX_TREE_DEPTH);
+ data = asn1_init(frame, ASN1_MAX_TREE_DEPTH);
if (data == NULL) {
/*
* We have to disconnect all, we can't tell which of
"tldap_msg_received: got msgid 0 of "
"type %"PRIu8", disconnecting\n",
type);
- tldap_context_disconnect(ld, TLDAP_SERVER_DOWN);
- return;
+ status = TLDAP_SERVER_DOWN;
+ goto fail;
}
num_pending = talloc_array_length(ld->pending);
done:
if (num_pending == 0) {
+ TALLOC_FREE(frame);
return;
}
goto fail;
}
tevent_req_set_callback(ld->read_req, tldap_msg_received, ld);
+ TALLOC_FREE(frame);
return;
fail:
tldap_context_disconnect(ld, status);
+ TALLOC_FREE(frame);
}
static TLDAPRC tldap_msg_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
static bool tldap_push_filter_basic(struct tldap_context *ld,
struct asn1_data *data,
+ TALLOC_CTX *tmpctx,
const char **_s);
static bool tldap_push_filter_substring(struct tldap_context *ld,
struct asn1_data *data,
+ TALLOC_CTX *tmpctx,
const char *val,
const char **_s);
static bool tldap_push_filter_int(struct tldap_context *ld,
struct asn1_data *data,
+ TALLOC_CTX *tmpctx,
const char **_s)
{
const char *s = *_s;
tldap_debug(ld, TLDAP_DEBUG_TRACE, "Filter op: NOT\n");
if (!asn1_push_tag(data, TLDAP_FILTER_NOT)) return false;
s++;
- ret = tldap_push_filter_int(ld, data, &s);
+ ret = tldap_push_filter_int(ld, data, tmpctx, &s);
if (!ret) {
return false;
}
return false;
default:
- ret = tldap_push_filter_basic(ld, data, &s);
+ ret = tldap_push_filter_basic(ld, data, tmpctx, &s);
if (!ret) {
return false;
}
}
while (*s) {
- ret = tldap_push_filter_int(ld, data, &s);
+ ret = tldap_push_filter_int(ld, data, tmpctx, &s);
if (!ret) {
return false;
}
static bool tldap_push_filter_basic(struct tldap_context *ld,
struct asn1_data *data,
+ TALLOC_CTX *tmpctx,
const char **_s)
{
- TALLOC_CTX *tmpctx = talloc_tos();
const char *s = *_s;
const char *e;
const char *eq;
/* substring */
if (!asn1_push_tag(data, TLDAP_FILTER_SUB)) return false;
if (!asn1_write_OctetString(data, s, e - s)) return false;
- ret = tldap_push_filter_substring(ld, data, val, &s);
+ ret = tldap_push_filter_substring(ld, data, tmpctx, val, &s);
if (!ret) {
return false;
}
static bool tldap_push_filter_substring(struct tldap_context *ld,
struct asn1_data *data,
+ TALLOC_CTX *tmpctx,
const char *val,
const char **_s)
{
- TALLOC_CTX *tmpctx = talloc_tos();
bool initial = true;
const char *star;
char *chunk;
struct asn1_data *data,
const char *filter)
{
+ TALLOC_CTX *frame = talloc_stackframe();
const char *s = filter;
bool ret;
- ret = tldap_push_filter_int(ld, data, &s);
+ ret = tldap_push_filter_int(ld, data, frame, &s);
if (ret && *s) {
tldap_debug(ld, TLDAP_DEBUG_ERROR,
"Incomplete or malformed filter\n");
+ TALLOC_FREE(frame);
return false;
}
+ TALLOC_FREE(frame);
return ret;
}
}
if ((i == num_mods) && (talloc_array_length(mods) < num_mods + 1)) {
- mods = talloc_realloc(talloc_tos(), mods, struct tldap_mod,
+ mods = talloc_realloc(mem_ctx, mods, struct tldap_mod,
num_mods+1);
if (mods == NULL) {
return false;
struct tldap_mod **pmods, int *pnum_mods,
int mod_op, const char *attrib, const char *str)
{
+ TALLOC_CTX *frame = talloc_stackframe();
DATA_BLOB utf8;
bool ret;
- if (!convert_string_talloc(talloc_tos(), CH_UNIX, CH_UTF8, str,
+ if (!convert_string_talloc(frame, CH_UNIX, CH_UTF8, str,
strlen(str), &utf8.data, &utf8.length)) {
+ TALLOC_FREE(frame);
return false;
}
ret = tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods, mod_op, attrib,
&utf8, 1);
- TALLOC_FREE(utf8.data);
+ TALLOC_FREE(frame);
return ret;
}
static int compare_utf8_blobs(const DATA_BLOB *d1, const DATA_BLOB *d2)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *s1, *s2;
size_t s1len, s2len;
int ret;
- if (!convert_string_talloc(talloc_tos(), CH_UTF8, CH_UNIX, d1->data,
+ if (!convert_string_talloc(frame, CH_UTF8, CH_UNIX, d1->data,
d1->length, &s1, &s1len)) {
/* can't do much here */
+ TALLOC_FREE(frame);
return 0;
}
- if (!convert_string_talloc(talloc_tos(), CH_UTF8, CH_UNIX, d2->data,
+ if (!convert_string_talloc(frame, CH_UTF8, CH_UNIX, d2->data,
d2->length, &s2, &s2len)) {
/* can't do much here */
- TALLOC_FREE(s1);
+ TALLOC_FREE(frame);
return 0;
}
ret = strcasecmp_m(s1, s2);
- TALLOC_FREE(s2);
- TALLOC_FREE(s1);
+ TALLOC_FREE(frame);
return ret;
}
struct tldap_mod **pmods, int *pnum_mods,
const char *attrib, const char *fmt, ...)
{
+ TALLOC_CTX *frame = talloc_stackframe();
va_list ap;
char *newval;
bool ret;
DATA_BLOB blob = data_blob_null;
va_start(ap, fmt);
- newval = talloc_vasprintf(talloc_tos(), fmt, ap);
+ newval = talloc_vasprintf(frame, fmt, ap);
va_end(ap);
if (newval == NULL) {
+ TALLOC_FREE(frame);
return false;
}
}
ret = tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods,
attrib, blob, compare_utf8_blobs);
- TALLOC_FREE(newval);
+ TALLOC_FREE(frame);
return ret;
}
TALLOC_CTX *mem_ctx, struct tldap_message ***res,
const char *fmt, va_list ap)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *filter;
TLDAPRC rc;
- filter = talloc_vasprintf(talloc_tos(), fmt, ap);
+ filter = talloc_vasprintf(frame, fmt, ap);
if (filter == NULL) {
+ TALLOC_FREE(frame);
return TLDAP_NO_MEMORY;
}
NULL /*sctrls*/, 0, NULL /*cctrls*/, 0,
0 /*timelimit*/, 0 /*sizelimit*/, 0 /*deref*/,
mem_ctx, res);
- TALLOC_FREE(filter);
+ TALLOC_FREE(frame);
return rc;
}
bool tldap_pull_uint64(struct tldap_message *msg, const char *attr,
uint64_t *presult)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *str;
uint64_t result;
int error = 0;
- str = tldap_talloc_single_attribute(msg, attr, talloc_tos());
+ str = tldap_talloc_single_attribute(msg, attr, frame);
if (str == NULL) {
DEBUG(10, ("Could not find attribute %s\n", attr));
+ TALLOC_FREE(frame);
return false;
}
if (error != 0) {
DBG_DEBUG("Attribute conversion failed (%s)\n",
strerror(error));
- TALLOC_FREE(str);
+ TALLOC_FREE(frame);
return false;
}
- TALLOC_FREE(str);
+ TALLOC_FREE(frame);
*presult = result;
return true;
}
TALLOC_FREE(state->cookie.data);
- asn1 = asn1_init(talloc_tos(), ASN1_MAX_TREE_DEPTH);
+ asn1 = asn1_init(state, ASN1_MAX_TREE_DEPTH);
if (tevent_req_nomem(asn1, req)) {
return;
}