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
@@ -71,167 +71,171 @@ static char *crypt_make_salt() {
71 static unsigned long x; 71 static unsigned long x;
72 static char result[3]; 72 static char result[3];
73 73
74 ::time(&now); 74 ::time(&now);
75 x += now + getpid() + clock(); 75 x += now + getpid() + clock();
76 result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077); 76 result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077);
77 result[1] = i64c(((x >> 12) ^ x) & 077); 77 result[1] = i64c(((x >> 12) ^ x) & 077);
78 result[2] = '\0'; 78 result[2] = '\0';
79 return result; 79 return result;
80} 80}
81 81
82/* 82/*
83 * Modal dialog to force root password. It is quite hard as it only leave 83 * Modal dialog to force root password. It is quite hard as it only leave
84 * when a password is set. 84 * when a password is set.
85 * Also it prevalidates the password... 85 * Also it prevalidates the password...
86 */ 86 */
87PasswordDialogImpl::PasswordDialogImpl( QWidget* parent ) 87PasswordDialogImpl::PasswordDialogImpl( QWidget* parent )
88 : PasswordDialog( parent, 0, true ), m_isSet( PasswordDialogImpl::needDialog() ) { 88 : PasswordDialog( parent, 0, true ), m_isSet( PasswordDialogImpl::needDialog() ) {
89} 89}
90 90
91PasswordDialogImpl::~PasswordDialogImpl() { 91PasswordDialogImpl::~PasswordDialogImpl() {
92 /* qt does the stuff for us */ 92 /* qt does the stuff for us */
93} 93}
94 94
95void PasswordDialogImpl::done(int res) { 95void PasswordDialogImpl::done(int res) {
96 m_isSet = true; 96 m_isSet = true;
97 97
98 /* 98 /*
99 * The user hit 'Ok' see if we can safe the file 99 * The user hit 'Ok' see if we can safe the file
100 * if not an error will be raised and m_isSet altered. 100 * if not an error will be raised and m_isSet altered.
101 * On cancel we will see if it is now ok... 101 * On cancel we will see if it is now ok...
102 */ 102 */
103 if ( res == Accepted ) 103 if ( res == Accepted )
104 writePassword(); 104 writePassword();
105 else if(PasswordDialogImpl::needDialog() ) { 105 else if(PasswordDialogImpl::needDialog() ) {
106 switch( QMessageBox::warning(this,tr("Trying to leave without password set") , 106 switch( QMessageBox::warning(this,tr("Trying to leave without password set") ,
107 tr("<qt>No password was set. This could lead to you not beeing" 107 tr("<qt>No password was set. This could lead to you not beeing"
108 "able to remotely connect to your machine." 108 "able to remotely connect to your machine."
109 "Do you want to continue not setting a password?</qt>" ), 109 "Do you want to continue not setting a password?</qt>" ),
110 QMessageBox::Ok, QMessageBox::Cancel ) ) { 110 QMessageBox::Ok, QMessageBox::Cancel ) ) {
111 case QMessageBox::Cancel: 111 case QMessageBox::Cancel:
112 m_isSet = false; 112 m_isSet = false;
113 break; 113 break;
114 case QMessageBox::Ok: 114 case QMessageBox::Ok:
115 default: 115 default:
116 break; 116 break;
117 } 117 }
118 118
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 ) {
216 QString str = QString::fromLatin1(pwd->pw_passwd ); 220 QString str = QString::fromLatin1(pwd->pw_passwd );
217 221
218 /* 222 /*
219 * If str is really empty it is passwordless anyway... or '*' is a hint to set one 223 * If str is really empty it is passwordless anyway... or '*' is a hint to set one
220 * on OE/Familiar 224 * on OE/Familiar
221 * else it is shadow based 225 * else it is shadow based
222 */ 226 */
223 if(str.isEmpty() || str == '*' ) 227 if(str.isEmpty() || str == '*' )
224 need = true; 228 need = true;
225 else if ( str == 'x' ) 229 else if ( str == 'x' )
226#ifdef OPIE_LOGIN_SHADOW_PW 230#ifdef OPIE_LOGIN_SHADOW_PW
227 need = QString::fromLatin1( ::getspnam( pwd->pw_name )->sp_pwdp ).isEmpty(); 231 need = QString::fromLatin1( ::getspnam( pwd->pw_name )->sp_pwdp ).isEmpty();
228#else 232#else
229 ; 233 ;
230#endif 234#endif
231 break; 235 break;
232 } 236 }
233 } 237 }
234 ::endpwent(); 238 ::endpwent();
235 239
236 return need; 240 return need;
237} 241}