[gnome-control-center/wip/feborges/new-remote-desktop-dialog: 13/13] sharing/remote-desktop: Initialize username/password if not set
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/feborges/new-remote-desktop-dialog: 13/13] sharing/remote-desktop: Initialize username/password if not set
- Date: Sat, 26 Feb 2022 18:19:15 +0000 (UTC)
commit 5dc4081e2cc9836056b22e523da0c98d2cbc4afd
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Fri Feb 25 21:13:21 2022 +0100
sharing/remote-desktop: Initialize username/password if not set
If no password or username was set (not even an empty one), initialize
them to something, specifically the username of the user of the session,
and a auto generated password.
meson.build | 1 +
panels/sharing/cc-sharing-panel.c | 58 +++++++++++++++++++++++++++++++++++++--
panels/sharing/meson.build | 1 +
panels/user-accounts/meson.build | 2 +-
4 files changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/meson.build b/meson.build
index 73f2ba303..3ae35704c 100644
--- a/meson.build
+++ b/meson.build
@@ -129,6 +129,7 @@ x11_dep = dependency('x11')
xi_dep = dependency('xi', version: '>= 1.2')
epoxy_dep = dependency('epoxy')
gcr_dep = dependency('gcr-base-3')
+pwquality_dep = dependency('pwquality', version: '>= 1.2.2')
m_dep = cc.find_library('m')
diff --git a/panels/sharing/cc-sharing-panel.c b/panels/sharing/cc-sharing-panel.c
index 19489a2ca..a3bd8869d 100644
--- a/panels/sharing/cc-sharing-panel.c
+++ b/panels/sharing/cc-sharing-panel.c
@@ -41,6 +41,8 @@
#define GCR_API_SUBJECT_TO_CHANGE
#include <gcr/gcr-base.h>
+#include <pwquality.h>
+
#include <config.h>
static void cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self, GtkWidget *label);
@@ -1310,6 +1312,52 @@ on_copy_clicked_entry (GtkButton *button,
gtk_entry_buffer_get_text (buffer));
}
+static pwquality_settings_t *
+get_pwq (void)
+{
+ static pwquality_settings_t *settings;
+
+ if (settings == NULL)
+ {
+ gchar *err = NULL;
+ gint rv = 0;
+
+ settings = pwquality_default_settings ();
+ pwquality_set_int_value (settings, PWQ_SETTING_MAX_SEQUENCE, 4);
+
+ rv = pwquality_read_config (settings, NULL, (gpointer)&err);
+ if (rv < 0)
+ {
+ g_warning ("Failed to read pwquality configuration: %s\n",
+ pwquality_strerror (NULL, 0, rv, err));
+ pwquality_free_settings (settings);
+
+ /* Load just default settings in case of failure. */
+ settings = pwquality_default_settings ();
+ pwquality_set_int_value (settings, PWQ_SETTING_MAX_SEQUENCE, 4);
+ }
+ }
+
+ return settings;
+}
+
+static char *
+pw_generate (void)
+{
+ char *res;
+ int rv;
+
+ rv = pwquality_generate (get_pwq (), 0, &res);
+
+ if (rv < 0) {
+ g_warning ("Password generation failed: %s\n",
+ pwquality_strerror (NULL, 0, rv, NULL));
+ return NULL;
+ }
+
+ return res;
+}
+
static void
cc_sharing_panel_setup_remote_desktop_dialog (CcSharingPanel *self)
{
@@ -1344,10 +1392,9 @@ cc_sharing_panel_setup_remote_desktop_dialog (CcSharingPanel *self)
hostname);
username = cc_grd_lookup_rdp_username (cc_panel_get_cancellable (CC_PANEL (self)));
+ password = cc_grd_lookup_rdp_password (cc_panel_get_cancellable (CC_PANEL (self)));
if (username != NULL)
gtk_editable_set_text (GTK_EDITABLE (self->remote_desktop_username_entry), username);
-
- password = cc_grd_lookup_rdp_password (cc_panel_get_cancellable (CC_PANEL (self)));
if (password != NULL)
gtk_editable_set_text (GTK_EDITABLE (self->remote_desktop_password_entry), password);
@@ -1360,6 +1407,13 @@ cc_sharing_panel_setup_remote_desktop_dialog (CcSharingPanel *self)
G_CALLBACK (remote_desktop_credentials_changed),
self);
+ if (username == NULL)
+ gtk_editable_set_text (GTK_EDITABLE (self->remote_desktop_username_entry),
+ getlogin ());
+ if (password == NULL)
+ gtk_editable_set_text (GTK_EDITABLE (self->remote_desktop_password_entry),
+ pw_generate ());
+
g_signal_connect (self->remote_desktop_device_name_copy,
"clicked", G_CALLBACK (on_copy_clicked_label),
self->remote_desktop_device_name_label);
diff --git a/panels/sharing/meson.build b/panels/sharing/meson.build
index 12ff1202d..c674cfba1 100644
--- a/panels/sharing/meson.build
+++ b/panels/sharing/meson.build
@@ -86,6 +86,7 @@ panels_libs += static_library(
libsecret_dep,
gnutls_dep,
gcr_dep,
+ pwquality_dep,
],
c_args: cflags
)
diff --git a/panels/user-accounts/meson.build b/panels/user-accounts/meson.build
index f6c865e0e..d9efd1fd8 100644
--- a/panels/user-accounts/meson.build
+++ b/panels/user-accounts/meson.build
@@ -175,7 +175,7 @@ deps = common_deps + [
krb_dep,
m_dep,
polkit_gobject_dep,
- dependency('pwquality', version: '>= 1.2.2')
+ pwquality_dep,
]
if enable_malcontent
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]