594
greeter_session_exited_cb (Session *session, gint status, Display *display)
596
end_greeter_session (display, status == 0);
600
greeter_session_killed_cb (Session *session, gint status, Display *display)
602
end_greeter_session (display, FALSE);
606
start_greeter (Display *display)
609
GError *error = NULL;
611
theme = load_theme (display->priv->greeter_theme, &error);
613
g_warning ("Failed to find theme %s: %s", display->priv->greeter_theme, error->message);
614
g_clear_error (&error);
593
handle_connect (Display *display)
597
if (!display->priv->greeter_connected)
619
gchar *username = NULL;
621
g_debug ("Starting greeter %s as user %s", display->priv->greeter_theme,
622
display->priv->greeter_user ? display->priv->greeter_user : "<current>");
624
command = theme_get_command (theme);
626
if (display->priv->greeter_user)
627
username = display->priv->greeter_user;
630
struct passwd *user_info;
631
user_info = getpwuid (getuid ());
634
g_warning ("Unable to determine current username: %s", strerror (errno));
637
username = user_info->pw_name;
640
display->priv->greeter_pam_session = pam_session_new (display->priv->pam_service, username);
641
pam_session_authorize (display->priv->greeter_pam_session);
643
display->priv->greeter_ck_session = start_ck_session (display,
647
display->priv->greeter_connected = FALSE;
648
display->priv->greeter_session = session_new (username, command);
649
g_signal_connect (G_OBJECT (display->priv->greeter_session), "exited", G_CALLBACK (greeter_session_exited_cb), display);
650
g_signal_connect (G_OBJECT (display->priv->greeter_session), "killed", G_CALLBACK (greeter_session_killed_cb), display);
651
child_process_set_env (CHILD_PROCESS (display->priv->greeter_session), "DISPLAY", xserver_get_address (display->priv->xserver));
652
if (display->priv->greeter_ck_session)
653
child_process_set_env (CHILD_PROCESS (display->priv->greeter_session), "XDG_SESSION_COOKIE", ck_connector_get_cookie (display->priv->greeter_ck_session));
654
set_env_from_pam_session (display->priv->greeter_session, display->priv->greeter_pam_session);
656
g_signal_emit (display, signals[START_GREETER], 0, display->priv->greeter_session);
658
session_start (display->priv->greeter_session);
661
g_key_file_free (theme);
599
display->priv->greeter_connected = TRUE;
600
g_debug ("Greeter connected");
603
child_process_write_int (CHILD_PROCESS (display->priv->greeter_session), GREETER_MESSAGE_CONNECTED);
604
theme = g_build_filename (THEME_DIR, display->priv->greeter_theme, "index.theme", NULL);
605
child_process_write_string (CHILD_PROCESS (display->priv->greeter_session), theme);
607
child_process_write_string (CHILD_PROCESS (display->priv->greeter_session), display->priv->default_layout);
608
child_process_write_string (CHILD_PROCESS (display->priv->greeter_session), display->priv->default_session);
609
child_process_write_string (CHILD_PROCESS (display->priv->greeter_session), display->priv->default_user ? display->priv->default_user : "");
610
child_process_write_int (CHILD_PROCESS (display->priv->greeter_session), display->priv->timeout);
611
child_process_flush (CHILD_PROCESS (display->priv->greeter_session));
665
#define TYPE_MESSAGE dbus_g_type_get_struct ("GValueArray", G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID)
668
615
pam_messages_cb (PAMSession *session, int num_msg, const struct pam_message **msg, Display *display)
672
DBusGMethodInvocation *context;
674
619
/* Respond to d-bus query with messages */
675
request = g_ptr_array_new ();
620
g_debug ("Prompt greeter with %d message(s)", num_msg);
621
child_process_write_int (CHILD_PROCESS (display->priv->greeter_session), GREETER_MESSAGE_PROMPT_AUTHENTICATION);
622
child_process_write_int (CHILD_PROCESS (display->priv->greeter_session), num_msg);
676
623
for (i = 0; i < num_msg; i++)
678
GValue value = { 0 };
680
g_value_init (&value, TYPE_MESSAGE);
681
g_value_take_boxed (&value, dbus_g_type_specialized_construct (TYPE_MESSAGE));
682
// FIXME: Need to convert to UTF-8
683
dbus_g_type_struct_set (&value, 0, msg[i]->msg_style, 1, msg[i]->msg, G_MAXUINT);
684
g_ptr_array_add (request, g_value_get_boxed (&value));
625
child_process_write_int (CHILD_PROCESS (display->priv->greeter_session), msg[i]->msg_style);
626
child_process_write_string (CHILD_PROCESS (display->priv->greeter_session), msg[i]->msg);
687
context = display->priv->dbus_context;
688
display->priv->dbus_context = NULL;
689
dbus_g_method_return (context, 0, request);
628
child_process_flush (CHILD_PROCESS (display->priv->greeter_session));
693
632
authenticate_result_cb (PAMSession *session, int result, Display *display)
696
DBusGMethodInvocation *context;
698
634
g_debug ("Authenticate result for user %s: %s", pam_session_get_username (display->priv->user_pam_session), pam_session_strerror (display->priv->user_pam_session, result));
700
636
if (result == PAM_SUCCESS)
717
651
display->priv->user_ck_session = start_ck_session (display, "", pam_session_get_username (display->priv->user_pam_session));
721
display_connect (Display *display,
723
const gchar **layout, const gchar **session,
724
const gchar **username, gint *delay, GError *error)
726
if (!display->priv->greeter_connected)
728
display->priv->greeter_connected = TRUE;
729
g_debug ("Greeter connected");
732
*theme = g_build_filename (THEME_DIR, display->priv->greeter_theme, "index.theme", NULL);
733
*layout = g_strdup (display->priv->default_layout);
734
*session = g_strdup (display->priv->default_session);
735
*username = g_strdup (display->priv->default_user);
736
*delay = display->priv->timeout;
742
display_start_authentication (Display *display, const gchar *username, DBusGMethodInvocation *context)
655
handle_start_authentication (Display *display, const gchar *username)
744
657
GError *error = NULL;
746
// FIXME: Only allow calls from the correct greeter
748
659
if (!display->priv->greeter_session || display->priv->user_session)
750
dbus_g_method_return_error (context, NULL);
754
662
/* Abort existing authentication */
755
663
if (display->priv->user_pam_session)
757
665
g_signal_handlers_disconnect_matched (display->priv->user_pam_session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, display);
758
666
pam_session_end (display->priv->user_pam_session);
759
if (display->priv->dbus_context)
760
dbus_g_method_return_error (display->priv->dbus_context, NULL);
762
667
g_object_unref (display->priv->user_pam_session);
765
670
g_debug ("Greeter start authentication for %s", username);
767
/* Store D-Bus request to respond to */
768
display->priv->dbus_context = context;
770
672
display->priv->user_pam_session = pam_session_new (display->priv->pam_service, username);
771
673
g_signal_connect (G_OBJECT (display->priv->user_pam_session), "got-messages", G_CALLBACK (pam_messages_cb), display);
772
674
g_signal_connect (G_OBJECT (display->priv->user_pam_session), "authentication-result", G_CALLBACK (authenticate_result_cb), display);
773
675
g_signal_connect (G_OBJECT (display->priv->user_pam_session), "started", G_CALLBACK (session_started_cb), display);
775
677
if (!pam_session_start (display->priv->user_pam_session, &error))
777
678
g_warning ("Failed to start authentication: %s", error->message);
778
display->priv->dbus_context = NULL;
779
dbus_g_method_return_error (context, NULL);
782
g_clear_error (&error);
788
display_continue_authentication (Display *display, gchar **secrets, DBusGMethodInvocation *context)
682
handle_continue_authentication (Display *display, gchar **secrets)
790
684
int num_messages;
791
685
const struct pam_message **messages;
920
799
display->priv->user_session_timer = g_timeout_add (USER_SESSION_TIMEOUT, (GSourceFunc) session_timeout_cb, display);
922
801
quit_greeter (display);
805
greeter_data_cb (Session *session, Display *display)
807
int message, n_secrets, i;
808
gchar *username, *session_name, *language;
811
/* FIXME: This could all block and lock up the server */
813
message = child_process_read_int (CHILD_PROCESS (session));
816
case GREETER_MESSAGE_CONNECT:
817
handle_connect (display);
819
case GREETER_MESSAGE_START_AUTHENTICATION:
820
username = child_process_read_string (CHILD_PROCESS (session));
821
handle_start_authentication (display, username);
824
case GREETER_MESSAGE_CONTINUE_AUTHENTICATION:
825
n_secrets = child_process_read_int (CHILD_PROCESS (session));
826
secrets = g_malloc (sizeof (gchar *) * (n_secrets + 1));
827
for (i = 0; i < n_secrets; i++)
828
secrets[i] = child_process_read_string (CHILD_PROCESS (session));
830
handle_continue_authentication (display, secrets);
831
g_strfreev (secrets);
833
case GREETER_MESSAGE_LOGIN:
834
username = child_process_read_string (CHILD_PROCESS (session));
835
session_name = child_process_read_string (CHILD_PROCESS (session));
836
language = child_process_read_string (CHILD_PROCESS (session));
837
handle_login (display, username, session_name, language);
839
g_free (session_name);
843
g_warning ("Unknown message from greeter: %d", message);
849
greeter_session_exited_cb (Session *session, gint status, Display *display)
851
end_greeter_session (display, status == 0);
855
greeter_session_killed_cb (Session *session, gint status, Display *display)
857
end_greeter_session (display, FALSE);
861
start_greeter (Display *display)
864
GError *error = NULL;
866
theme = load_theme (display->priv->greeter_theme, &error);
868
g_warning ("Failed to find theme %s: %s", display->priv->greeter_theme, error->message);
869
g_clear_error (&error);
874
gchar *username = NULL;
876
g_debug ("Starting greeter %s as user %s", display->priv->greeter_theme,
877
display->priv->greeter_user ? display->priv->greeter_user : "<current>");
879
command = theme_get_command (theme);
881
if (display->priv->greeter_user)
882
username = display->priv->greeter_user;
885
struct passwd *user_info;
886
user_info = getpwuid (getuid ());
889
g_warning ("Unable to determine current username: %s", strerror (errno));
892
username = user_info->pw_name;
895
display->priv->greeter_pam_session = pam_session_new (display->priv->pam_service, username);
896
pam_session_authorize (display->priv->greeter_pam_session);
898
display->priv->greeter_ck_session = start_ck_session (display,
902
display->priv->greeter_connected = FALSE;
903
display->priv->greeter_session = session_new (username, command);
904
g_signal_connect (G_OBJECT (display->priv->greeter_session), "got-data", G_CALLBACK (greeter_data_cb), display);
905
g_signal_connect (G_OBJECT (display->priv->greeter_session), "exited", G_CALLBACK (greeter_session_exited_cb), display);
906
g_signal_connect (G_OBJECT (display->priv->greeter_session), "killed", G_CALLBACK (greeter_session_killed_cb), display);
907
child_process_set_env (CHILD_PROCESS (display->priv->greeter_session), "DISPLAY", xserver_get_address (display->priv->xserver));
908
if (display->priv->greeter_ck_session)
909
child_process_set_env (CHILD_PROCESS (display->priv->greeter_session), "XDG_SESSION_COOKIE", ck_connector_get_cookie (display->priv->greeter_ck_session));
910
set_env_from_pam_session (display->priv->greeter_session, display->priv->greeter_pam_session);
912
g_signal_emit (display, signals[START_GREETER], 0, display->priv->greeter_session);
914
session_start (display->priv->greeter_session, TRUE);
917
g_key_file_free (theme);