summaryrefslogtreecommitdiff
authorzecke <zecke>2004-07-09 21:36:37 (UTC)
committer zecke <zecke>2004-07-09 21:36:37 (UTC)
commit944adb8bf2741a16cf627d19e08f51c08920ad89 (patch) (unidiff)
tree5f9edc9784e0268a00fe68ec74d7151900c5183a
parentc5d3262afd775bce81b99c5dc06e74c4686cee2a (diff)
downloadopie-944adb8bf2741a16cf627d19e08f51c08920ad89.zip
opie-944adb8bf2741a16cf627d19e08f51c08920ad89.tar.gz
opie-944adb8bf2741a16cf627d19e08f51c08920ad89.tar.bz2
Add setting a root password if none is set to opie-login
If you directly start Opie-Taskbar or use AutoLogin you will not be presented by a set root password gui
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/.cvsignore2
-rw-r--r--core/opie-login/loginwindowimpl.cpp14
-rw-r--r--core/opie-login/loginwindowimpl.h5
-rw-r--r--core/opie-login/opie-login.pro8
-rw-r--r--core/opie-login/passworddialog.ui225
-rw-r--r--core/opie-login/passworddialogimpl.cpp232
-rw-r--r--core/opie-login/passworddialogimpl.h65
7 files changed, 545 insertions, 6 deletions
diff --git a/core/opie-login/.cvsignore b/core/opie-login/.cvsignore
index 0c3cc62..b80bdc4 100644
--- a/core/opie-login/.cvsignore
+++ b/core/opie-login/.cvsignore
@@ -1,7 +1,9 @@
1*.moc 1*.moc
2Makefile* 2Makefile*
3loginwindow.cpp 3loginwindow.cpp
4loginwindow.h 4loginwindow.h
5passworddialog.h
6passworddialog.cpp
5moc_* 7moc_*
6.moc 8.moc
7.obj 9.obj
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp
index 32f98f3..73c2cbe 100644
--- a/core/opie-login/loginwindowimpl.cpp
+++ b/core/opie-login/loginwindowimpl.cpp
@@ -42,16 +42,17 @@
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43#include <qpe/config.h> 43#include <qpe/config.h>
44 44
45#include <opie2/odevice.h> 45#include <opie2/odevice.h>
46 46
47#include <stdio.h> 47#include <stdio.h>
48#include <stdlib.h> 48#include <stdlib.h>
49 49
50#include "passworddialogimpl.h"
50#include "loginwindowimpl.h" 51#include "loginwindowimpl.h"
51#include "loginapplication.h" 52#include "loginapplication.h"
52#include "inputmethods.h" 53#include "inputmethods.h"
53 54
54using namespace Opie::Core; 55using namespace Opie::Core;
55 56
56 57
57LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) 58LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
@@ -85,26 +86,31 @@ LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_C
85 86
86 if ( !bgpix. isNull ( )) { 87 if ( !bgpix. isNull ( )) {
87 setBackgroundPixmap ( bgpix ); 88 setBackgroundPixmap ( bgpix );
88 m_caption-> setBackgroundPixmap ( bgpix); 89 m_caption-> setBackgroundPixmap ( bgpix);
89 TextLabel1-> setBackgroundPixmap ( bgpix); 90 TextLabel1-> setBackgroundPixmap ( bgpix);
90 TextLabel2-> setBackgroundPixmap ( bgpix); 91 TextLabel2-> setBackgroundPixmap ( bgpix);
91 } 92 }
92 93
93 m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); 94 //m_caption-> setText ( tr("<center>Welcome to OPIE %1</center><center>& %2 %3</center>"). arg(QPE_VERSION). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( )));
94 95
95 Config cfg ( "opie-login" ); 96 Config cfg ( "opie-login" );
96 cfg. setGroup ( "General" ); 97 cfg. setGroup ( "General" );
97 QString last = cfg. readEntry ( "LastLogin" ); 98 QString last = cfg. readEntry ( "LastLogin" );
98 99
99 if ( !last. isEmpty ( )) 100 if ( !last. isEmpty ( ))
100 m_user-> setEditText ( last ); 101 m_user-> setEditText ( last );
101 102
102 calcMaxWindowRect ( ); 103 calcMaxWindowRect ( );
104
105 if ( PasswordDialogImpl::needDialog() )
106 QTimer::singleShot(10, this, SLOT(showPasswordDialog()) );
107
108
103} 109}
104 110
105LoginWindowImpl::~LoginWindowImpl ( ) 111LoginWindowImpl::~LoginWindowImpl ( )
106{ 112{
107} 113}
108 114
109 115
110void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data ) 116void LoginWindowImpl::receive ( const QCString &msg, const QByteArray &data )
@@ -243,8 +249,14 @@ void LoginWindowImpl::login ( )
243 new WaitLogo ( ); 249 new WaitLogo ( );
244 // WaitLogo::showEvent() calls qApp-> quit() 250 // WaitLogo::showEvent() calls qApp-> quit()
245 } 251 }
246 else { 252 else {
247 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); 253 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
248 m_password-> clear ( ); 254 m_password-> clear ( );
249 } 255 }
250} 256}
257
258void LoginWindowImpl::showPasswordDialog() {
259 PasswordDialogImpl dia( this );
260 dia.showMaximized();
261 dia.exec();
262}
diff --git a/core/opie-login/loginwindowimpl.h b/core/opie-login/loginwindowimpl.h
index df8dbbb..1de212c 100644
--- a/core/opie-login/loginwindowimpl.h
+++ b/core/opie-login/loginwindowimpl.h
@@ -29,31 +29,32 @@
29#define __OPIE_LOGINWINDOW_IMPL_H__ 29#define __OPIE_LOGINWINDOW_IMPL_H__
30 30
31#include "loginwindow.h" 31#include "loginwindow.h"
32 32
33class InputMethods; 33class InputMethods;
34 34
35class LoginWindowImpl : public LoginWindow { 35class LoginWindowImpl : public LoginWindow {
36 Q_OBJECT 36 Q_OBJECT
37 37
38public: 38public:
39 LoginWindowImpl ( ); 39 LoginWindowImpl ( );
40 virtual ~LoginWindowImpl ( ); 40 virtual ~LoginWindowImpl ( );
41 41
42protected slots: 42protected slots:
43 void restart ( ); 43 void restart ( );
44 void quit ( ); 44 void quit ( );
45 void showIM ( ); 45 void showIM ( );
46 void suspend ( ); 46 void suspend ( );
47 void backlight ( ); 47 void backlight ( );
48 void login ( ); 48 void login ( );
49 void toggleEchoMode ( bool ); 49 void toggleEchoMode ( bool );
50 void calcMaxWindowRect ( ); 50 void calcMaxWindowRect ( );
51 void receive ( const QCString &, const QByteArray & ); 51 void receive ( const QCString &, const QByteArray & );
52 void showPasswordDialog();
52 53
53protected: 54protected:
54 virtual void keyPressEvent ( QKeyEvent *e ); 55 virtual void keyPressEvent ( QKeyEvent *e );
55 56
56 QStringList getAllUsers ( ); 57 QStringList getAllUsers ( );
57 bool changeIdentity ( const char *user ); 58 bool changeIdentity ( const char *user );
58 59
59private: 60private:
diff --git a/core/opie-login/opie-login.pro b/core/opie-login/opie-login.pro
index 63d4481..175d0b6 100644
--- a/core/opie-login/opie-login.pro
+++ b/core/opie-login/opie-login.pro
@@ -1,23 +1,25 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on usepam 2CONFIG = qt warn_on usepam
3 3
4HEADERS = loginwindowimpl.h \ 4HEADERS = loginwindowimpl.h \
5 loginapplication.h \ 5 loginapplication.h \
6 passworddialogimpl.h \
6 ../launcher/inputmethods.h \ 7 ../launcher/inputmethods.h \
7 ../apps/calibrate/calibrate.h 8 ../apps/calibrate/calibrate.h
8 9
9SOURCES = loginwindowimpl.cpp \ 10SOURCES = loginwindowimpl.cpp \
10 loginapplication.cpp \ 11 loginapplication.cpp \
12 passworddialogimpl.cpp \
11 ../launcher/inputmethods.cpp \ 13 ../launcher/inputmethods.cpp \
12 ../apps/calibrate/calibrate.cpp \ 14 ../apps/calibrate/calibrate.cpp \
13 main.cpp 15 main.cpp
14 16
15INTERFACES = loginwindow.ui 17INTERFACES = loginwindow.ui passworddialog.ui
16 18
17INCLUDEPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate 19INCLUDEPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate
18DEPENDPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate 20DEPENDPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate
19 21
20LIBS += -lqpe -lopiecore2 22LIBS += -lqpe -lopiecore2
21 23
22usepam:LIBS += -lpam 24usepam:LIBS += -lpam
23usepam:DEFINES += USEPAM 25usepam:DEFINES += USEPAM
diff --git a/core/opie-login/passworddialog.ui b/core/opie-login/passworddialog.ui
new file mode 100644
index 0000000..f2b2c88
--- a/dev/null
+++ b/core/opie-login/passworddialog.ui
@@ -0,0 +1,225 @@
1<!DOCTYPE UI><UI>
2<class>PasswordDialog</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>PasswordDialog</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>625</width>
15 <height>277</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Set Password</string>
21 <comment>Caption of the password dialog</comment>
22 </property>
23 <property>
24 <name>layoutMargin</name>
25 </property>
26 <property>
27 <name>layoutSpacing</name>
28 </property>
29 <grid>
30 <property stdset="1">
31 <name>margin</name>
32 <number>4</number>
33 </property>
34 <property stdset="1">
35 <name>spacing</name>
36 <number>4</number>
37 </property>
38 <widget row="0" column="0" >
39 <class>QLabel</class>
40 <property stdset="1">
41 <name>name</name>
42 <cstring>m_header</cstring>
43 </property>
44 <property stdset="1">
45 <name>text</name>
46 <string>&lt;qt&gt;&lt;h2&gt;Please set a password for the Superuser.&lt;/h2&gt;&lt;/qt&gt;</string>
47 </property>
48 </widget>
49 <widget row="1" column="0" >
50 <class>QLayoutWidget</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>Layout5</cstring>
54 </property>
55 <grid>
56 <property stdset="1">
57 <name>margin</name>
58 <number>0</number>
59 </property>
60 <property stdset="1">
61 <name>spacing</name>
62 <number>6</number>
63 </property>
64 <widget row="0" column="1" >
65 <class>QLineEdit</class>
66 <property stdset="1">
67 <name>name</name>
68 <cstring>m_pass</cstring>
69 </property>
70 <property stdset="1">
71 <name>echoMode</name>
72 <enum>Password</enum>
73 </property>
74 </widget>
75 <widget row="0" column="0" >
76 <class>QLabel</class>
77 <property stdset="1">
78 <name>name</name>
79 <cstring>m_passLabel</cstring>
80 </property>
81 <property stdset="1">
82 <name>text</name>
83 <string>&lt;b&gt;Password:&lt;/b&gt;</string>
84 </property>
85 <property>
86 <name>buddy</name>
87 <cstring>m_pass</cstring>
88 </property>
89 </widget>
90 <widget row="0" column="2" >
91 <class>QToolButton</class>
92 <property stdset="1">
93 <name>name</name>
94 <cstring>ToolButton3</cstring>
95 </property>
96 <property stdset="1">
97 <name>text</name>
98 <string></string>
99 </property>
100 <property stdset="1">
101 <name>pixmap</name>
102 <pixmap>image0</pixmap>
103 </property>
104 <property stdset="1">
105 <name>toggleButton</name>
106 <bool>true</bool>
107 </property>
108 <property stdset="1">
109 <name>toggleButton</name>
110 <bool>true</bool>
111 </property>
112 </widget>
113 <widget row="1" column="3" >
114 <class>QToolButton</class>
115 <property stdset="1">
116 <name>name</name>
117 <cstring>ToolButton1_2</cstring>
118 </property>
119 <property stdset="1">
120 <name>text</name>
121 <string></string>
122 </property>
123 <property stdset="1">
124 <name>pixmap</name>
125 <pixmap>image1</pixmap>
126 </property>
127 </widget>
128 <widget row="1" column="1" >
129 <class>QLineEdit</class>
130 <property stdset="1">
131 <name>name</name>
132 <cstring>m_confirm</cstring>
133 </property>
134 <property stdset="1">
135 <name>echoMode</name>
136 <enum>Password</enum>
137 </property>
138 </widget>
139 <widget row="0" column="3" >
140 <class>QToolButton</class>
141 <property stdset="1">
142 <name>name</name>
143 <cstring>ToolButton1</cstring>
144 </property>
145 <property stdset="1">
146 <name>text</name>
147 <string></string>
148 </property>
149 <property stdset="1">
150 <name>pixmap</name>
151 <pixmap>image1</pixmap>
152 </property>
153 </widget>
154 <widget row="1" column="0" >
155 <class>QLabel</class>
156 <property stdset="1">
157 <name>name</name>
158 <cstring>m_confirmLbl</cstring>
159 </property>
160 <property stdset="1">
161 <name>text</name>
162 <string>&lt;b&gt;Confirm:&lt;/b&gt;</string>
163 </property>
164 </widget>
165 </grid>
166 </widget>
167 <spacer row="2" column="0" >
168 <property>
169 <name>name</name>
170 <cstring>Spacer2</cstring>
171 </property>
172 <property stdset="1">
173 <name>orientation</name>
174 <enum>Vertical</enum>
175 </property>
176 <property stdset="1">
177 <name>sizeType</name>
178 <enum>Expanding</enum>
179 </property>
180 <property>
181 <name>sizeHint</name>
182 <size>
183 <width>20</width>
184 <height>20</height>
185 </size>
186 </property>
187 </spacer>
188 </grid>
189</widget>
190<images>
191 <image>
192 <name>image0</name>
193 <data format="XPM.GZ" length="394">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022230543251d2e253d856405bffcbc54105b19c856360003b0141a808a2983b03284848a298304c108240e15033141045829580cac07ac4e590f5d0c22a4876caf32d45898797a48044caf32c22948e629c39d0457a78ce60f65b8f104ec50d6c366af1e865eb4b0aab5e602008bcd444d</data>
194 </image>
195 <image>
196 <name>image1</name>
197 <data format="XPM.GZ" length="341">789c558fcd0a02310c84ef7d8ad0b915c9bae84d7c04c5a3201e4275d1c32ab8eb41c477b73fa96e43a1f30d4d266d1ced771b728d194619af9efc451ee44ecfbe7f1d8eebb7b1ed92c259506b67c63279dade6fe7a81134e6a9224ac4ae2bc85565075004901c8820731069a648b490effc26eac4a25dcc195373c94231b87a8349fabf894b7a3d27a76af8cf01eb0e534757d70da1bf8a933f2bf30509e84b68</data>
198 </image>
199</images>
200<connections>
201 <connection>
202 <sender>ToolButton3</sender>
203 <signal>toggled(bool)</signal>
204 <receiver>PasswordDialog</receiver>
205 <slot>slotToggleEcho(bool)</slot>
206 </connection>
207 <connection>
208 <sender>ToolButton1</sender>
209 <signal>clicked()</signal>
210 <receiver>m_pass</receiver>
211 <slot>clear()</slot>
212 </connection>
213 <connection>
214 <sender>ToolButton1_2</sender>
215 <signal>clicked()</signal>
216 <receiver>m_confirm</receiver>
217 <slot>clear()</slot>
218 </connection>
219 <slot access="protected">slotToggleEcho(bool)</slot>
220</connections>
221<tabstops>
222 <tabstop>m_pass</tabstop>
223 <tabstop>m_confirm</tabstop>
224</tabstops>
225</UI>
diff --git a/core/opie-login/passworddialogimpl.cpp b/core/opie-login/passworddialogimpl.cpp
new file mode 100644
index 0000000..aeb7516
--- a/dev/null
+++ b/core/opie-login/passworddialogimpl.cpp
@@ -0,0 +1,232 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2004 Holger Hans Peter Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.
25
26*/
27
28
29#include <qlayout.h>
30#include <qlabel.h>
31#include <qlineedit.h>
32#include <qvalidator.h>
33#include <qmessagebox.h>
34#include <qhbox.h>
35#include <qtoolbutton.h>
36
37#include <sys/types.h>
38#include <pwd.h>
39#include <shadow.h>
40#include <stdio.h>
41#include <time.h>
42#include <unistd.h>
43
44
45#include "passworddialogimpl.h"
46
47
48// This function is taken from 'busybox'.
49static int i64c(int i) {
50 if (i <= 0)
51 return ('.');
52 if (i == 1)
53 return ('/');
54 if (i >= 2 && i < 12)
55 return ('0' - 2 + i);
56 if (i >= 12 && i < 38)
57 return ('A' - 12 + i);
58 if (i >= 38 && i < 63)
59 return ('a' - 38 + i);
60 return ('z');
61}
62
63// This function is taken from 'busybox'.
64static char *crypt_make_salt() {
65 time_t now;
66 static unsigned long x;
67 static char result[3];
68
69 ::time(&now);
70 x += now + getpid() + clock();
71 result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077);
72 result[1] = i64c(((x >> 12) ^ x) & 077);
73 result[2] = '\0';
74 return result;
75}
76
77/*
78 * Modal dialog to force root password. It is quite hard as it only leave
79 * when a password is set.
80 * Also it prevalidates the password...
81 */
82PasswordDialogImpl::PasswordDialogImpl( QWidget* parent )
83 : PasswordDialog( parent, 0, true ), m_isSet( PasswordDialogImpl::needDialog() ) {
84}
85
86PasswordDialogImpl::~PasswordDialogImpl() {
87 /* qt does the stuff for us */
88}
89
90void PasswordDialogImpl::done(int res) {
91 m_isSet = true;
92
93 /*
94 * The user hit 'Ok' see if we can safe the file
95 * if not an error will be raised and m_isSet altered.
96 * On cancel we will see if it is now ok...
97 */
98 if ( res == Accepted )
99 writePassword();
100 else if(PasswordDialogImpl::needDialog() ) {
101 switch( QMessageBox::warning(this,tr("Trying to leave without password set") ,
102 tr("<qt>No password was set. This could lead to you not beeing"
103 "able to remotely connect to your machine."
104 "Do you want to continue not setting a password?</qt>" ),
105 QMessageBox::Ok, QMessageBox::Cancel ) ) {
106 case QMessageBox::Cancel:
107 m_isSet = false;
108 break;
109 case QMessageBox::Ok:
110 default:
111 break;
112 }
113
114 }
115
116 if(m_isSet)
117 PasswordDialog::done( res );
118}
119
120/*
121 * Lets see if we can write either shadow
122 *
123 */
124/**
125 * CRYPT the password and then tries to write it either to the shadow password
126 * or to the plain /etc/passwd
127 */
128void PasswordDialogImpl::writePassword() {
129 /*
130 * Check if both texts are the same
131 */
132 if ( m_pass->text() != m_confirm->text() )
133 return error( tr("Passwords don't match"),
134 tr("<qt>The two passwords don't match. Please try again.</qt>") );
135
136
137 /*
138 * Now crypt the password so we can write it later
139 */
140 char* password = ::crypt( m_pass->text().latin1(), crypt_make_salt() );
141
142 if ( !password )
143 return error( tr("Password not legal" ),
144 tr("<qt>The entered password is not a valid password."
145 "Please try entering a valid password.</qt>" ) );
146
147 /* rewind and rewrite the password file */
148 ::setpwent();
149
150 FILE* file = ::fopen( "/etc/passwd.new", "w" );
151 struct passwd* pass;
152 while ( (pass = ::getpwent()) != 0l ) {
153 /* no shadow password support */
154 if ( pass->pw_uid == 0 )
155 pass->pw_passwd = password;
156
157 ::putpwent( pass, file );
158 }
159
160 ::fclose( file );
161 ::endpwent();
162 ::unlink("/etc/passwd");
163 ::rename("/etc/passwd.new","/etc/passwd" );
164
165 /* should be done now */
166#ifdef OPIE_LOGIN_SHADOW_PW
167 #error "Can't write Shadow Passwords fixme"
168#endif
169}
170
171/**
172 * Raise an error. Delete input and set the focus after showing
173 * the error to the user
174 */
175void PasswordDialogImpl::error( const QString& caption, const QString& text ) {
176 m_isSet = false;
177 QMessageBox::critical(this,caption, text,
178 QMessageBox::Ok, QMessageBox::NoButton );
179
180 m_pass->setText("");
181 m_pass->setFocus();
182
183 m_confirm->setText("");
184}
185
186void PasswordDialogImpl::slotToggleEcho( bool b ) {
187 m_pass-> setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password );
188 m_confirm->setEchoMode( b ? QLineEdit::Normal : QLineEdit::Password );
189}
190
191/////////////////////////
192/// static functions
193///
194
195/**
196 * Ask whether or not we need to show the dialog. It returns true if
197 * no root password is set so that the user will be able to set one.
198 */
199bool PasswordDialogImpl::needDialog() {
200 /*
201 * This can cope with no password and shadow passwords
202 * Let us go through the user database until we find 'root' and then
203 * see if it is 'shadow' and see if shadow is empty or see if the password is empty
204 */
205 bool need = false;
206 struct passwd *pwd;
207 ::setpwent();
208
209 while((pwd = ::getpwent() ) ) {
210 /* found root */
211 if( pwd->pw_uid == 0 ) {
212 QString str = QString::fromLatin1(pwd->pw_passwd );
213
214 /*
215 * If str is really empty it is passwordless anyway...
216 * else it is shadow based
217 */
218 if(str.isEmpty() )
219 need = true;
220 else if ( str == '*' || str == 'x' )
221#ifdef OPIE_LOGIN_SHADOW_PW
222 need = QString::fromLatin1( ::getspnam( pwd->pw_name )->sp_pwdp ).isEmpty();
223#else
224 ;
225#endif
226 break;
227 }
228 }
229 ::endpwent();
230
231 return need;
232}
diff --git a/core/opie-login/passworddialogimpl.h b/core/opie-login/passworddialogimpl.h
new file mode 100644
index 0000000..f8953dd
--- a/dev/null
+++ b/core/opie-login/passworddialogimpl.h
@@ -0,0 +1,65 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2004 Holger Hans Peter Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This file is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This file is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
17..}^=.=       =       ; Public License for more details.
18++=   -.     .`     .:
19 :     =  ...= . :.=- You should have received a copy of the GNU
20 -.   .:....=;==+<; General Public License along with this file;
21  -_. . .   )=.  = see the file COPYING. If not, write to the
22    --        :-=` Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330,
24 Boston, MA 02111-1307, USA.
25
26*/
27
28
29#ifndef OPIE_LOGIN_PASSWORDIMPL_DIALOG_H
30#define OPIE_LOGIN_PASSWORDIMPL_DIALOG_H
31
32#include "passworddialog.h"
33
34
35class QLineEdit;
36/**
37 * Small Dialog and Class to set the root password if it
38 * is not empty.
39 * \code
40 * if(PasswordDialogImpl::needDialog()) {
41 * PasswordDialogImpl *dia = new PasswordDialogImpl()
42 * dia->exec();
43 * dia->delete();
44 * }
45 */
46class PasswordDialogImpl : public PasswordDialog {
47 Q_OBJECT
48public:
49 PasswordDialogImpl( QWidget *parent );
50 ~PasswordDialogImpl();
51 static bool needDialog();
52
53protected slots:
54 void done( int );
55 void slotToggleEcho( bool );
56
57private:
58 void writePassword();
59 void writeShadow();
60 void error( const QString&, const QString& );
61 bool m_isSet : 1;
62};
63
64
65#endif