set_up_for_current_vt (GdmSessionWorker  *worker,
                       GError           **error)
{
#ifdef PAM_XAUTHDATA
        struct pam_xauth_data *pam_xauth;
#endif
        int                    error_code = PAM_SUCCESS;
        char                  *pam_tty;

        /* set TTY */
        pam_tty = _get_tty_for_pam (worker->priv->x11_display_name, worker->priv->display_device);
        if (pam_tty != NULL && pam_tty[0] != '\0') {
                error_code = pam_set_item (worker->priv->pam_handle, PAM_TTY, pam_tty);

                if (error_code != PAM_SUCCESS) {
                        g_debug ("error informing authentication system of user's console %s: %s",
                                 pam_tty,
                                 pam_strerror (worker->priv->pam_handle, error_code));
                        g_free (pam_tty);
                        g_set_error (error,
                                     GDM_SESSION_WORKER_ERROR,
                                     GDM_SESSION_WORKER_ERROR_AUTHENTICATING,
                                     "%s", "");
                        goto out;
                }
        }
        g_free (pam_tty);

#ifdef PAM_XDISPLAY
        /* set XDISPLAY */
        if (worker->priv->x11_display_name != NULL && worker->priv->x11_display_name[0] != '\0') {
                error_code = pam_set_item (worker->priv->pam_handle, PAM_XDISPLAY, worker->priv->x11_display_name);
                if (error_code != PAM_SUCCESS) {
                        g_debug ("error informing authentication system of display string %s: %s",
                                 worker->priv->x11_display_name,
                                 pam_strerror (worker->priv->pam_handle, error_code));
                        g_set_error (error,
                                     GDM_SESSION_WORKER_ERROR,
                                     GDM_SESSION_WORKER_ERROR_AUTHENTICATING,
                                     "%s", "");
                        goto out;
                }
        }
#endif
#ifdef PAM_XAUTHDATA
        /* set XAUTHDATA */
        pam_xauth = _get_xauth_for_pam (worker->priv->x11_authority_file);
        if (pam_xauth != NULL) {
                error_code = pam_set_item (worker->priv->pam_handle, PAM_XAUTHDATA, pam_xauth);
                if (error_code != PAM_SUCCESS) {
                        g_debug ("error informing authentication system of display string %s: %s",
                                 worker->priv->x11_display_name,
                                 pam_strerror (worker->priv->pam_handle, error_code));
                        g_free (pam_xauth);

                        g_set_error (error,
                                     GDM_SESSION_WORKER_ERROR,
                                     GDM_SESSION_WORKER_ERROR_AUTHENTICATING,
                                     "%s", "");
                        goto out;
                }
                g_free (pam_xauth);
         }
#endif

        if (g_strcmp0 (worker->priv->display_seat_id, "seat0") == 0) {
                g_debug ("GdmSessionWorker: setting XDG_VTNR to current vt");
                set_xdg_vtnr_to_current_vt (worker);
        } else {
                g_debug ("GdmSessionWorker: not setting XDG_VTNR since not seat0");
        }

        return TRUE;
out:
        return FALSE;
}