~ubuntu-branches/ubuntu/wily/mugshot/wily-proposed

« back to all changes in this revision

Viewing changes to mugshot_lib/SudoDialog.py

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-04-05 12:41:01 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140405124101-wjxrx75e2jbnxqkt
Tags: 0.2.3-1
* New upstream release. LP: #1302906
  - fix: mugshot is unable to store profile picture (LP: #1298665)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import pexpect
24
24
 
25
25
 
 
26
def check_sudo():
 
27
    """Return True if user has permission to use sudo."""
 
28
    child = pexpect.spawn('sudo -v', env={"LANG": "C"})
 
29
    child.timeout = 1
 
30
    # Check for failure message.
 
31
    try:
 
32
        child.expect(["Sorry", pexpect.EOF])
 
33
        child.close()
 
34
        return False
 
35
    except:
 
36
        child.close()
 
37
        return True
 
38
 
 
39
 
26
40
class SudoDialog(Gtk.MessageDialog):
27
41
    '''
28
42
    Creates a new SudoDialog. This is a replacement for using gksudo which
52
66
 
53
67
        # initialize the dialog
54
68
        super(SudoDialog, self).__init__(transient_for=parent,
55
 
                                        modal=True,
56
 
                                        destroy_with_parent=True,
57
 
                                        message_type=message_type,
58
 
                                        buttons=buttons,
59
 
                                        text='')
 
69
                                         modal=True,
 
70
                                         destroy_with_parent=True,
 
71
                                         message_type=message_type,
 
72
                                         buttons=buttons,
 
73
                                         text='')
60
74
        self.set_dialog_icon(icon)
61
75
        self.connect("show", self.on_show)
62
76
 
94
108
 
95
109
        # Outer password box for incorrect password label and inner widgets.
96
110
        password_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
97
 
                                    spacing=12)
 
111
                                 spacing=12)
98
112
        password_outer.set_orientation(Gtk.Orientation.VERTICAL)
99
113
        # Password error label, only displayed when unsuccessful.
100
114
        self.password_info = Gtk.Label(label="")
103
117
 
104
118
        # Inner password box for Password: label and password entry.
105
119
        password_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
106
 
                                    spacing=12)
 
120
                               spacing=12)
107
121
        password_label = Gtk.Label(label=_("Password:"))
108
122
        self.password_entry = Gtk.Entry()
109
123
        self.password_entry.set_visibility(False)
110
124
        self.password_entry.set_activates_default(True)
111
125
        self.password_entry.connect("changed", self.on_password_changed,
112
 
                                                                    ok_button)
 
126
                                    ok_button)
113
127
 
114
128
        # Pack all the widgets.
115
129
        password_box.pack_start(password_label, False, False, 0)
179
193
        then emit the response signal with REJECT.
180
194
        '''
181
195
        top, bottom, left, right = self.password_alignment.get_padding()
182
 
        if self.attempt_login():
 
196
        # Password cannot be validated without sudo
 
197
        if (not check_sudo()) or self.attempt_login():
183
198
            self.password_valid = True
184
199
            # Adjust the dialog for attactiveness.
185
200
            self.password_alignment.set_padding(12, bottom, left, right)