summaryrefslogtreecommitdiff
path: root/core/opie-login
authorerik <erik>2007-01-23 21:39:59 (UTC)
committer erik <erik>2007-01-23 21:39:59 (UTC)
commit8644340455a433f4d6e3b31b329479f1e7983f78 (patch) (unidiff)
tree8429c11d6634f4d8a7ad83fd59aaf03989d027a3 /core/opie-login
parentadcf6075db477909dd8170a74862a6ef91a5127f (diff)
downloadopie-8644340455a433f4d6e3b31b329479f1e7983f78.zip
opie-8644340455a433f4d6e3b31b329479f1e7983f78.tar.gz
opie-8644340455a433f4d6e3b31b329479f1e7983f78.tar.bz2
A couple more return values that need to be checked.
Diffstat (limited to 'core/opie-login') (more/less context) (show whitespace changes)
-rw-r--r--core/opie-login/passworddialogimpl.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/core/opie-login/passworddialogimpl.cpp b/core/opie-login/passworddialogimpl.cpp
index d9132e2..3c1b474 100644
--- a/core/opie-login/passworddialogimpl.cpp
+++ b/core/opie-login/passworddialogimpl.cpp
@@ -119,97 +119,101 @@ void PasswordDialogImpl::done(int res) {
119 } 119 }
120 120
121 if(m_isSet) 121 if(m_isSet)
122 PasswordDialog::done( res ); 122 PasswordDialog::done( res );
123} 123}
124 124
125/* 125/*
126 * Lets see if we can write either shadow 126 * Lets see if we can write either shadow
127 * 127 *
128 */ 128 */
129/** 129/**
130 * CRYPT the password and then tries to write it either to the shadow password 130 * CRYPT the password and then tries to write it either to the shadow password
131 * or to the plain /etc/passwd 131 * or to the plain /etc/passwd
132 */ 132 */
133void PasswordDialogImpl::writePassword() { 133void PasswordDialogImpl::writePassword() {
134 /* 134 /*
135 * Check if both texts are the same 135 * Check if both texts are the same
136 */ 136 */
137 if ( m_pass->text() != m_confirm->text() ) 137 if ( m_pass->text() != m_confirm->text() )
138 return error( tr("Passwords don't match"), 138 return error( tr("Passwords don't match"),
139 tr("<qt>The two passwords don't match. Please try again.</qt>") ); 139 tr("<qt>The two passwords don't match. Please try again.</qt>") );
140 140
141 141
142 /* 142 /*
143 * Now crypt the password so we can write it later 143 * Now crypt the password so we can write it later
144 */ 144 */
145 char* password = ::crypt( m_pass->text().latin1(), crypt_make_salt() ); 145 char* password = ::crypt( m_pass->text().latin1(), crypt_make_salt() );
146 146
147 if ( !password ) 147 if ( !password )
148 return error( tr("Password not legal" ), 148 return error( tr("Password not legal" ),
149 tr("<qt>The entered password is not a valid password." 149 tr("<qt>The entered password is not a valid password."
150 "Please try entering a valid password.</qt>" ) ); 150 "Please try entering a valid password.</qt>" ) );
151 151
152 /* rewind and rewrite the password file */ 152 /* rewind and rewrite the password file */
153 ::setpwent(); 153 ::setpwent();
154 154
155 FILE* file = ::fopen( "/etc/passwd.new", "w" ); 155 FILE* file = ::fopen( "/etc/passwd.new", "w" );
156 struct passwd* pass; 156 struct passwd* pass;
157 while ( (pass = ::getpwent()) != 0l ) { 157 while ( (pass = ::getpwent()) != 0l ) {
158 /* no shadow password support */ 158 /* no shadow password support */
159 if ( pass->pw_uid == 0 ) 159 if ( pass->pw_uid == 0 )
160 pass->pw_passwd = password; 160 pass->pw_passwd = password;
161 161
162 ::putpwent( pass, file ); 162 ::putpwent( pass, file );
163 } 163 }
164 164
165 ::fclose( file ); 165 ::fclose( file );
166 ::endpwent(); 166 ::endpwent();
167 ::rename("/etc/passwd.new","/etc/passwd" ); 167 if (::rename("/etc/passwd.new","/etc/passwd" ) == -1)
168 return error( tr("Rename /etc/passwd failed"),
169 tr("<qt>Renaming /etc/passwd.new to /etc/passwd failed."
170 "Please check your /etc/passed file, your /etc directory "
171 "or your filesystem.</qt>") );
168 172
169 /* should be done now */ 173 /* should be done now */
170#ifdef OPIE_LOGIN_SHADOW_PW 174#ifdef OPIE_LOGIN_SHADOW_PW
171 #error "Can't write Shadow Passwords fixme" 175 #error "Can't write Shadow Passwords fixme"
172#endif 176#endif
173} 177}
174 178
175/** 179/**
176 * Raise an error. Delete input and set the focus after showing 180 * Raise an error. Delete input and set the focus after showing
177 * the error to the user 181 * the error to the user
178 */ 182 */
179void PasswordDialogImpl::error( const QString& caption, const QString& text ) { 183void PasswordDialogImpl::error( const QString& caption, const QString& text ) {
180 m_isSet = false; 184 m_isSet = false;
181 QMessageBox::critical(this,caption, text, 185 QMessageBox::critical(this,caption, text,
182 QMessageBox::Ok, QMessageBox::NoButton ); 186 QMessageBox::Ok, QMessageBox::NoButton );
183 187
184 m_pass->setText(""); 188 m_pass->setText("");
185 m_pass->setFocus(); 189 m_pass->setFocus();
186 190
187 m_confirm->setText(""); 191 m_confirm->setText("");
188} 192}
189 193
190void PasswordDialogImpl::slotToggleEcho( bool b ) { 194void PasswordDialogImpl::slotToggleEcho( bool b ) {
191 m_pass-> setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password ); 195 m_pass-> setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password );
192 m_confirm->setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password ); 196 m_confirm->setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password );
193} 197}
194 198
195///////////////////////// 199/////////////////////////
196/// static functions 200/// static functions
197/// 201///
198 202
199/** 203/**
200 * Ask whether or not we need to show the dialog. It returns true if 204 * Ask whether or not we need to show the dialog. It returns true if
201 * no root password is set so that the user will be able to set one. 205 * no root password is set so that the user will be able to set one.
202 */ 206 */
203bool PasswordDialogImpl::needDialog() { 207bool PasswordDialogImpl::needDialog() {
204 /* 208 /*
205 * This can cope with no password and shadow passwords 209 * This can cope with no password and shadow passwords
206 * Let us go through the user database until we find 'root' and then 210 * Let us go through the user database until we find 'root' and then
207 * see if it is 'shadow' and see if shadow is empty or see if the password is empty 211 * see if it is 'shadow' and see if shadow is empty or see if the password is empty
208 */ 212 */
209 bool need = false; 213 bool need = false;
210 struct passwd *pwd; 214 struct passwd *pwd;
211 ::setpwent(); 215 ::setpwent();
212 216
213 while((pwd = ::getpwent() ) ) { 217 while((pwd = ::getpwent() ) ) {
214 /* found root */ 218 /* found root */
215 if( pwd->pw_uid == 0 ) { 219 if( pwd->pw_uid == 0 ) {