summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBranden Robinson <branden@debian.org>2010-01-05 16:40:21 +0000
committerJulien Cristau <jcristau@debian.org>2010-01-12 18:08:17 +0000
commit17105faffcb4533da71f0d3d17fd40a64b6faf50 (patch)
treed564343b5e2eef5d22b9ac44c3889c4c436d7d3b
parent11d6aa0b392daef2900681b70960d8be4ada89a9 (diff)
Always attempt to write data to the auth file
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@debian.org>. Signed-off-by: Julien Cristau <jcristau@debian.org> Reviewed-by: Alan Coopersmith <alan.coopersmith@sun.com> Reviewed-by: Matthieu Herrb <matthieu.herrb@laas.fr>
-rw-r--r--auth.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/auth.c b/auth.c
index b80f16d..e59d2ce 100644
--- a/auth.c
+++ b/auth.c
@@ -401,6 +401,8 @@ SaveServerAuthorizations (
mode_t mask;
int ret;
int i;
+ const 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;