static gint update_password_strength (UmPasswordDialog *um) { const gchar *password; const gchar *old_password; const gchar *username; gint strength_level; const gchar *hint; const gchar *long_hint; if (um->user == NULL) { return 0; } password = gtk_entry_get_text (GTK_ENTRY (um->password_entry)); old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry)); username = act_user_get_user_name (um->user); pw_strength (password, old_password, username, &hint, &long_hint, &strength_level); gtk_level_bar_set_value (GTK_LEVEL_BAR (um->strength_indicator), strength_level); gtk_label_set_label (GTK_LABEL (um->password_hint), long_hint); if (strength_level > 0) { set_entry_validation_checkmark (GTK_ENTRY (um->password_entry)); } else if (strlen (password) == 0) { set_entry_generation_icon (GTK_ENTRY (um->password_entry)); } else { clear_entry_validation_error (GTK_ENTRY (um->password_entry)); } return strength_level; }
static gint get_user_groups (ActUser *user, gid_t *primary, gid_t **groups) { struct passwd *pwd; const gchar *name; gint res; gint ngroups; name = act_user_get_user_name (user); pwd = getpwnam_alloc (name); if (pwd == NULL) { *primary = -1; *groups = NULL; return 0; } *primary = pwd->pw_gid; ngroups = 0; res = getgrouplist (name, *primary, NULL, &ngroups); g_debug ("user %s has %d groups", name, ngroups); *groups = g_new (gid_t, ngroups); res = getgrouplist (name, *primary, *groups, &ngroups); g_free (pwd); return res; }
void account_update (Account *acc, ActUser *user) { acc->u = user; if (user) { cockpit_account_set_user_name (COCKPIT_ACCOUNT (acc), act_user_get_user_name (user)); cockpit_account_set_real_name (COCKPIT_ACCOUNT (acc), act_user_get_real_name (user)); cockpit_account_set_locked (COCKPIT_ACCOUNT (acc), act_user_get_locked (user)); cockpit_account_set_last_login (COCKPIT_ACCOUNT (acc), act_user_get_login_time (user)); cockpit_account_set_logged_in (COCKPIT_ACCOUNT (acc), act_user_is_logged_in_anywhere (user)); cockpit_account_set_groups (COCKPIT_ACCOUNT (acc), act_user_get_groups (user)); cockpit_account_emit_changed (COCKPIT_ACCOUNT (acc)); } }
static gboolean handle_set_password_hash (CockpitAccount *object, GDBusMethodInvocation *invocation, const gchar *arg_hash) { GError *error; Account *acc = ACCOUNT (object); const gchar *argv[6]; gint status; if (!account_auth_check (object, invocation, acc)) return TRUE; if (acc->u == NULL) { cockpit_account_complete_set_password_hash (object, invocation); return TRUE; } argv[0] = "/usr/sbin/usermod"; argv[1] = "-p"; argv[2] = arg_hash; argv[3] = "--"; argv[4] = act_user_get_user_name (acc->u); argv[5] = NULL; error = NULL; if (g_spawn_sync (NULL, (gchar**)argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error)) g_spawn_check_exit_status (status, &error); if (error) { g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "Failed to change password hash via %s: %s", argv[0], error->message); g_error_free (error); } else { cockpit_account_complete_set_password_hash (object, invocation); } return TRUE; }
static gboolean handle_get_password_hash (CockpitAccount *object, GDBusMethodInvocation *invocation) { Account *acc = ACCOUNT (object); const gchar *hash = ""; if (!account_auth_check (object, invocation, acc)) return TRUE; if (acc->u) { struct spwd *sp = getspnam (act_user_get_user_name (acc->u)); if (sp && sp->sp_pwdp) hash = sp->sp_pwdp; } cockpit_account_complete_get_password_hash (object, invocation, hash); return TRUE; }
static void log_user_in (GisSummaryPage *page) { GisSummaryPagePrivate *priv = gis_summary_page_get_instance_private (page); GError *error = NULL; GdmGreeter *greeter; GdmUserVerifier *user_verifier; if (!connect_to_gdm (&greeter, &user_verifier)) { g_warning ("No GDM connection; not initiating login"); return; } g_signal_connect (user_verifier, "info", G_CALLBACK (on_info), page); g_signal_connect (user_verifier, "problem", G_CALLBACK (on_problem), page); g_signal_connect (user_verifier, "info-query", G_CALLBACK (on_info_query), page); g_signal_connect (user_verifier, "secret-info-query", G_CALLBACK (on_secret_info_query), page); g_signal_connect (greeter, "session-opened", G_CALLBACK (on_session_opened), page); /* We are in NEW_USER mode and we want to make it possible for third * parties to find out which user ID we created. */ add_uid_file (act_user_get_uid (priv->user_account)); gdm_user_verifier_call_begin_verification_for_user_sync (user_verifier, SERVICE_NAME, act_user_get_user_name (priv->user_account), NULL, &error); if (error != NULL) { g_warning ("Could not begin verification: %s", error->message); return; } }
static int update_password_strength (UmPasswordDialog *um) { const gchar *password; const gchar *old_password; const gchar *username; gint strength_level; const gchar *hint; const gchar *long_hint; password = gtk_entry_get_text (GTK_ENTRY (um->password_entry)); old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry)); username = act_user_get_user_name (um->user); pw_strength (password, old_password, username, &hint, &long_hint, &strength_level); gtk_level_bar_set_value (GTK_LEVEL_BAR (um->strength_indicator), strength_level); gtk_label_set_label (GTK_LABEL (um->strength_indicator_label), hint); gtk_widget_set_tooltip_text (um->strength_indicator, long_hint); gtk_widget_set_tooltip_text (um->strength_indicator_label, long_hint); return strength_level; }
static gboolean handle_change_groups (CockpitAccount *object, GDBusMethodInvocation *invocation, const gchar *const *arg_add, const gchar *const *arg_remove) { Account *acc = ACCOUNT (object); GError *error; int i, j, ngroups; gid_t primary; gid_t *groups; GString *str; struct group *gr; const gchar *argv[6]; gint status; if (!auth_check_sender_role (invocation, COCKPIT_ROLE_USER_ADMIN)) return TRUE; ngroups = get_user_groups (acc->u, &primary, &groups); str = g_string_new (""); for (i = 0; i < ngroups; i++) { if (groups[i] == primary) continue; gr = getgrgid_alloc (groups[i]); if (gr != NULL) { for (j = 0; arg_remove[j]; j++) { if (strcmp (gr->gr_name, arg_remove[j]) == 0) break; } if (!arg_remove[j]) g_string_append_printf (str, "%s,", gr->gr_name); g_free (gr); } } for (j = 0; arg_add[j]; j++) g_string_append_printf (str, "%s,", arg_add[j]); /* remove excess comma */ g_string_truncate (str, str->len - 1); g_free (groups); argv[0] = "/usr/sbin/usermod"; argv[1] = "-G"; argv[2] = str->str; argv[3] = "--"; argv[4] = act_user_get_user_name (acc->u); argv[5] = NULL; error = NULL; if (g_spawn_sync (NULL, (gchar**)argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error)) g_spawn_check_exit_status (status, &error); if (error) { g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "Failed to change user groups via %s: %s", argv[0], error->message); g_error_free (error); } else { account_update (acc, acc->u); cockpit_account_complete_change_groups (object, invocation); } return TRUE; }