[PATCH 05/10] Always attempt to write data to the auth file

Alan Coopersmith Alan.Coopersmith at Sun.COM
Tue Jan 5 10:39:39 PST 2010


Should dummy_auth be const char?

	-alan-

Julien Cristau wrote:
> From: Branden Robinson <branden at debian.org>
> 
> Actually attempt to write data to the auth file in SaveServerAuthorizations();
> that way we detect problems like ENOSPC (full filesystem, user over quota)
> early enough to do something about it.  (See Debian #217505, #253480)
> 
> Forward-ported by Julien Cristau <jcristau at debian.org>.
> ---
>  auth.c |   34 ++++++++++++++++++++++++++++++++++
>  1 files changed, 34 insertions(+), 0 deletions(-)
> 
> diff --git a/auth.c b/auth.c
> index b80f16d..571276a 100644
> --- a/auth.c
> +++ b/auth.c
> @@ -401,6 +401,8 @@ SaveServerAuthorizations (
>      mode_t	mask;
>      int		ret;
>      int		i;
> +    char	dummy_auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
> +		               "XXXXXXXXXXXXXXXXX"; /* 64 "X"s */
>  
>      mask = umask (0077);
>      ret = MakeServerAuthFile(d, &auth_file);
> @@ -418,6 +420,31 @@ SaveServerAuthorizations (
>      {
>      	Debug ("File: %s auth: %p\n", d->authFile, auths);
>  	ret = TRUE;
> +	if (count == 0)
> +	{
> +		/*
> +		 * This is a crude hack to determine whether we really can
> +		 * write to the auth file even if we don't have real data
> +		 * to write right now.
> +		 */
> +
> +		/*
> +		 * Write garbage data to file to provoke ENOSPC and other
> +		 * errors.
> +		 */
> +		(void) fprintf (auth_file, "%s", dummy_auth);
> +		(void) fflush (auth_file);
> +		if (ferror (auth_file))
> +		{
> +		    LogError ("Cannot write server authorization file %s\n",
> +			      d->authFile);
> +		    ret = FALSE;
> +		}
> +		/*
> +		 * Rewind so that the garbage data is overwritten later.
> +		 */
> +		rewind(auth_file);
> +	}
>  	for (i = 0; i < count; i++)
>  	{
>  	    /*
> @@ -436,6 +463,13 @@ SaveServerAuthorizations (
>  		    d->authFile = NULL;
>  		}
>      	}
> +	/*
> +	 * XXX: This is not elegant, but stdio has no truncation function.
> +	 */
> +	if (ftruncate(fileno(auth_file), ftell(auth_file)))
> +	{
> +		Debug ("ftruncate() failed\n");
> +	}
>  	fclose (auth_file);
>      }
>      return ret;

-- 
	-Alan Coopersmith-           alan.coopersmith at sun.com
	 Sun Microsystems, Inc. - X Window System Engineering



More information about the xorg-devel mailing list