Blame SOURCES/support-choicelist-extension.patch

0999a2
From 0994cc8fe87cfc9d78221e2e6df074257124a81d Mon Sep 17 00:00:00 2001
0999a2
From: Ray Strode <rstrode@redhat.com>
0999a2
Date: Tue, 18 Jul 2017 12:58:14 -0400
0999a2
Subject: [PATCH 1/2] gdm: add AuthList control
0999a2
0999a2
Ultimately, we want to add support for GDM's new ChoiceList
0999a2
PAM extension.  That extension allows PAM modules to present
0999a2
a list of choices to the user. Before we can support that
0999a2
extension, however, we need to have a list control in the
0999a2
login-screen/unlock screen.  This commit adds that control.
0999a2
0999a2
For the most part, it's a copy-and-paste of the gdm userlist,
0999a2
but with less features.  It lacks API specific to the users,
0999a2
lacks the built in timed login indicator, etc. It does feature
0999a2
a label heading.
0999a2
---
0999a2
 js/gdm/authList.js            | 193 ++++++++++++++++++++++++++++++++++
0999a2
 js/js-resources.gresource.xml |   1 +
0999a2
 2 files changed, 194 insertions(+)
0999a2
 create mode 100644 js/gdm/authList.js
0999a2
0999a2
diff --git a/js/gdm/authList.js b/js/gdm/authList.js
0999a2
new file mode 100644
0999a2
index 000000000..e4475dc20
0999a2
--- /dev/null
0999a2
+++ b/js/gdm/authList.js
0999a2
@@ -0,0 +1,193 @@
0999a2
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
0999a2
+/*
0999a2
+ * Copyright 2017 Red Hat, Inc
0999a2
+ *
0999a2
+ * This program is free software; you can redistribute it and/or modify
0999a2
+ * it under the terms of the GNU General Public License as published by
0999a2
+ * the Free Software Foundation; either version 2, or (at your option)
0999a2
+ * any later version.
0999a2
+ *
0999a2
+ * This program is distributed in the hope that it will be useful,
0999a2
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
0999a2
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0999a2
+ * GNU General Public License for more details.
0999a2
+ *
0999a2
+ * You should have received a copy of the GNU General Public License
0999a2
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
0999a2
+ */
0999a2
+/* exported AuthList */
0999a2
+
0999a2
+const { Clutter, GObject, Meta, St } = imports.gi;
0999a2
+
0999a2
+const SCROLL_ANIMATION_TIME = 500;
0999a2
+
0999a2
+const AuthListItem = GObject.registerClass({
0999a2
+    Signals: { 'activate': {} },
0999a2
+}, class AuthListItem extends St.Button {
0999a2
+    _init(key, text) {
0999a2
+        this.key = key;
0999a2
+        const label = new St.Label({
0999a2
+            style_class: 'auth-list-item-label',
0999a2
+            y_align: Clutter.ActorAlign.CENTER,
0999a2
+        });
0999a2
+        label.text = text;
0999a2
+
0999a2
+        super._init({
0999a2
+            style_class: 'login-dialog-user-list-item',
0999a2
+            button_mask: St.ButtonMask.ONE | St.ButtonMask.THREE,
0999a2
+            can_focus: true,
0999a2
+            child: label,
0999a2
+            reactive: true,
0999a2
+            x_align: St.Align.START,
0999a2
+            x_fill: true,
0999a2
+        });
0999a2
+
0999a2
+        this.connect('key-focus-in',
0999a2
+            () => this._setSelected(true));
0999a2
+        this.connect('key-focus-out',
0999a2
+            () => this._setSelected(false));
0999a2
+        this.connect('notify::hover',
0999a2
+            () => this._setSelected(this.hover));
0999a2
+
0999a2
+        this.connect('clicked', this._onClicked.bind(this));
0999a2
+    }
0999a2
+
0999a2
+    _onClicked() {
0999a2
+        this.emit('activate');
0999a2
+    }
0999a2
+
0999a2
+    _setSelected(selected) {
0999a2
+        if (selected) {
0999a2
+            this.add_style_pseudo_class('selected');
0999a2
+            this.grab_key_focus();
0999a2
+        } else {
0999a2
+            this.remove_style_pseudo_class('selected');
0999a2
+        }
0999a2
+    }
0999a2
+});
0999a2
+
0999a2
+var AuthList = GObject.registerClass({
0999a2
+    Signals: {
0999a2
+        'activate': { param_types: [GObject.TYPE_STRING] },
0999a2
+        'item-added': { param_types: [AuthListItem.$gtype] },
0999a2
+    },
0999a2
+}, class AuthList extends St.BoxLayout {
0999a2
+    _init() {
0999a2
+        super._init({
0999a2
+            vertical: true,
0999a2
+            style_class: 'login-dialog-auth-list-layout',
0999a2
+        });
0999a2
+
0999a2
+        this.label = new St.Label({ style_class: 'prompt-dialog-headline' });
0999a2
+        this.add_child(this.label);
0999a2
+
0999a2
+        this._scrollView = new St.ScrollView({
0999a2
+            style_class: 'login-dialog-user-list-view',
0999a2
+        });
0999a2
+        this._scrollView.set_policy(
0999a2
+            St.PolicyType.NEVER, St.PolicyType.AUTOMATIC);
0999a2
+        this.add_child(this._scrollView);
0999a2
+
0999a2
+        this._box = new St.BoxLayout({
0999a2
+            vertical: true,
0999a2
+            style_class: 'login-dialog-user-list',
0999a2
+            pseudo_class: 'expanded',
0999a2
+        });
0999a2
+
0999a2
+        this._scrollView.add_actor(this._box);
0999a2
+        this._items = {};
0999a2
+
0999a2
+        this.connect('key-focus-in', this._moveFocusToItems.bind(this));
0999a2
+    }
0999a2
+
0999a2
+    _moveFocusToItems() {
0999a2
+        let hasItems = Object.keys(this._items).length > 0;
0999a2
+
0999a2
+        if (!hasItems)
0999a2
+            return;
0999a2
+
0999a2
+        if (global.stage.get_key_focus() !== this)
0999a2
+            return;
0999a2
+
0999a2
+        let focusSet = this.navigate_focus(null, St.DirectionType.TAB_FORWARD, false);
0999a2
+        if (!focusSet) {
0999a2
+            Meta.later_add(Meta.LaterType.BEFORE_REDRAW, () => {
0999a2
+                this._moveFocusToItems();
0999a2
+                return false;
0999a2
+            });
0999a2
+        }
0999a2
+    }
0999a2
+
0999a2
+    _onItemActivated(activatedItem) {
0999a2
+        this.emit('activate', activatedItem.key);
0999a2
+    }
0999a2
+
0999a2
+    scrollToItem(item) {
0999a2
+        let box = item.get_allocation_box();
0999a2
+
0999a2
+        let adjustment = this._scrollView.get_vscroll_bar().get_adjustment();
0999a2
+
0999a2
+        let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
0999a2
+        adjustment.ease(value, {
0999a2
+            duration: SCROLL_ANIMATION_TIME,
0999a2
+            mode: Clutter.AnimationMode.EASE_OUT_QUAD,
0999a2
+        });
0999a2
+    }
0999a2
+
0999a2
+    jumpToItem(item) {
0999a2
+        let box = item.get_allocation_box();
0999a2
+
0999a2
+        let adjustment = this._scrollView.get_vscroll_bar().get_adjustment();
0999a2
+
0999a2
+        let value = (box.y1 + adjustment.step_increment / 2.0) - (adjustment.page_size / 2.0);
0999a2
+
0999a2
+        adjustment.set_value(value);
0999a2
+    }
0999a2
+
0999a2
+    getItem(key) {
0999a2
+        let item = this._items[key];
0999a2
+
0999a2
+        if (!item)
0999a2
+            return null;
0999a2
+
0999a2
+        return item;
0999a2
+    }
0999a2
+
0999a2
+    addItem(key, text) {
0999a2
+        this.removeItem(key);
0999a2
+
0999a2
+        let item = new AuthListItem(key, text);
0999a2
+        this._box.add(item, { x_fill: true });
0999a2
+
0999a2
+        this._items[key] = item;
0999a2
+
0999a2
+        item.connect('activate', this._onItemActivated.bind(this));
0999a2
+
0999a2
+        // Try to keep the focused item front-and-center
0999a2
+        item.connect('key-focus-in', () => this.scrollToItem(item));
0999a2
+
0999a2
+        this._moveFocusToItems();
0999a2
+
0999a2
+        this.emit('item-added', item);
0999a2
+    }
0999a2
+
0999a2
+    removeItem(key) {
0999a2
+        let item = this._items[key];
0999a2
+
0999a2
+        if (!item)
0999a2
+            return;
0999a2
+
0999a2
+        item.destroy();
0999a2
+        delete this._items[key];
0999a2
+    }
0999a2
+
0999a2
+    numItems() {
0999a2
+        return Object.keys(this._items).length;
0999a2
+    }
0999a2
+
0999a2
+    clear() {
0999a2
+        this.label.text = '';
0999a2
+        this._box.destroy_all_children();
0999a2
+        this._items = {};
0999a2
+    }
0999a2
+});
0999a2
diff --git a/js/js-resources.gresource.xml b/js/js-resources.gresource.xml
0999a2
index e65e0e9cf..b2c603a55 100644
0999a2
--- a/js/js-resources.gresource.xml
0999a2
+++ b/js/js-resources.gresource.xml
0999a2
@@ -1,6 +1,7 @@
0999a2
 
0999a2
 <gresources>
0999a2
   <gresource prefix="/org/gnome/shell">
0999a2
+    <file>gdm/authList.js</file>
0999a2
     <file>gdm/authPrompt.js</file>
0999a2
     <file>gdm/batch.js</file>
0999a2
     <file>gdm/loginDialog.js</file>
0999a2
-- 
0999a2
2.31.1
0999a2
0999a2
0999a2
From 79c8beffbdabc7d0948bb7335f67ada441e68b4e Mon Sep 17 00:00:00 2001
0999a2
From: Ray Strode <rstrode@redhat.com>
0999a2
Date: Mon, 17 Jul 2017 16:48:03 -0400
0999a2
Subject: [PATCH 2/2] gdmUtil: enable support for GDM's ChoiceList PAM
0999a2
 extension
0999a2
0999a2
This commit hooks up support for GDM's ChoiceList PAM extension.
0999a2
---
0999a2
 js/gdm/authPrompt.js  | 69 +++++++++++++++++++++++++++++++++++++++++++
0999a2
 js/gdm/loginDialog.js |  5 ++++
0999a2
 js/gdm/util.js        | 28 ++++++++++++++++++
0999a2
 js/ui/unlockDialog.js |  7 +++++
0999a2
 4 files changed, 109 insertions(+)
0999a2
0999a2
diff --git a/js/gdm/authPrompt.js b/js/gdm/authPrompt.js
0999a2
index 84c608b2f..b25897ea7 100644
0999a2
--- a/js/gdm/authPrompt.js
0999a2
+++ b/js/gdm/authPrompt.js
0999a2
@@ -4,6 +4,7 @@
0999a2
 const { Clutter, GLib, GObject, Meta, Pango, Shell, St } = imports.gi;
0999a2
 
0999a2
 const Animation = imports.ui.animation;
0999a2
+const AuthList = imports.gdm.authList;
0999a2
 const Batch = imports.gdm.batch;
0999a2
 const GdmUtil = imports.gdm.util;
0999a2
 const OVirt = imports.gdm.oVirt;
0999a2
@@ -75,6 +76,7 @@ var AuthPrompt = GObject.registerClass({
0999a2
 
0999a2
         this._userVerifier.connect('ask-question', this._onAskQuestion.bind(this));
0999a2
         this._userVerifier.connect('show-message', this._onShowMessage.bind(this));
0999a2
+        this._userVerifier.connect('show-choice-list', this._onShowChoiceList.bind(this));
0999a2
         this._userVerifier.connect('verification-failed', this._onVerificationFailed.bind(this));
0999a2
         this._userVerifier.connect('verification-complete', this._onVerificationComplete.bind(this));
0999a2
         this._userVerifier.connect('reset', this._onReset.bind(this));
0999a2
@@ -107,6 +109,27 @@ var AuthPrompt = GObject.registerClass({
0999a2
             capsLockPlaceholder, 'visible',
0999a2
             GObject.BindingFlags.SYNC_CREATE | GObject.BindingFlags.INVERT_BOOLEAN);
0999a2
 
0999a2
+        this._authList = new AuthList.AuthList();
0999a2
+        this._authList.set({
0999a2
+            x_expand: true,
0999a2
+            x_align: Clutter.ActorAlign.START,
0999a2
+            visible: false,
0999a2
+        });
0999a2
+        this._authList.connect('activate', (list, key) => {
0999a2
+            this._authList.reactive = false;
0999a2
+            this._authList.ease({
0999a2
+                opacity: 0,
0999a2
+                duration: MESSAGE_FADE_OUT_ANIMATION_TIME,
0999a2
+                mode: Clutter.AnimationMode.EASE_OUT_QUAD,
0999a2
+                onComplete: () => {
0999a2
+                    this._authList.clear();
0999a2
+                    this._authList.hide();
0999a2
+                    this._userVerifier.selectChoice(this._queryingService, key);
0999a2
+                },
0999a2
+            });
0999a2
+        });
0999a2
+        this.add_child(this._authList);
0999a2
+
0999a2
         this._message = new St.Label({
0999a2
             opacity: 0,
0999a2
             styleClass: 'login-dialog-message',
0999a2
@@ -303,6 +326,20 @@ var AuthPrompt = GObject.registerClass({
0999a2
         this.emit('prompted');
0999a2
     }
0999a2
 
0999a2
+    _onShowChoiceList(userVerifier, serviceName, promptMessage, choiceList) {
0999a2
+        if (this._queryingService)
0999a2
+            this.clear();
0999a2
+
0999a2
+        this._queryingService = serviceName;
0999a2
+
0999a2
+        if (this._preemptiveAnswer)
0999a2
+            this._preemptiveAnswer = null;
0999a2
+
0999a2
+        this.setChoiceList(promptMessage, choiceList);
0999a2
+        this.updateSensitivity(true);
0999a2
+        this.emit('prompted');
0999a2
+    }
0999a2
+
0999a2
     _onCredentialManagerAuthenticated() {
0999a2
         if (this.verificationStatus != AuthPromptStatus.VERIFICATION_SUCCEEDED)
0999a2
             this.reset();
0999a2
@@ -438,6 +475,8 @@ var AuthPrompt = GObject.registerClass({
0999a2
     clear() {
0999a2
         this._entry.text = '';
0999a2
         this.stopSpinning();
0999a2
+        this._authList.clear();
0999a2
+        this._authList.hide();
0999a2
     }
0999a2
 
0999a2
     setQuestion(question) {
0999a2
@@ -448,10 +487,39 @@ var AuthPrompt = GObject.registerClass({
0999a2
 
0999a2
         this._entry.hint_text = question;
0999a2
 
0999a2
+        this._authList.hide();
0999a2
         this._entry.show();
0999a2
         this._entry.grab_key_focus();
0999a2
     }
0999a2
 
0999a2
+    _fadeInChoiceList() {
0999a2
+        this._authList.set({
0999a2
+            opacity: 0,
0999a2
+            visible: true,
0999a2
+            reactive: false,
0999a2
+        });
0999a2
+        this._authList.ease({
0999a2
+            opacity: 255,
0999a2
+            duration: MESSAGE_FADE_OUT_ANIMATION_TIME,
0999a2
+            transition: Clutter.AnimationMode.EASE_OUT_QUAD,
0999a2
+            onComplete: () => (this._authList.reactive = true),
0999a2
+        });
0999a2
+    }
0999a2
+
0999a2
+    setChoiceList(promptMessage, choiceList) {
0999a2
+        this._authList.clear();
0999a2
+        this._authList.label.text = promptMessage;
0999a2
+        for (let key in choiceList) {
0999a2
+            let text = choiceList[key];
0999a2
+            this._authList.addItem(key, text);
0999a2
+        }
0999a2
+
0999a2
+        this._entry.hide();
0999a2
+        if (this._message.text == '')
0999a2
+            this._message.hide();
0999a2
+        this._fadeInChoiceList();
0999a2
+    }
0999a2
+
0999a2
     getAnswer() {
0999a2
         let text;
0999a2
 
0999a2
@@ -487,6 +555,7 @@ var AuthPrompt = GObject.registerClass({
0999a2
         else
0999a2
             this._message.remove_style_class_name('login-dialog-message-hint');
0999a2
 
0999a2
+        this._message.show();
0999a2
         if (message) {
0999a2
             this._message.remove_all_transitions();
0999a2
             this._message.text = message;
0999a2
diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js
0999a2
index d2a82b43d..41dd99646 100644
0999a2
--- a/js/gdm/loginDialog.js
0999a2
+++ b/js/gdm/loginDialog.js
0999a2
@@ -418,6 +418,11 @@ var LoginDialog = GObject.registerClass({
0999a2
         this._userManager = AccountsService.UserManager.get_default();
0999a2
         this._gdmClient = new Gdm.Client();
0999a2
 
0999a2
+        try {
0999a2
+            this._gdmClient.set_enabled_extensions([Gdm.UserVerifierChoiceList.interface_info().name]);
0999a2
+        } catch (e) {
0999a2
+        }
0999a2
+
0999a2
         this._settings = new Gio.Settings({ schema_id: GdmUtil.LOGIN_SCREEN_SCHEMA });
0999a2
 
0999a2
         this._settings.connect('changed::%s'.format(GdmUtil.BANNER_MESSAGE_KEY),
0999a2
diff --git a/js/gdm/util.js b/js/gdm/util.js
0999a2
index e62114cb1..3f327400f 100644
0999a2
--- a/js/gdm/util.js
0999a2
+++ b/js/gdm/util.js
0999a2
@@ -238,6 +238,10 @@ var ShellUserVerifier = class {
0999a2
             this._disconnectSignals();
0999a2
             this._userVerifier.run_dispose();
0999a2
             this._userVerifier = null;
0999a2
+            if (this._userVerifierChoiceList) {
0999a2
+                this._userVerifierChoiceList.run_dispose();
0999a2
+                this._userVerifierChoiceList = null;
0999a2
+            }
0999a2
         }
0999a2
     }
0999a2
 
0999a2
@@ -268,6 +272,10 @@ var ShellUserVerifier = class {
0999a2
         }
0999a2
     }
0999a2
 
0999a2
+    selectChoice(serviceName, key) {
0999a2
+        this._userVerifierChoiceList.call_select_choice(serviceName, key, this._cancellable, null);
0999a2
+    }
0999a2
+
0999a2
     answerQuery(serviceName, answer) {
0999a2
         if (!this.hasPendingMessages) {
0999a2
             this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
0999a2
@@ -456,6 +464,11 @@ var ShellUserVerifier = class {
0999a2
             return;
0999a2
         }
0999a2
 
0999a2
+        if (this._client.get_user_verifier_choice_list)
0999a2
+            this._userVerifierChoiceList = this._client.get_user_verifier_choice_list();
0999a2
+        else
0999a2
+            this._userVerifierChoiceList = null;
0999a2
+
0999a2
         this.reauthenticating = true;
0999a2
         this._connectSignals();
0999a2
         this._beginVerification();
0999a2
@@ -474,6 +487,11 @@ var ShellUserVerifier = class {
0999a2
             return;
0999a2
         }
0999a2
 
0999a2
+        if (this._client.get_user_verifier_choice_list)
0999a2
+            this._userVerifierChoiceList = this._client.get_user_verifier_choice_list();
0999a2
+        else
0999a2
+            this._userVerifierChoiceList = null;
0999a2
+
0999a2
         this._connectSignals();
0999a2
         this._beginVerification();
0999a2
         this._hold.release();
0999a2
@@ -499,6 +517,9 @@ var ShellUserVerifier = class {
0999a2
         this._signalIds.push(id);
0999a2
         id = this._userVerifier.connect('verification-complete', this._onVerificationComplete.bind(this));
0999a2
         this._signalIds.push(id);
0999a2
+
0999a2
+        if (this._userVerifierChoiceList)
0999a2
+            this._userVerifierChoiceList.connect('choice-query', this._onChoiceListQuery.bind(this));
0999a2
     }
0999a2
 
0999a2
     _disconnectSignals() {
0999a2
@@ -581,6 +602,13 @@ var ShellUserVerifier = class {
0999a2
             this._startService(FINGERPRINT_SERVICE_NAME);
0999a2
     }
0999a2
 
0999a2
+    _onChoiceListQuery(client, serviceName, promptMessage, list) {
0999a2
+        if (!this.serviceIsForeground(serviceName))
0999a2
+            return;
0999a2
+
0999a2
+        this.emit('show-choice-list', serviceName, promptMessage, list.deep_unpack());
0999a2
+    }
0999a2
+
0999a2
     _onInfo(client, serviceName, info) {
0999a2
         if (this.serviceIsForeground(serviceName)) {
0999a2
             this._queueMessage(serviceName, info, MessageType.INFO);
0999a2
diff --git a/js/ui/unlockDialog.js b/js/ui/unlockDialog.js
0999a2
index 8ddae8b03..33fbbdd8e 100644
0999a2
--- a/js/ui/unlockDialog.js
0999a2
+++ b/js/ui/unlockDialog.js
0999a2
@@ -484,6 +484,13 @@ var UnlockDialog = GObject.registerClass({
0999a2
 
0999a2
         this._gdmClient = new Gdm.Client();
0999a2
 
0999a2
+        try {
0999a2
+            this._gdmClient.set_enabled_extensions([
0999a2
+                Gdm.UserVerifierChoiceList.interface_info().name,
0999a2
+            ]);
0999a2
+        } catch (e) {
0999a2
+        }
0999a2
+
0999a2
         this._adjustment = new St.Adjustment({
0999a2
             actor: this,
0999a2
             lower: 0,
0999a2
-- 
0999a2
2.31.1
0999a2