[REPOST PATCH xauth] Make matching algorithm mimic XauGet*AuthByAddr

walter harms wharms at bfs.de
Wed Aug 14 09:53:05 PDT 2013



Am 14.08.2013 17:10, schrieb Egbert Eich:
> Xlib (xcb) uses XauGetBestAuthByAddr() when looking for an
> authorization. 'xauth [n]list $DISPLAY' used a slightly
> stricter algorithm which doesn't find a possible authorization
> for cases where either the family is set to FamilyWild or
> address the address length is 0.
> 
> Signed-off-by: Egbert Eich <eich at freedesktop.org>
> ---
>  process.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/process.c b/process.c
> index a9466a7..0e12a56 100644
> --- a/process.c
> +++ b/process.c
> @@ -1064,11 +1064,13 @@ eq_auth(Xauth *a, Xauth *b)
>  static int
>  match_auth_dpy(register Xauth *a, register Xauth *b)
>  {
> -    return ((a->family == b->family &&
> -	     a->address_length == b->address_length &&
> -	     a->number_length == b->number_length &&
> -	     memcmp(a->address, b->address, a->address_length) == 0 &&
> -	     memcmp(a->number, b->number, a->number_length) == 0) ? 1 : 0);
> +    return (((a->family == FamilyWild || b->family == FamilyWild ||
> +	     (a->family == b->family &&
> +	      a->address_length == b->address_length &&
> +	      memcmp(a->address, b->address, a->address_length) == 0)) &&
> +	    (a->number_length == 0 || b->number_length == 0 ||
> +	     (a->number_length == b->number_length &&
> +	      memcmp(a->number, b->number, a->number_length) == 0))) ? 1 : 0);
>  }
>  
making this a bit more readable would be a nice add on.
here my suggestion:

/* Families do not match */
if ( a->family != FamilyWild && b->family != FamilyWild || a->family != b->family)
	return 0;

/* addresses do not match */
if ( a->address_length != b->address_length || memcmp(a->address, b->address, a->address_length) != 0 )
	return 0;

/* if any length is zero nothing to compare (why no such check above ?) */
if (  a->number_length == 0 || b->number_length == 0 )
	return 1;

/* number does not match */
if ( a->number_length != b->number_length || memcmp(a->number, b->number, a->number_length) != 0)
	return 0;

/* we have a match ! */
return 1;


no warranty, just my 2 cents,
re,
 wh

>  /* return non-zero iff display and authorization type are the same */


More information about the xorg-devel mailing list