diff options
author | George Lebl <jirka@5z.com> | 2002-07-09 15:56:34 +0000 |
---|---|---|
committer | George Lebl <jirka@src.gnome.org> | 2002-07-09 15:56:34 +0000 |
commit | 50ae5e212018bd02cb7ca49fb8debd8b4c3c6917 (patch) | |
tree | fc87413e48cea6674c5f601c491cca7b766fd016 /daemon | |
parent | f24d49dfe74822f67374ed817ad099f863f1df24 (diff) | |
download | gdm-50ae5e212018bd02cb7ca49fb8debd8b4c3c6917.tar.gz |
handle fails on user auth writing by going to the fallback file to handle
Tue Jul 09 09:08:25 2002 George Lebl <jirka@5z.com>
* daemon/auth.c: handle fails on user auth writing by going to the
fallback file to handle things in a saner way. Fixed
locking/unlocking to be done properly and fixed leaks in the purge
function.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/auth.c | 72 | ||||
-rw-r--r-- | daemon/slave.c | 8 |
2 files changed, 58 insertions, 22 deletions
diff --git a/daemon/auth.c b/daemon/auth.c index acf4eb7d..55193a34 100644 --- a/daemon/auth.c +++ b/daemon/auth.c @@ -387,24 +387,34 @@ gdm_auth_user_add (GdmDisplay *d, uid_t user, const char *homedir) FILE *af; GSList *auths = NULL; gboolean ret = TRUE; + gboolean automatic_tmp_dir = FALSE; + gboolean locked; if (!d) return FALSE; gdm_debug ("gdm_auth_user_add: Adding cookie for %d", user); +try_user_add_again: + + locked = FALSE; + /* Determine whether UserAuthDir is specified. Otherwise ~user is used */ - if (*GdmUserAuthDir) + if ( ! ve_string_empty (GdmUserAuthDir)) authdir = GdmUserAuthDir; else authdir = homedir; umask (077); - d->userauth = g_strconcat (authdir, "/", GdmUserAuthFile, NULL); + if (authdir == NULL) + d->userauth = NULL; + else + d->userauth = g_strconcat (authdir, "/", GdmUserAuthFile, NULL); /* Find out if the Xauthority file passes the paranoia check */ - if (authdir == NULL || + if (automatic_tmp_dir || + authdir == NULL || ! gdm_file_check ("gdm_auth_user_add", user, authdir, GdmUserAuthFile, TRUE, GdmUserMaxFile, GdmRelaxPerms) || ! try_open_append (d->userauth)) { @@ -438,21 +448,30 @@ gdm_auth_user_add (GdmDisplay *d, uid_t user, const char *homedir) umask (022); - return FALSE; + automatic_tmp_dir = TRUE; + goto try_user_add_again; } + locked = TRUE; + af = fopen (d->userauth, "a+"); } if (!af) { /* Really no need to clean up here - this process is a goner anyway */ gdm_error (_("gdm_auth_user_add: Could not open cookie file %s"), d->userauth); - XauUnlockAuth (d->userauth); + if (locked) + XauUnlockAuth (d->userauth); g_free (d->userauth); d->userauth = NULL; umask (022); + if ( ! d->authfb) { + automatic_tmp_dir = TRUE; + goto try_user_add_again; + } + return FALSE; } @@ -469,6 +488,17 @@ gdm_auth_user_add (GdmDisplay *d, uid_t user, const char *homedir) if ( ! XauWriteAuth (af, auths->data)) { gdm_error (_("%s: Could not write cookie"), "gdm_auth_user_add"); + + if ( ! d->authfb) { + fclose (af); + if (locked) + XauUnlockAuth (d->userauth); + g_free (d->userauth); + d->userauth = NULL; + automatic_tmp_dir = TRUE; + goto try_user_add_again; + } + ret = FALSE; break; } @@ -477,7 +507,8 @@ gdm_auth_user_add (GdmDisplay *d, uid_t user, const char *homedir) } fclose (af); - XauUnlockAuth (d->userauth); + if (locked) + XauUnlockAuth (d->userauth); gdm_debug ("gdm_auth_user_add: Done"); @@ -537,14 +568,20 @@ gdm_auth_user_remove (GdmDisplay *d, uid_t user) g_free (authfile); /* Lock user's cookie jar and open it for writing */ - if (XauLockAuth (d->userauth, 3, 3, 0) != LOCK_SUCCESS) + if (XauLockAuth (d->userauth, 3, 3, 0) != LOCK_SUCCESS) { + g_free (d->userauth); + d->userauth = NULL; return; + } af = fopen (d->userauth, "a+"); if (!af) { XauUnlockAuth (d->userauth); + g_free (d->userauth); + d->userauth = NULL; + return; } @@ -572,7 +609,7 @@ static void gdm_auth_purge (GdmDisplay *d, FILE *af) { Xauth *xa; - GSList *keep = NULL; + GSList *keep = NULL, *li; if (!d || !af) return; @@ -585,7 +622,7 @@ 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)) ) { + while ( (xa = XauReadAuth (af)) != NULL ) { gboolean match = FALSE; GSList *alist = d->auths; @@ -608,17 +645,14 @@ gdm_auth_purge (GdmDisplay *d, FILE *af) /* Rewind the file */ af = freopen (d->userauth, "w", af); - if (!af) { - XauUnlockAuth (d->userauth); - - return; - } - /* Write out remaining entries */ - while (keep) { - XauWriteAuth (af, keep->data); - XauDisposeAuth (keep->data); - keep = keep->next; + for (li = keep; li != NULL; li = li->next) { + /* FIXME: is this correct, if we can't open + * this is quite crap isn't it ... */ + if (af != NULL) + XauWriteAuth (af, li->data); + XauDisposeAuth (li->data); + li->data = NULL; } g_slist_free (keep); diff --git a/daemon/slave.c b/daemon/slave.c index eb5d5dab..83edf813 100644 --- a/daemon/slave.c +++ b/daemon/slave.c @@ -317,15 +317,17 @@ setup_automatic_session (GdmDisplay *display, const char *name) greet = FALSE; gdm_debug ("setup_automatic_session: Automatic login: %s", login); - if ( ! gdm_verify_setup_user (display, login, display->name)) - return FALSE; - /* Run the init script. gdmslave suspends until script * has terminated */ gdm_slave_exec_script (display, GdmDisplayInit, NULL, NULL); gdm_debug ("setup_automatic_session: DisplayInit script finished"); + if ( ! gdm_verify_setup_user (display, login, display->name)) + return FALSE; + + gdm_debug ("setup_automatic_session: Automatic login successful"); + return TRUE; } |