1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# root password spoke class
#
# Copyright (C) 2012 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
# Red Hat Author(s): Jesse Keating <jkeating@redhat.com>
#
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
N_ = lambda x: x
from gi.repository import Gtk
from pyanaconda.users import cryptPassword, validatePassword
from pwquality import PWQError
import string
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.gui.categories.user_settings import UserSettingsCategory
from pyanaconda.ui.common import FirstbootSpokeMixIn
#from _isys import isCapsLockEnabled
__all__ = ["PasswordSpoke"]
class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke):
builderObjects = ["passwordWindow"]
mainWidgetName = "passwordWindow"
uiFile = "spokes/password.glade"
category = UserSettingsCategory
icon = "dialog-password-symbolic"
title = N_("_ROOT PASSWORD")
def __init__(self, *args):
NormalSpoke.__init__(self, *args)
self._password = None
self._error = False
self._oldweak = None
def initialize(self):
NormalSpoke.initialize(self)
# place holders for the text boxes
self.pw = self.builder.get_object("pw")
self.confirm = self.builder.get_object("confirm")
def refresh(self):
# self.setCapsLockLabel()
self.pw.grab_focus()
# Caps lock detection isn't hooked up right now
# def setCapsLockLabel(self):
# if isCapsLockEnabled():
# self.capslock.set_text("<b>" + _("Caps Lock is on.") + "</b>")
# self.capslock.set_use_markup(True)
# else:
# self.capslock..set_text("")
@property
def status(self):
if self._error:
return _("Error setting root password")
if self.data.rootpw.password:
return _("Root password is set")
elif self.data.rootpw.lock:
return _("Root account is disabled")
else:
return _("Root password is not set")
@property
def mandatory(self):
return not self.data.user.userList
def apply(self):
self.data.rootpw.password = cryptPassword(self._password)
self.data.rootpw.isCrypted = True
self.data.rootpw.lock = False
@property
def completed(self):
return bool(self.data.rootpw.password or self.data.rootpw.lock)
def _validatePassword(self):
# Do various steps to validate the password
# sets self._error to an error string
# Return True if valid, False otherwise
self._error = False
pw = self.pw.get_text()
confirm = self.confirm.get_text()
if not pw and not confirm:
self._error = _("You must provide and confirm a password.")
return False
try:
self._error = validatePassword(pw, confirm)
except PWQError as (e, msg):
if pw == self._oldweak:
# We got a second attempt with the same weak password
pass
else:
self._error = _("You have provided a weak password: %s. "
" Press Done again to use anyway.") % msg
self._oldweak = pw
return False
if self._error:
return False
# if no errors, clear the info for next time we go into the spoke
self._password = pw
self.clear_info()
self._error = False
return True
def on_back_clicked(self, button):
if self._validatePassword():
self.clear_info()
NormalSpoke.on_back_clicked(self, button)
else:
self.clear_info()
self.set_warning(self._error)
self.pw.grab_focus()
self.window.show_all()
|