summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/passworddialogimpl.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/opie-login/passworddialogimpl.cpp b/core/opie-login/passworddialogimpl.cpp
index 951c4e1..852708e 100644
--- a/core/opie-login/passworddialogimpl.cpp
+++ b/core/opie-login/passworddialogimpl.cpp
@@ -118,114 +118,115 @@ void PasswordDialogImpl::done(int res) {
118} 118}
119 119
120/* 120/*
121 * Lets see if we can write either shadow 121 * Lets see if we can write either shadow
122 * 122 *
123 */ 123 */
124/** 124/**
125 * CRYPT the password and then tries to write it either to the shadow password 125 * CRYPT the password and then tries to write it either to the shadow password
126 * or to the plain /etc/passwd 126 * or to the plain /etc/passwd
127 */ 127 */
128void PasswordDialogImpl::writePassword() { 128void PasswordDialogImpl::writePassword() {
129 /* 129 /*
130 * Check if both texts are the same 130 * Check if both texts are the same
131 */ 131 */
132 if ( m_pass->text() != m_confirm->text() ) 132 if ( m_pass->text() != m_confirm->text() )
133 return error( tr("Passwords don't match"), 133 return error( tr("Passwords don't match"),
134 tr("<qt>The two passwords don't match. Please try again.</qt>") ); 134 tr("<qt>The two passwords don't match. Please try again.</qt>") );
135 135
136 136
137 /* 137 /*
138 * Now crypt the password so we can write it later 138 * Now crypt the password so we can write it later
139 */ 139 */
140 char* password = ::crypt( m_pass->text().latin1(), crypt_make_salt() ); 140 char* password = ::crypt( m_pass->text().latin1(), crypt_make_salt() );
141 141
142 if ( !password ) 142 if ( !password )
143 return error( tr("Password not legal" ), 143 return error( tr("Password not legal" ),
144 tr("<qt>The entered password is not a valid password." 144 tr("<qt>The entered password is not a valid password."
145 "Please try entering a valid password.</qt>" ) ); 145 "Please try entering a valid password.</qt>" ) );
146 146
147 /* rewind and rewrite the password file */ 147 /* rewind and rewrite the password file */
148 ::setpwent(); 148 ::setpwent();
149 149
150 FILE* file = ::fopen( "/etc/passwd.new", "w" ); 150 FILE* file = ::fopen( "/etc/passwd.new", "w" );
151 struct passwd* pass; 151 struct passwd* pass;
152 while ( (pass = ::getpwent()) != 0l ) { 152 while ( (pass = ::getpwent()) != 0l ) {
153 /* no shadow password support */ 153 /* no shadow password support */
154 if ( pass->pw_uid == 0 ) 154 if ( pass->pw_uid == 0 )
155 pass->pw_passwd = password; 155 pass->pw_passwd = password;
156 156
157 ::putpwent( pass, file ); 157 ::putpwent( pass, file );
158 } 158 }
159 159
160 ::fclose( file ); 160 ::fclose( file );
161 ::endpwent(); 161 ::endpwent();
162 ::rename("/etc/passwd.new","/etc/passwd" ); 162 ::rename("/etc/passwd.new","/etc/passwd" );
163 163
164 /* should be done now */ 164 /* should be done now */
165#ifdef OPIE_LOGIN_SHADOW_PW 165#ifdef OPIE_LOGIN_SHADOW_PW
166 #error "Can't write Shadow Passwords fixme" 166 #error "Can't write Shadow Passwords fixme"
167#endif 167#endif
168} 168}
169 169
170/** 170/**
171 * Raise an error. Delete input and set the focus after showing 171 * Raise an error. Delete input and set the focus after showing
172 * the error to the user 172 * the error to the user
173 */ 173 */
174void PasswordDialogImpl::error( const QString& caption, const QString& text ) { 174void PasswordDialogImpl::error( const QString& caption, const QString& text ) {
175 m_isSet = false; 175 m_isSet = false;
176 QMessageBox::critical(this,caption, text, 176 QMessageBox::critical(this,caption, text,
177 QMessageBox::Ok, QMessageBox::NoButton ); 177 QMessageBox::Ok, QMessageBox::NoButton );
178 178
179 m_pass->setText(""); 179 m_pass->setText("");
180 m_pass->setFocus(); 180 m_pass->setFocus();
181 181
182 m_confirm->setText(""); 182 m_confirm->setText("");
183} 183}
184 184
185void PasswordDialogImpl::slotToggleEcho( bool b ) { 185void PasswordDialogImpl::slotToggleEcho( bool b ) {
186 m_pass-> setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password ); 186 m_pass-> setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password );
187 m_confirm->setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password ); 187 m_confirm->setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password );
188} 188}
189 189
190///////////////////////// 190/////////////////////////
191/// static functions 191/// static functions
192/// 192///
193 193
194/** 194/**
195 * Ask whether or not we need to show the dialog. It returns true if 195 * Ask whether or not we need to show the dialog. It returns true if
196 * no root password is set so that the user will be able to set one. 196 * no root password is set so that the user will be able to set one.
197 */ 197 */
198bool PasswordDialogImpl::needDialog() { 198bool PasswordDialogImpl::needDialog() {
199 /* 199 /*
200 * This can cope with no password and shadow passwords 200 * This can cope with no password and shadow passwords
201 * Let us go through the user database until we find 'root' and then 201 * Let us go through the user database until we find 'root' and then
202 * see if it is 'shadow' and see if shadow is empty or see if the password is empty 202 * see if it is 'shadow' and see if shadow is empty or see if the password is empty
203 */ 203 */
204 bool need = false; 204 bool need = false;
205 struct passwd *pwd; 205 struct passwd *pwd;
206 ::setpwent(); 206 ::setpwent();
207 207
208 while((pwd = ::getpwent() ) ) { 208 while((pwd = ::getpwent() ) ) {
209 /* found root */ 209 /* found root */
210 if( pwd->pw_uid == 0 ) { 210 if( pwd->pw_uid == 0 ) {
211 QString str = QString::fromLatin1(pwd->pw_passwd ); 211 QString str = QString::fromLatin1(pwd->pw_passwd );
212 212
213 /* 213 /*
214 * If str is really empty it is passwordless anyway... 214 * If str is really empty it is passwordless anyway... or '*' is a hint to set one
215 * on OE/Familiar
215 * else it is shadow based 216 * else it is shadow based
216 */ 217 */
217 if(str.isEmpty() ) 218 if(str.isEmpty() || str == '*' )
218 need = true; 219 need = true;
219 else if ( str == '*' || str == 'x' ) 220 else if ( str == 'x' )
220#ifdef OPIE_LOGIN_SHADOW_PW 221#ifdef OPIE_LOGIN_SHADOW_PW
221 need = QString::fromLatin1( ::getspnam( pwd->pw_name )->sp_pwdp ).isEmpty(); 222 need = QString::fromLatin1( ::getspnam( pwd->pw_name )->sp_pwdp ).isEmpty();
222#else 223#else
223 ; 224 ;
224#endif 225#endif
225 break; 226 break;
226 } 227 }
227 } 228 }
228 ::endpwent(); 229 ::endpwent();
229 230
230 return need; 231 return need;
231} 232}