[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha8-154-g826ee30

simo idra at samba.org
Wed Jul 1 11:06:36 GMT 2009


Tridge,
this set of patches completely break the talloc ABI and changes the
behavior in ways that will break any application using
talloc_reference(), not to talk about printing to stderr, (although you
promised to fix that).

Can we revert them and discuss them on the list before applying such
radical changes ?

Simo.

On Wed, 2009-07-01 at 00:16 -0500, Andrew Tridgell wrote:
> The branch, master has been updated
>        via  826ee307fcfc24a1f133628ffec657222569b611 (commit)
>        via  27620c85e7d55e6e522b39c7aea8f83c2b5eb9b1 (commit)
>        via  0534ae012b3ef962f52fef9968eef30e88668874 (commit)
>        via  5fe1d8dc1275e43d96da1297f5fb0d0088a1c3ab (commit)
>        via  6a192020a230ab8e085f32b5559c0fe0d2f5c1a4 (commit)
>        via  386211a81ce9091db0d6dbb711dc656af412c649 (commit)
>        via  08ed6a2281121a4acca29d4f40d6959449ec9eab (commit)
>        via  269b16212a65c9506147db381ecdcbdd58347af6 (commit)
>        via  12510329217dd2b8027794b63258a34797a0f940 (commit)
>        via  956b5a0003a3ab82d2d7cffb7aee6e5281b4fbb4 (commit)
>        via  2d981919b8dd63655a39ccaa4fd7bdb39d1830f6 (commit)
>        via  45ba09457eadc8832ff40d2f8c0d5a6cc14ae3f3 (commit)
>        via  f7a6206b55ee849ceddf7e97be3fc008100ba1c6 (commit)
>        via  b2c3c08b461042de683b0e49dcaa5f9386c72f9e (commit)
>        via  9faa0745e9598a9096a7c69c30c273b47393e819 (commit)
>       from  b31f1e6d5bffddf5eb8df940bc4ff19f8bb5a7c4 (commit)
> 
> http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
> 
> 
> - Log -----------------------------------------------------------------
> commit 826ee307fcfc24a1f133628ffec657222569b611
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 15:15:13 2009 +1000
> 
>     removed a generated file
> 
> commit 27620c85e7d55e6e522b39c7aea8f83c2b5eb9b1
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 15:13:49 2009 +1000
> 
>     use a talloc_reparent in a very ugly way
>     
>     this works around some terrible use of talloc in the libnet code
> 
> commit 0534ae012b3ef962f52fef9968eef30e88668874
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:53:32 2009 +1000
> 
>     use the new talloc_reparent in two places
> 
> commit 5fe1d8dc1275e43d96da1297f5fb0d0088a1c3ab
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:53:01 2009 +1000
> 
>     changes to remove the ambiguity in talloc_free() and talloc_steal()
>     
>     These changes follow from the discussions on samba-technical. The
>     changes are in several parts, and stem from the inherent ambiguity
>     that was in talloc_free() and talloc_steal() when the pointer that is
>     being changes has more than one parent, via references.
>     
>     The changes are:
>     
>      1) when you call talloc_free() on a pointer with more than one parent
>      the free will fail, and talloc will log an error to stderr like this:
>     
>         ERROR: talloc_free with references at some/foo.c:123
>     	   reference at other/bar.c:201
>     	   reference at other/foobar.c:641
>     
>      2) Similarly, when you call talloc_steal() on a pointer with more
>      than one parent, the steal will fail and talloc will log an error to
>      stderr like this:
>     
>         ERROR: talloc_steal with references at some/foo.c:123
>     	   reference at other/bar.c:201
>     
>      3) A new function talloc_reparent() has been added to change a parent
>      in a controlled fashion. You need to supply both the old parent and
>      the new parent. It handles the case whether either the old parent was
>      a normal parent or a reference
>     
>     The use of stderr in the logging is ugly (and potentially dangerous),
>     and will be removed in a future patch. We'll need to add a debug
>     registration function to talloc.
> 
> commit 6a192020a230ab8e085f32b5559c0fe0d2f5c1a4
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:08:43 2009 +1000
> 
>     gensec_start now steals the auth_context
> 
> commit 386211a81ce9091db0d6dbb711dc656af412c649
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:08:13 2009 +1000
> 
>     A rather strange varient of talloc_unlink
>     
>     A dcerpc request may have a reference from a still completing async
>     callback, but we now consider the request to be complete. We want to
>     lose the main parent, leaving just the reference, if any.
> 
> commit 08ed6a2281121a4acca29d4f40d6959449ec9eab
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:06:56 2009 +1000
> 
>     another case that should use py_talloc_reference
> 
> commit 269b16212a65c9506147db381ecdcbdd58347af6
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:06:38 2009 +1000
> 
>     use py_talloc_reference instead of py_talloc_import
>     
>     This is one of the few cases where we want the object to be owned by
>     both the python object and C code
> 
> commit 12510329217dd2b8027794b63258a34797a0f940
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:05:53 2009 +1000
> 
>     py_talloc_import now uses a steal, so this free is incorrect
> 
> commit 956b5a0003a3ab82d2d7cffb7aee6e5281b4fbb4
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:05:17 2009 +1000
> 
>     fixed use of reference in pytalloc
>     
>     The previous code caused memory leaks, and also caused situations
>     where talloc_free could be called on pointers with multiple parents
>     
>     The new approach is to have two functions:
>     
>       py_talloc_import : steals the pointer, so it becomes wholly owned by
>                          the python object
>       py_talloc_reference: uses a reference, so it is owned by both python
>                          and C
> 
> commit 2d981919b8dd63655a39ccaa4fd7bdb39d1830f6
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:02:37 2009 +1000
> 
>     use a talloc_unlink() as ops may have a reference
> 
> commit 45ba09457eadc8832ff40d2f8c0d5a6cc14ae3f3
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:02:12 2009 +1000
> 
>     fixed the reference to the global_schema
> 
> commit f7a6206b55ee849ceddf7e97be3fc008100ba1c6
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:01:44 2009 +1000
> 
>     removed a redundent talloc_steal
> 
> commit b2c3c08b461042de683b0e49dcaa5f9386c72f9e
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 14:01:24 2009 +1000
> 
>     fixed the use of talloc_steal in ntlmssp_server
>     
>     The previous use of talloc_steal could cause a steal of a pointer that
>     had references. This ensures that doesn't happen
> 
> commit 9faa0745e9598a9096a7c69c30c273b47393e819
> Author: Andrew Tridgell <tridge at samba.org>
> Date:   Wed Jul 1 13:59:52 2009 +1000
> 
>     fixed rpc smb code to not reply on talloc_free being a function pointer
>     
>     The upcoming talloc_free/talloc_reference changes change talloc_free
>     to be a macro. These two bits of code relied on it being a function
>     pointer
> 
> -----------------------------------------------------------------------
> 
> Summary of changes:
>  lib/talloc/pytalloc.c                    |   26 ++++++-
>  lib/talloc/pytalloc.h                    |    1 +
>  lib/talloc/talloc.c                      |  119 +++++++++++++++++++++++++-----
>  lib/talloc/talloc.h                      |   16 +++--
>  source4/auth/gensec/gensec.c             |    4 +-
>  source4/auth/ntlmssp/ntlmssp_server.c    |    5 +-
>  source4/auth/pyauth.c                    |    2 +-
>  source4/auth/samba_server_gensec.c       |    2 -
>  source4/bin/python/samba/tests/shares.py |   74 ------------------
>  source4/dsdb/schema/schema_set.c         |    5 +-
>  source4/ldap_server/ldap_backend.c       |    2 +-
>  source4/libnet/libnet_join.c             |    2 +-
>  source4/libnet/libnet_rpc.c              |   13 +++-
>  source4/librpc/ndr/py_security.c         |    1 -
>  source4/librpc/rpc/dcerpc.c              |    2 +-
>  source4/librpc/rpc/dcerpc_smb.c          |    8 ++-
>  source4/librpc/rpc/dcerpc_smb2.c         |    7 ++-
>  source4/param/pyparam.c                  |    2 +-
>  source4/smb_server/smb/negprot.c         |    2 +-
>  19 files changed, 171 insertions(+), 122 deletions(-)
>  delete mode 100644 source4/bin/python/samba/tests/shares.py
> 
> 
> Changeset truncated at 500 lines:
> 
> diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
> index 30da9ee..3ce49d6 100644
> --- a/lib/talloc/pytalloc.c
> +++ b/lib/talloc/pytalloc.c
> @@ -43,7 +43,27 @@ PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx,
>  	if (ret->talloc_ctx == NULL) {
>  		return NULL;
>  	}
> -	if (talloc_reference(ret->talloc_ctx, mem_ctx) == NULL) {
> +	if (talloc_steal(ret->talloc_ctx, mem_ctx) == NULL) {
> +		return NULL;
> +	}
> +	ret->ptr = ptr;
> +	return (PyObject *)ret;
> +}
> +
> +
> +/**
> + * Import an existing talloc pointer into a Python object, leaving the
> + * original parent, and creating a reference to the object in the python
> + * object
> + */
> +PyObject *py_talloc_reference(PyTypeObject *py_type, void *ptr)
> +{
> +	py_talloc_Object *ret = (py_talloc_Object *)py_type->tp_alloc(py_type, 0);
> +	ret->talloc_ctx = talloc_new(NULL);
> +	if (ret->talloc_ctx == NULL) {
> +		return NULL;
> +	}
> +	if (talloc_reference(ret->talloc_ctx, ptr) == NULL) {
>  		return NULL;
>  	}
>  	ret->ptr = ptr;
> @@ -58,6 +78,6 @@ PyObject *py_talloc_default_repr(PyObject *obj)
>  	py_talloc_Object *talloc_obj = (py_talloc_Object *)obj;
>  	PyTypeObject *type = (PyTypeObject*)PyObject_Type(obj);
>  
> -	return PyString_FromFormat("<%s talloc object at 0x%x>", 
> -				   type->tp_name, (intptr_t)talloc_obj->ptr);
> +	return PyString_FromFormat("<%s talloc object at 0x%p>", 
> +				   type->tp_name, talloc_obj->ptr);
>  }
> diff --git a/lib/talloc/pytalloc.h b/lib/talloc/pytalloc.h
> index c5a1428..00282c4 100644
> --- a/lib/talloc/pytalloc.h
> +++ b/lib/talloc/pytalloc.h
> @@ -43,6 +43,7 @@ void py_talloc_dealloc(PyObject* self);
>  #define py_talloc_get_mem_ctx(py_obj)  ((py_talloc_Object *)py_obj)->talloc_ctx
>  
>  PyObject *py_talloc_import_ex(PyTypeObject *py_type, TALLOC_CTX *mem_ctx, void *ptr);
> +PyObject *py_talloc_reference(PyTypeObject *py_type, void *ptr);
>  #define py_talloc_import(py_type, talloc_ptr) py_talloc_import_ex(py_type, talloc_ptr, talloc_ptr)
>  
>  /* Sane default implementation of reprfunc. */
> diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c
> index 33cbfd7..bf2fb1f 100644
> --- a/lib/talloc/talloc.c
> +++ b/lib/talloc/talloc.c
> @@ -107,6 +107,7 @@ static void *autofree_context;
>  struct talloc_reference_handle {
>  	struct talloc_reference_handle *next, *prev;
>  	void *ptr;
> +	const char *location;
>  };
>  
>  typedef int (*talloc_destructor_t)(void *);
> @@ -465,7 +466,7 @@ static inline void *_talloc_named_const(const void *context, size_t size, const
>    same underlying data, and you want to be able to free the two instances separately,
>    and in either order
>  */
> -void *_talloc_reference(const void *context, const void *ptr)
> +void *_talloc_reference(const void *context, const void *ptr, const char *location)
>  {
>  	struct talloc_chunk *tc;
>  	struct talloc_reference_handle *handle;
> @@ -482,6 +483,7 @@ void *_talloc_reference(const void *context, const void *ptr)
>  	   own destructor on the context if they want to */
>  	talloc_set_destructor(handle, talloc_reference_destructor);
>  	handle->ptr = discard_const_p(void, ptr);
> +	handle->location = location;
>  	_TLIST_ADD(tc->refs, handle);
>  	return handle->ptr;
>  }
> @@ -490,7 +492,7 @@ void *_talloc_reference(const void *context, const void *ptr)
>  /* 
>     internal talloc_free call
>  */
> -static inline int _talloc_free(void *ptr)
> +static inline int _talloc_free_internal(void *ptr)
>  {
>  	struct talloc_chunk *tc;
>  
> @@ -510,9 +512,9 @@ static inline int _talloc_free(void *ptr)
>  		 * pointer.
>  		 */
>  		is_child = talloc_is_parent(tc->refs, ptr);
> -		_talloc_free(tc->refs);
> +		_talloc_free_internal(tc->refs);
>  		if (is_child) {
> -			return _talloc_free(ptr);
> +			return _talloc_free_internal(ptr);
>  		}
>  		return -1;
>  	}
> @@ -559,12 +561,12 @@ static inline int _talloc_free(void *ptr)
>  			struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
>  			if (p) new_parent = TC_PTR_FROM_CHUNK(p);
>  		}
> -		if (unlikely(_talloc_free(child) == -1)) {
> +		if (unlikely(_talloc_free_internal(child) == -1)) {
>  			if (new_parent == null_context) {
>  				struct talloc_chunk *p = talloc_parent_chunk(ptr);
>  				if (p) new_parent = TC_PTR_FROM_CHUNK(p);
>  			}
> -			talloc_steal(new_parent, child);
> +			_talloc_steal_internal(new_parent, child);
>  		}
>  	}
>  
> @@ -600,7 +602,7 @@ static inline int _talloc_free(void *ptr)
>     ptr on success, or NULL if it could not be transferred.
>     passing NULL as ptr will always return NULL with no side effects.
>  */
> -void *_talloc_steal(const void *new_ctx, const void *ptr)
> +void *_talloc_steal_internal(const void *new_ctx, const void *ptr)
>  {
>  	struct talloc_chunk *tc, *new_tc;
>  
> @@ -653,6 +655,66 @@ void *_talloc_steal(const void *new_ctx, const void *ptr)
>  }
>  
> 
> +/* 
> +   move a lump of memory from one talloc context to another return the
> +   ptr on success, or NULL if it could not be transferred.
> +   passing NULL as ptr will always return NULL with no side effects.
> +*/
> +void *_talloc_steal(const void *new_ctx, const void *ptr, const char *location)
> +{
> +	struct talloc_chunk *tc;
> +
> +	if (unlikely(ptr == NULL)) {
> +		return NULL;
> +	}
> +	
> +	tc = talloc_chunk_from_ptr(ptr);
> +	
> +	if (unlikely(tc->refs != NULL) && talloc_parent(ptr) != new_ctx) {
> +		struct talloc_reference_handle *h;
> +		fprintf(stderr, "ERROR: talloc_steal with references at %s\n", location);
> +		for (h=tc->refs; h; h=h->next) {
> +			fprintf(stderr, "\treference at %s\n", h->location);
> +		}
> +		return NULL;
> +	}
> +	
> +	return _talloc_steal_internal(new_ctx, ptr);
> +}
> +
> +/* 
> +   this is like a talloc_steal(), but you must supply the old
> +   parent. This resolves the ambiguity in a talloc_steal() which is
> +   called on a context that has more than one parent (via references)
> +
> +   The old parent can be either a reference or a parent
> +*/
> +void *talloc_reparent(const void *old_parent, const void *new_parent, const void *ptr)
> +{
> +	struct talloc_chunk *tc;
> +	struct talloc_reference_handle *h;
> +
> +	if (unlikely(ptr == NULL)) {
> +		return NULL;
> +	}
> +
> +	if (old_parent == talloc_parent(ptr)) {
> +		return _talloc_steal_internal(new_parent, ptr);
> +	}
> +
> +	tc = talloc_chunk_from_ptr(ptr);
> +	for (h=tc->refs;h;h=h->next) {
> +		if (talloc_parent(h) == old_parent) {
> +			if (_talloc_steal_internal(new_parent, h) != h) {
> +				return NULL;
> +			}
> +			return ptr;
> +		}
> +	}	
> +
> +	/* it wasn't a parent */
> +	return NULL;
> +}
>  
>  /*
>    remove a secondary reference to a pointer. This undo's what
> @@ -680,7 +742,7 @@ static inline int talloc_unreference(const void *context, const void *ptr)
>  		return -1;
>  	}
>  
> -	return _talloc_free(h);
> +	return _talloc_free_internal(h);
>  }
>  
>  /*
> @@ -717,7 +779,7 @@ int talloc_unlink(const void *context, void *ptr)
>  	tc_p = talloc_chunk_from_ptr(ptr);
>  
>  	if (tc_p->refs == NULL) {
> -		return _talloc_free(ptr);
> +		return _talloc_free_internal(ptr);
>  	}
>  
>  	new_p = talloc_parent_chunk(tc_p->refs);
> @@ -731,7 +793,7 @@ int talloc_unlink(const void *context, void *ptr)
>  		return -1;
>  	}
>  
> -	talloc_steal(new_parent, ptr);
> +	_talloc_steal_internal(new_parent, ptr);
>  
>  	return 0;
>  }
> @@ -784,7 +846,7 @@ void *talloc_named(const void *context, size_t size, const char *fmt, ...)
>  	va_end(ap);
>  
>  	if (unlikely(name == NULL)) {
> -		_talloc_free(ptr);
> +		_talloc_free_internal(ptr);
>  		return NULL;
>  	}
>  
> @@ -882,7 +944,7 @@ void *talloc_init(const char *fmt, ...)
>  	va_end(ap);
>  
>  	if (unlikely(name == NULL)) {
> -		_talloc_free(ptr);
> +		_talloc_free_internal(ptr);
>  		return NULL;
>  	}
>  
> @@ -916,12 +978,12 @@ void talloc_free_children(void *ptr)
>  			struct talloc_chunk *p = talloc_parent_chunk(tc->child->refs);
>  			if (p) new_parent = TC_PTR_FROM_CHUNK(p);
>  		}
> -		if (unlikely(_talloc_free(child) == -1)) {
> +		if (unlikely(talloc_free(child) == -1)) {
>  			if (new_parent == null_context) {
>  				struct talloc_chunk *p = talloc_parent_chunk(ptr);
>  				if (p) new_parent = TC_PTR_FROM_CHUNK(p);
>  			}
> -			talloc_steal(new_parent, child);
> +			_talloc_steal_internal(new_parent, child);
>  		}
>  	}
>  
> @@ -969,9 +1031,26 @@ void *talloc_named_const(const void *context, size_t size, const char *name)
>     will not be freed if the ref_count is > 1 or the destructor (if
>     any) returns non-zero
>  */
> -int talloc_free(void *ptr)
> +int _talloc_free(void *ptr, const char *location)
>  {
> -	return _talloc_free(ptr);
> +	struct talloc_chunk *tc;
> +
> +	if (unlikely(ptr == NULL)) {
> +		return -1;
> +	}
> +	
> +	tc = talloc_chunk_from_ptr(ptr);
> +	
> +	if (unlikely(tc->refs != NULL)) {
> +		struct talloc_reference_handle *h;
> +		fprintf(stderr, "ERROR: talloc_free with references at %s\n", location);
> +		for (h=tc->refs; h; h=h->next) {
> +			fprintf(stderr, "\treference at %s\n", h->location);
> +		}
> +		return -1;
> +	}
> +	
> +	return _talloc_free_internal(ptr);
>  }
>  
> 
> @@ -988,7 +1067,7 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
>  
>  	/* size zero is equivalent to free() */
>  	if (unlikely(size == 0)) {
> -		_talloc_free(ptr);
> +		talloc_free(ptr);
>  		return NULL;
>  	}
>  
> @@ -1085,7 +1164,7 @@ void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *n
>  void *_talloc_move(const void *new_ctx, const void *_pptr)
>  {
>  	const void **pptr = discard_const_p(const void *,_pptr);
> -	void *ret = _talloc_steal(new_ctx, *pptr);
> +	void *ret = talloc_steal(new_ctx, *pptr);
>  	(*pptr) = NULL;
>  	return ret;
>  }
> @@ -1306,7 +1385,7 @@ void talloc_enable_null_tracking(void)
>  */
>  void talloc_disable_null_tracking(void)
>  {
> -	_talloc_free(null_context);
> +	talloc_free(null_context);
>  	null_context = NULL;
>  }
>  
> @@ -1688,7 +1767,7 @@ static int talloc_autofree_destructor(void *ptr)
>  
>  static void talloc_autofree(void)
>  {
> -	_talloc_free(autofree_context);
> +	talloc_free(autofree_context);
>  }
>  
>  /*
> diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h
> index a4b33c3..9d1aa0d 100644
> --- a/lib/talloc/talloc.h
> +++ b/lib/talloc/talloc.h
> @@ -69,15 +69,15 @@ typedef void TALLOC_CTX;
>  	} while(0)
>  /* this extremely strange macro is to avoid some braindamaged warning
>     stupidity in gcc 4.1.x */
> -#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr)); __talloc_steal_ret; })
> +#define talloc_steal(ctx, ptr) ({ _TALLOC_TYPEOF(ptr) __talloc_steal_ret = (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr), __location__); __talloc_steal_ret; })
>  #else
>  #define talloc_set_destructor(ptr, function) \
>  	_talloc_set_destructor((ptr), (int (*)(void *))(function))
>  #define _TALLOC_TYPEOF(ptr) void *
> -#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr))
> +#define talloc_steal(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_steal((ctx),(ptr), __location__)
>  #endif
>  
> -#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr))
> +#define talloc_reference(ctx, ptr) (_TALLOC_TYPEOF(ptr))_talloc_reference((ctx),(ptr), __location__)
>  #define talloc_move(ctx, ptr) (_TALLOC_TYPEOF(*(ptr)))_talloc_move((ctx),(void *)(ptr))
>  
>  /* useful macros for creating type checked pointers */
> @@ -106,6 +106,8 @@ typedef void TALLOC_CTX;
>  #define talloc_get_type_abort(ptr, type) (type *)_talloc_get_type_abort(ptr, #type, __location__)
>  
>  #define talloc_find_parent_bytype(ptr, type) (type *)talloc_find_parent_byname(ptr, #type)
> +#define talloc_free(ctx) _talloc_free(ctx, __location__)
> +
>  
>  #if TALLOC_DEPRECATED
>  #define talloc_zero_p(ctx, type) talloc_zero(ctx, type)
> @@ -124,7 +126,7 @@ void *talloc_pool(const void *context, size_t size);
>  void _talloc_set_destructor(const void *ptr, int (*_destructor)(void *));
>  int talloc_increase_ref_count(const void *ptr);
>  size_t talloc_reference_count(const void *ptr);
> -void *_talloc_reference(const void *context, const void *ptr);
> +void *_talloc_reference(const void *context, const void *ptr, const char *location);
>  int talloc_unlink(const void *context, void *ptr);
>  const char *talloc_set_name(const void *ptr, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
>  void talloc_set_name_const(const void *ptr, const char *name);
> @@ -137,10 +139,12 @@ void *_talloc_get_type_abort(const void *ptr, const char *name, const char *loca
>  void *talloc_parent(const void *ptr);
>  const char *talloc_parent_name(const void *ptr);
>  void *talloc_init(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
> -int talloc_free(void *ptr);
> +int _talloc_free(void *ptr, const char *location);
>  void talloc_free_children(void *ptr);
>  void *_talloc_realloc(const void *context, void *ptr, size_t size, const char *name);
> -void *_talloc_steal(const void *new_ctx, const void *ptr);
> +void *_talloc_steal(const void *new_ctx, const void *ptr, const char *location);
> +void *_talloc_steal_internal(const void *new_ctx, const void *ptr);
> +void *talloc_reparent(const void *old_parent, const void *new_parent, const void *ptr);
>  void *_talloc_move(const void *new_ctx, const void *pptr);
>  size_t talloc_total_size(const void *ptr);
>  size_t talloc_total_blocks(const void *ptr);
> diff --git a/source4/auth/gensec/gensec.c b/source4/auth/gensec/gensec.c
> index 2feb545..1addf93 100644
> --- a/source4/auth/gensec/gensec.c
> +++ b/source4/auth/gensec/gensec.c
> @@ -504,6 +504,8 @@ const char **gensec_security_oids(struct gensec_security *gensec_security,
>    @param mem_ctx The parent TALLOC memory context.
>    @param gensec_security Returned GENSEC context pointer.
>    @note  The mem_ctx is only a parent and may be NULL.
> +  @note, the auth context is moved to be a child of the
> +  @ gensec_security return 
>  */
>  static NTSTATUS gensec_start(TALLOC_CTX *mem_ctx, 
>  			     struct tevent_context *ev,
> @@ -532,7 +534,7 @@ static NTSTATUS gensec_start(TALLOC_CTX *mem_ctx,
>  	(*gensec_security)->event_ctx = ev;
>  	SMB_ASSERT(settings->lp_ctx != NULL);
>  	(*gensec_security)->settings = talloc_reference(*gensec_security, settings);
> -	(*gensec_security)->auth_context = talloc_reference(*gensec_security, auth_context);
> +	(*gensec_security)->auth_context = talloc_steal(*gensec_security, auth_context);
>  
>  	return NT_STATUS_OK;
>  }
> diff --git a/source4/auth/ntlmssp/ntlmssp_server.c b/source4/auth/ntlmssp/ntlmssp_server.c
> index 00d3e56..28169d9 100644
> --- a/source4/auth/ntlmssp/ntlmssp_server.c
> +++ b/source4/auth/ntlmssp/ntlmssp_server.c
> @@ -458,6 +458,7 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security,
>  
>  	} else if (user_session_key && user_session_key->data) {
>  		session_key = *user_session_key;
> +		talloc_steal(gensec_ntlmssp_state, session_key.data);
>  		DEBUG(10,("ntlmssp_server_auth: Using unmodified nt session key.\n"));
>  		dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
>  
> @@ -467,6 +468,7 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security,
>  	} else if (lm_session_key && lm_session_key->data) {
>  		/* Very weird to have LM key, but no user session key, but anyway.. */
>  		session_key = *lm_session_key;
> +		talloc_steal(gensec_ntlmssp_state, session_key.data);
>  		DEBUG(10,("ntlmssp_server_auth: Using unmodified lm session key.\n"));
>  		dump_data_pw("unmodified session key:\n", session_key.data, session_key.length);
>  
> @@ -511,9 +513,6 @@ static NTSTATUS ntlmssp_server_postauth(struct gensec_security *gensec_security,
>  		gensec_ntlmssp_state->session_key = session_key;
>  	}
>  
> -	/* keep the session key around on the new context */
> -	talloc_steal(gensec_ntlmssp_state, session_key.data);
> -
>  	if ((gensec_security->want_features & GENSEC_FEATURE_SIGN)
>  	    || (gensec_security->want_features & GENSEC_FEATURE_SEAL)) {
>  		nt_status = ntlmssp_sign_init(gensec_ntlmssp_state);
> diff --git a/source4/auth/pyauth.c b/source4/auth/pyauth.c
> index e97174f..04880b7 100644
> --- a/source4/auth/pyauth.c
> +++ b/source4/auth/pyauth.c
> @@ -32,7 +32,7 @@ PyTypeObject PyAuthSession = {
>  
>  PyObject *PyAuthSession_FromSession(struct auth_session_info *session)
>  {
> -	return py_talloc_import(&PyAuthSession, session);
> +	return py_talloc_reference(&PyAuthSession, session);
>  }
>  
>  static PyObject *py_system_session(PyObject *module, PyObject *args)
> diff --git a/source4/auth/samba_server_gensec.c b/source4/auth/samba_server_gensec.c
> index 0576b15..31f52fc 100644
> --- a/source4/auth/samba_server_gensec.c
> +++ b/source4/auth/samba_server_gensec.c
> @@ -61,8 +61,6 @@ NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
>  		return nt_status;
>  	}
>  	
> -	talloc_steal(gensec_ctx, auth_context);
> -
>  	gensec_set_credentials(gensec_ctx, server_credentials);
>  
>  	if (target_service) {
> diff --git a/source4/bin/python/samba/tests/shares.py b/source4/bin/python/samba/tests/shares.py
> deleted file mode 100644
> index 9130c36..0000000
> --- a/source4/bin/python/samba/tests/shares.py
> +++ /dev/null
> @@ -1,74 +0,0 @@
> -#!/usr/bin/python
> -
> -# Unix SMB/CIFS implementation. Tests for shares
> -# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2009
> -#   
> -# This program is free software; you can redistribute it and/or modify
> -# it under the terms of the GNU General Public License as published by
> -# the Free Software Foundation; either version 3 of the License, or
> -# (at your option) any later version.
> -#   
> -# This program is distributed in the hope that it will be useful,
> -# but WITHOUT ANY WARRANTY; without even the implied warranty of
> -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> -# GNU General Public License for more details.
> -#   
> -# You should have received a copy of the GNU General Public License
> -# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> -#
> -from samba.shares import SharesContainer
> -from unittest import TestCase
> -
> -
> -class MockService(object):
> -
> -    def __init__(self, data):
> -        self.data = data
> -
> -    def __getitem__(self, name):
> -        return self.data[name]
> -
> -
> -class MockLoadParm(object):
> -
> -    def __init__(self, data):
> -        self.data = data
> -
> -    def __getitem__(self, name):
> -        return MockService(self.data[name])
> -
> -    def __contains__(self, name):
> 
> 
-- 
Simo Sorce
Samba Team GPL Compliance Officer <simo at samba.org>
Principal Software Engineer at Red Hat, Inc. <simo at redhat.com>



More information about the samba-technical mailing list