summaryrefslogtreecommitdiff
path: root/daemon/auth.c
diff options
context:
space:
mode:
authorGeorge Lebl <jirka@5z.com>2003-08-16 01:44:11 +0000
committerGeorge Lebl <jirka@src.gnome.org>2003-08-16 01:44:11 +0000
commited5b916de2f38e72b2c5b8e7a0b1eeec06e4474f (patch)
treed20d2b014e4ad009c738770733413f8314b2c79a /daemon/auth.c
parente2c2f8f05ead837f6d0528e5aada44f69cf76a7d (diff)
downloadgdm-ed5b916de2f38e72b2c5b8e7a0b1eeec06e4474f.tar.gz
handle NULL addresses, purge by number and name, not by number and address
Fri Aug 15 18:32:54 2003 George Lebl <jirka@5z.com> * daemon/auth.c: handle NULL addresses, purge by number and name, not by number and address * daemon/auth.c, daemon/gdm.c: Correctly handle out of diskspace errors on auth files and on the PID file * daemon/slave.c, daemon/gdm.c: fix the runlevel checking code, damnit, it's popen, not fopen. DOH! * daemon/misc.c: use 16 lines of output for text dialogs, since some of the strings we use are quite long.
Diffstat (limited to 'daemon/auth.c')
-rw-r--r--daemon/auth.c81
1 files changed, 53 insertions, 28 deletions
diff --git a/daemon/auth.c b/daemon/auth.c
index 6dcf1f53..aa4972d9 100644
--- a/daemon/auth.c
+++ b/daemon/auth.c
@@ -85,15 +85,20 @@ add_auth_entry (GdmDisplay *d, FILE *af, FILE *af2,
return FALSE;
xa->family = family;
- xa->address = malloc (addrlen);
- if G_UNLIKELY (xa->address == NULL) {
- free (xa);
- return FALSE;
- }
+ if (addrlen == 0) {
+ xa->address = NULL;
+ xa->address_length = 0;
+ } else {
+ xa->address = malloc (addrlen);
+ if G_UNLIKELY (xa->address == NULL) {
+ free (xa);
+ return FALSE;
+ }
- memcpy (xa->address, addr, addrlen);
- xa->address_length = addrlen;
+ memcpy (xa->address, addr, addrlen);
+ xa->address_length = addrlen;
+ }
dispnum = g_strdup_printf ("%d", d->dispnum);
xa->number = strdup (dispnum);
@@ -364,9 +369,16 @@ gdm_auth_secure_display (GdmDisplay *d)
return FALSE;
}
- fclose (af);
- if (af_gdm != NULL)
- fclose (af_gdm);
+ if G_UNLIKELY (fclose (af) < 0) {
+ display_add_error (d);
+ return FALSE;
+ }
+ if (af_gdm != NULL) {
+ if G_UNLIKELY (fclose (af_gdm) < 0) {
+ display_add_error (d);
+ return FALSE;
+ }
+ }
ve_setenv ("XAUTHORITY", GDM_AUTHFILE (d), TRUE);
gdm_debug ("gdm_auth_secure_display: Setting up access for %s - %d entries",
@@ -588,7 +600,22 @@ try_user_add_again:
auths = auths->next;
}
- fclose (af);
+ if G_UNLIKELY (fclose (af) < 0) {
+ gdm_error (_("%s: Could not write cookie"),
+ "gdm_auth_user_add");
+
+ if ( ! d->authfb) {
+ if (locked)
+ XauUnlockAuth (d->userauth);
+ g_free (d->userauth);
+ d->userauth = NULL;
+ automatic_tmp_dir = TRUE;
+ goto try_user_add_again;
+ }
+
+ ret = FALSE;
+ }
+
if (locked)
XauUnlockAuth (d->userauth);
@@ -686,6 +713,7 @@ gdm_auth_user_remove (GdmDisplay *d, uid_t user)
/* Close the file and unlock it */
fclose (af);
+ /* FIXME: what about out of diskspace errors on errors close */
XauUnlockAuth (d->userauth);
g_free (d->userauth);
@@ -706,6 +734,8 @@ gdm_auth_purge (GdmDisplay *d, FILE *af)
{
Xauth *xa;
GSList *keep = NULL, *li;
+ char *dispnum;
+ int displen;
if G_UNLIKELY (!d || !af)
return af;
@@ -718,28 +748,22 @@ gdm_auth_purge (GdmDisplay *d, FILE *af)
* temporary file issues. Then remove any instance of this display
* in the cookie jar... */
- while ( (xa = XauReadAuth (af)) != NULL ) {
- gboolean match = FALSE;
- GSList *alist = d->auths;
-
- while (alist) {
- Xauth *da = alist->data;
-
- if (xa->address_length == da->address_length &&
- xa->number_length == da->number_length &&
- memcmp (da->address, xa->address, xa->address_length) == 0 &&
- memcmp (da->number, xa->number, xa->number_length) == 0)
- match = TRUE;
+ dispnum = g_strdup_printf ("%d", d->dispnum);
+ displen = strlen (dispnum);
- alist = alist->next;
- }
+ while ( (xa = XauReadAuth (af)) != NULL ) {
- if (match)
- XauDisposeAuth (xa);
+ if (xa->number_length == displen &&
+ xa->name_length == strlen ("MIT-MAGIC-COOKIE-1") &&
+ memcmp ("MIT-MAGIC-COOKIE-1", xa->name, xa->name_length) == 0 &&
+ memcmp (dispnum, xa->number, xa->number_length) == 0)
+ XauDisposeAuth (xa);
else
- keep = g_slist_append (keep, xa);
+ keep = g_slist_append (keep, xa);
}
+ g_free (dispnum);
+
/* Rewind the file */
fclose (af);
af = gdm_safe_fopen_w (d->userauth);
@@ -750,6 +774,7 @@ gdm_auth_purge (GdmDisplay *d, FILE *af)
* this is quite crap isn't it ... */
if G_LIKELY (af != NULL)
XauWriteAuth (af, li->data);
+ /* FIXME: what about errors? */
XauDisposeAuth (li->data);
li->data = NULL;
}