summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginwindow.ui396
-rw-r--r--core/opie-login/loginwindowimpl.cpp323
-rw-r--r--core/opie-login/loginwindowimpl.h33
-rw-r--r--core/opie-login/main.cpp178
-rw-r--r--core/opie-login/opie-login.pro25
5 files changed, 955 insertions, 0 deletions
diff --git a/core/opie-login/loginwindow.ui b/core/opie-login/loginwindow.ui
new file mode 100644
index 0000000..86d5469
--- a/dev/null
+++ b/core/opie-login/loginwindow.ui
@@ -0,0 +1,396 @@
1<!DOCTYPE UI><UI>
2<class>LoginWindow</class>
3<widget>
4 <class>QWidget</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>LoginWindow</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>472</width>
15 <height>341</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Login</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>0</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>0</number>
36 </property>
37 <widget>
38 <class>QLayoutWidget</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>Layout7</cstring>
42 </property>
43 <property>
44 <name>layoutMargin</name>
45 </property>
46 <vbox>
47 <property stdset="1">
48 <name>margin</name>
49 <number>4</number>
50 </property>
51 <property stdset="1">
52 <name>spacing</name>
53 <number>6</number>
54 </property>
55 <widget>
56 <class>QLabel</class>
57 <property stdset="1">
58 <name>name</name>
59 <cstring>m_caption</cstring>
60 </property>
61 <property stdset="1">
62 <name>sizePolicy</name>
63 <sizepolicy>
64 <hsizetype>5</hsizetype>
65 <vsizetype>5</vsizetype>
66 </sizepolicy>
67 </property>
68 <property stdset="1">
69 <name>autoMask</name>
70 <bool>true</bool>
71 </property>
72 <property stdset="1">
73 <name>backgroundOrigin</name>
74 <enum>ParentOrigin</enum>
75 </property>
76 <property stdset="1">
77 <name>text</name>
78 <string>&lt;center&gt;&lt;h1&gt;Welcome to OPIE&lt;/h1&gt;&lt;/center&gt;</string>
79 </property>
80 </widget>
81 <widget>
82 <class>QLayoutWidget</class>
83 <property stdset="1">
84 <name>name</name>
85 <cstring>Layout6</cstring>
86 </property>
87 <property>
88 <name>layoutSpacing</name>
89 </property>
90 <grid>
91 <property stdset="1">
92 <name>margin</name>
93 <number>0</number>
94 </property>
95 <property stdset="1">
96 <name>spacing</name>
97 <number>4</number>
98 </property>
99 <widget row="0" column="1" >
100 <class>QComboBox</class>
101 <property stdset="1">
102 <name>name</name>
103 <cstring>m_user</cstring>
104 </property>
105 <property stdset="1">
106 <name>autoMask</name>
107 <bool>true</bool>
108 </property>
109 <property stdset="1">
110 <name>editable</name>
111 <bool>true</bool>
112 </property>
113 <property stdset="1">
114 <name>autoCompletion</name>
115 <bool>true</bool>
116 </property>
117 </widget>
118 <widget row="0" column="0" >
119 <class>QLabel</class>
120 <property stdset="1">
121 <name>name</name>
122 <cstring>TextLabel1</cstring>
123 </property>
124 <property stdset="1">
125 <name>autoMask</name>
126 <bool>true</bool>
127 </property>
128 <property stdset="1">
129 <name>backgroundOrigin</name>
130 <enum>ParentOrigin</enum>
131 </property>
132 <property stdset="1">
133 <name>text</name>
134 <string>User</string>
135 </property>
136 </widget>
137 <widget row="1" column="1" >
138 <class>QLayoutWidget</class>
139 <property stdset="1">
140 <name>name</name>
141 <cstring>Layout5</cstring>
142 </property>
143 <property>
144 <name>layoutSpacing</name>
145 </property>
146 <hbox>
147 <property stdset="1">
148 <name>margin</name>
149 <number>0</number>
150 </property>
151 <property stdset="1">
152 <name>spacing</name>
153 <number>4</number>
154 </property>
155 <widget>
156 <class>QLineEdit</class>
157 <property stdset="1">
158 <name>name</name>
159 <cstring>m_password</cstring>
160 </property>
161 <property stdset="1">
162 <name>autoMask</name>
163 <bool>true</bool>
164 </property>
165 <property stdset="1">
166 <name>echoMode</name>
167 <enum>Password</enum>
168 </property>
169 </widget>
170 <widget>
171 <class>QToolButton</class>
172 <property stdset="1">
173 <name>name</name>
174 <cstring>ToolButton3</cstring>
175 </property>
176 <property stdset="1">
177 <name>text</name>
178 <string></string>
179 </property>
180 <property stdset="1">
181 <name>pixmap</name>
182 <pixmap>image0</pixmap>
183 </property>
184 <property stdset="1">
185 <name>toggleButton</name>
186 <bool>true</bool>
187 </property>
188 <property stdset="1">
189 <name>toggleButton</name>
190 <bool>true</bool>
191 </property>
192 </widget>
193 <widget>
194 <class>QToolButton</class>
195 <property stdset="1">
196 <name>name</name>
197 <cstring>ToolButton1</cstring>
198 </property>
199 <property stdset="1">
200 <name>text</name>
201 <string></string>
202 </property>
203 <property stdset="1">
204 <name>pixmap</name>
205 <pixmap>image1</pixmap>
206 </property>
207 </widget>
208 </hbox>
209 </widget>
210 <widget row="1" column="0" >
211 <class>QLabel</class>
212 <property stdset="1">
213 <name>name</name>
214 <cstring>TextLabel2</cstring>
215 </property>
216 <property stdset="1">
217 <name>autoMask</name>
218 <bool>true</bool>
219 </property>
220 <property stdset="1">
221 <name>backgroundOrigin</name>
222 <enum>ParentOrigin</enum>
223 </property>
224 <property stdset="1">
225 <name>text</name>
226 <string>Password</string>
227 </property>
228 </widget>
229 </grid>
230 </widget>
231 <widget>
232 <class>Line</class>
233 <property stdset="1">
234 <name>name</name>
235 <cstring>Line1</cstring>
236 </property>
237 <property stdset="1">
238 <name>orientation</name>
239 <enum>Horizontal</enum>
240 </property>
241 </widget>
242 <widget>
243 <class>QLayoutWidget</class>
244 <property stdset="1">
245 <name>name</name>
246 <cstring>Layout3</cstring>
247 </property>
248 <property>
249 <name>layoutSpacing</name>
250 </property>
251 <hbox>
252 <property stdset="1">
253 <name>margin</name>
254 <number>0</number>
255 </property>
256 <property stdset="1">
257 <name>spacing</name>
258 <number>4</number>
259 </property>
260 <widget>
261 <class>QPushButton</class>
262 <property stdset="1">
263 <name>name</name>
264 <cstring>m_login</cstring>
265 </property>
266 <property stdset="1">
267 <name>autoMask</name>
268 <bool>true</bool>
269 </property>
270 <property stdset="1">
271 <name>text</name>
272 <string>Login</string>
273 </property>
274 </widget>
275 <widget>
276 <class>QPushButton</class>
277 <property stdset="1">
278 <name>name</name>
279 <cstring>m_suspend</cstring>
280 </property>
281 <property stdset="1">
282 <name>autoMask</name>
283 <bool>true</bool>
284 </property>
285 <property stdset="1">
286 <name>text</name>
287 <string>Suspend</string>
288 </property>
289 </widget>
290 <widget>
291 <class>QPushButton</class>
292 <property stdset="1">
293 <name>name</name>
294 <cstring>m_menu</cstring>
295 </property>
296 <property stdset="1">
297 <name>autoMask</name>
298 <bool>true</bool>
299 </property>
300 <property stdset="1">
301 <name>text</name>
302 <string>Menu</string>
303 </property>
304 </widget>
305 </hbox>
306 </widget>
307 <spacer>
308 <property>
309 <name>name</name>
310 <cstring>Spacer1</cstring>
311 </property>
312 <property stdset="1">
313 <name>orientation</name>
314 <enum>Vertical</enum>
315 </property>
316 <property stdset="1">
317 <name>sizeType</name>
318 <enum>Expanding</enum>
319 </property>
320 <property>
321 <name>sizeHint</name>
322 <size>
323 <width>20</width>
324 <height>20</height>
325 </size>
326 </property>
327 </spacer>
328 </vbox>
329 </widget>
330 <widget>
331 <class>QFrame</class>
332 <property stdset="1">
333 <name>name</name>
334 <cstring>m_taskbar</cstring>
335 </property>
336 <property stdset="1">
337 <name>frameShape</name>
338 <enum>NoFrame</enum>
339 </property>
340 <property stdset="1">
341 <name>frameShadow</name>
342 <enum>Raised</enum>
343 </property>
344 <property stdset="1">
345 <name>margin</name>
346 <number>0</number>
347 </property>
348 </widget>
349 </vbox>
350</widget>
351<images>
352 <image>
353 <name>image0</name>
354 <data format="XPM.GZ" length="394">789cd3d7528808f055d0d2e72a2e492cc94c5648ce482c52d04a29cdcdad8c8eb5ade6523234530022230543251d2e253d856405bffcbc54105b19c856360003b0141a808a2983b03284848a298304c108240e15033141045829580cac07ac4e590f5d0c22a4876caf32d45898797a48044caf32c22948e629c39d0457a78ce60f65b8f104ec50d6c366af1e865eb4b0aab5e602008bcd444d</data>
355 </image>
356 <image>
357 <name>image1</name>
358 <data format="XPM.GZ" length="341">789c558fcd0a02310c84ef7d8ad0b915c9bae84d7c04c5a3201e4275d1c32ab8eb41c477b73fa96e43a1f30d4d266d1ced771b728d194619af9efc451ee44ecfbe7f1d8eebb7b1ed92c259506b67c63279dade6fe7a81134e6a9224ac4ae2bc85565075004901c8820731069a648b490effc26eac4a25dcc195373c94231b87a8349fabf894b7a3d27a76af8cf01eb0e534757d70da1bf8a933f2bf30509e84b68</data>
359 </image>
360</images>
361<connections>
362 <connection>
363 <sender>ToolButton1</sender>
364 <signal>clicked()</signal>
365 <receiver>m_password</receiver>
366 <slot>clear()</slot>
367 </connection>
368 <connection>
369 <sender>ToolButton3</sender>
370 <signal>toggled(bool)</signal>
371 <receiver>LoginWindow</receiver>
372 <slot>toggleEchoMode(bool)</slot>
373 </connection>
374 <connection>
375 <sender>m_suspend</sender>
376 <signal>clicked()</signal>
377 <receiver>LoginWindow</receiver>
378 <slot>suspend()</slot>
379 </connection>
380 <connection>
381 <sender>m_password</sender>
382 <signal>returnPressed()</signal>
383 <receiver>m_login</receiver>
384 <slot>animateClick()</slot>
385 </connection>
386 <connection>
387 <sender>m_login</sender>
388 <signal>clicked()</signal>
389 <receiver>LoginWindow</receiver>
390 <slot>login()</slot>
391 </connection>
392 <slot access="public">login()</slot>
393 <slot access="public">suspend()</slot>
394 <slot access="public">toggleEchoMode(bool)</slot>
395</connections>
396</UI>
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp
new file mode 100644
index 0000000..3265b46
--- a/dev/null
+++ b/core/opie-login/loginwindowimpl.cpp
@@ -0,0 +1,323 @@
1#include <qapplication.h>
2#include <qpushbutton.h>
3#include <qlayout.h>
4#include <qframe.h>
5#include <qlineedit.h>
6#include <qtimer.h>
7#include <qcombobox.h>
8#include <qpixmap.h>
9#include <qlabel.h>
10#include <qpopupmenu.h>
11#include <qmessagebox.h>
12
13#include <qpe/qcopenvelope_qws.h>
14
15#include <opie/odevice.h>
16
17#include <stdio.h>
18
19#include <pwd.h>
20#include <grp.h>
21#include <unistd.h>
22#include <stdlib.h>
23
24#ifdef USEPAM
25extern "C" {
26#include <security/pam_appl.h>
27}
28#else
29#include <crypt.h>
30#include <shadow.h>
31#endif
32
33#include "loginwindowimpl.h"
34#include "inputmethods.h"
35
36LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
37{
38 QPopupMenu *pop = new QPopupMenu ( this );
39 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( )));
40 m_menu-> setPopup ( pop );
41
42 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 );
43 m_input = new InputMethods ( m_taskbar );
44 lay-> addWidget ( m_input );
45 lay-> addStretch ( 10 );
46
47 setActiveWindow ( );
48 m_password-> setFocus ( );
49
50 m_user-> insertStringList ( getAllUsers ( ));
51
52 QTimer::singleShot ( 0, this, SLOT( showIM ( )));
53
54 QString opiedir = ::getenv ( "OPIEDIR" );
55 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" );
56
57 if ( !bgpix. isNull ( ))
58 setBackgroundPixmap ( bgpix );
59
60 m_caption-> setText ( m_caption-> text ( ) + tr( "<center><h1><u>%1 %2</u></h1></center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( )));
61}
62
63LoginWindowImpl::~LoginWindowImpl ( )
64{
65}
66
67void LoginWindowImpl::keyPressEvent ( QKeyEvent *e )
68{
69 switch ( e-> key ( )) {
70 case Key_F34: suspend ( );
71 break;
72 case Key_F35: backlight ( );
73 break;
74 default : e-> ignore ( );
75 break;
76 }
77 LoginWindow::keyPressEvent ( e );
78}
79
80
81void LoginWindowImpl::toggleEchoMode ( bool t )
82{
83 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password );
84}
85
86QStringList LoginWindowImpl::getAllUsers ( )
87{
88 struct passwd *pwd;
89 QStringList sl;
90
91 while (( pwd = getpwent ( ))) {
92 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 ))
93 sl << QString ( pwd-> pw_name );
94 }
95
96 endpwent ( );
97
98 return sl;
99}
100
101void LoginWindowImpl::showIM ( )
102{
103 m_input-> showInputMethod ( );
104}
105
106void LoginWindowImpl::restart ( )
107{
108 qApp-> quit ( );
109}
110
111void LoginWindowImpl::suspend ( )
112{
113 system ( "apm -s" );
114 usleep ( 1 * 1000 * 1000 );
115 {
116 QCopEnvelope e("QPE/System", "setBacklight(int)");
117 e << -3; // Force on
118 }
119}
120
121void LoginWindowImpl::backlight ( )
122{
123 {
124 QCopEnvelope e("QPE/System", "setBacklight(int)");
125 e << -2; // toggle
126 }
127}
128
129#ifdef USEPAM
130
131static const char *_PAM_SERVICE = "xdm";
132static const char *PAM_password;
133
134typedef const struct pam_message pam_message_type;
135
136static int PAM_conv( int, pam_message_type **, struct pam_response **, void * );
137
138static struct pam_conv PAM_conversation = {
139 &PAM_conv,
140 NULL
141};
142
143//----------------------------------------------------------------------------
144
145static char *COPY_STRING( const char * s ) {
146 return (s) ? strdup(s) : (char *)NULL;
147}
148
149#define GET_MEM if (reply) realloc(reply, size);\
150 else reply = (struct pam_response *)malloc(size); \
151 if (!reply) return PAM_CONV_ERR; \
152 size += sizeof(struct pam_response)
153
154
155static int PAM_conv( int num_msg, pam_message_type **msg,
156 struct pam_response **resp, void *)
157{
158 int count = 0, replies = 0;
159 struct pam_response *reply = NULL;
160 int size = sizeof(struct pam_response);
161
162 for( count = 0; count < num_msg; count++ ) {
163 switch (msg[count]->msg_style) {
164 case PAM_PROMPT_ECHO_ON:
165 /* user name given to PAM already */
166 return PAM_CONV_ERR;
167
168 case PAM_PROMPT_ECHO_OFF:
169 /* wants password */
170 GET_MEM;
171 reply[replies].resp_retcode = PAM_SUCCESS;
172 reply[replies].resp = COPY_STRING(PAM_password);
173 replies++;
174 /* PAM frees resp */
175 break;
176 case PAM_TEXT_INFO:
177 break;
178 default:
179 /* unknown or PAM_ERROR_MSG */
180 if (reply) free (reply);
181 return PAM_CONV_ERR;
182 }
183 }
184 if (reply) *resp = reply;
185 return PAM_SUCCESS;
186}
187
188
189static bool pwcheck_PAM( const char *user, const char *password )
190{
191 bool pw_correct = false;
192 int pam_error;
193 int pam_return = 0;
194 pam_handle_t *pamh = 0;
195 PAM_password = password;
196
197 pam_error = pam_start( _PAM_SERVICE, user, &PAM_conversation, &pamh );
198 if( pam_error == PAM_SUCCESS ) {
199 pam_error = pam_authenticate( pamh, 0 );
200 if( pam_error == PAM_SUCCESS ) {
201 //-- password correct
202 pw_correct = true;
203 pam_return = PAM_SUCCESS;
204 } else {
205 pam_return = pam_error;
206 }
207 } else {
208 // cerr << "PAM error: " << pam_strerror( pamh, pam_error ) << endl;
209 }
210 pam_end( pamh, pam_return );
211 return pw_correct;
212}
213
214#else
215
216//----------------------------------------------------------------------------
217
218static bool pwcheck_Unix( const char *user, const char *pass )
219{
220 char *encrypted, *correct;
221 struct passwd *pw;
222
223 if ( !user || !pass )
224 return false;
225
226 pw = getpwnam ( user );
227
228 if ( !pw )
229 return false;
230
231 if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
232 struct spwd *sp = getspnam ( pw-> pw_name );
233
234 if ( !sp )
235 return false;
236
237 correct = sp-> sp_pwdp;
238 }
239 else
240 correct = pw-> pw_passwd;
241
242 if ( correct == 0 || correct[0] == '\0' )
243 return true;
244
245 encrypted = crypt ( pass, correct );
246 return ( strcmp ( encrypted, correct ) == 0 );
247}
248
249#endif
250
251
252bool LoginWindowImpl::changeIdentity ( const char *user )
253{
254 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin";
255 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin";
256
257 bool fail = false;
258 struct passwd *pw = getpwnam ( user );
259
260 fail |= ( pw == 0 );
261 printf ( "1 %d\n", fail );
262 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid ));
263 endgrent ( );
264 printf ( "2 %d\n", fail );
265 fail |= ( setgid ( pw-> pw_gid ));
266 printf ( "3 %d\n", fail );
267 fail |= ( setuid ( pw-> pw_uid ));
268
269 printf ( "4 %d\n", fail );
270 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" ));
271
272 printf ( "5 %d\n", fail );
273 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 ));
274 printf ( "6 %d\n", fail );
275 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 ));
276 printf ( "7 %d\n", fail );
277 fail |= ( setenv ( "USER", pw-> pw_name, 1 ));
278 printf ( "8 %d\n", fail );
279 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 ));
280 printf ( "9 %d\n", fail );
281 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 ));
282 printf ( "10 %d\n", fail );
283
284 return !fail;
285}
286
287void LoginWindowImpl::login ( )
288{
289 const char *user = strdup ( m_user-> currentText ( ). local8Bit ( ));
290 const char *pass = strdup ( m_password-> text ( ). local8Bit ( ));
291 bool ok;
292
293 if ( !user || !user [0] )
294 return;
295 if ( !pass )
296 pass = "";
297
298#if defined( USEPAM )
299 ok = pwcheck_PAM ( user, pass );
300#else
301 ok = pwcheck_Unix ( user, pass );
302#endif
303
304 if ( ok ) {
305 if ( changeIdentity ( user )) {
306 QString opie = getenv ( "OPIEDIR" );
307 opie += "/bin/qpe";
308
309 execl ( opie. latin1 ( ), "qpe", 0 );
310
311 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE." ));
312 restart ( );
313 }
314 else {
315 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" ));
316 restart ( );
317 }
318 }
319 else {
320 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
321 m_password-> clear ( );
322 }
323}
diff --git a/core/opie-login/loginwindowimpl.h b/core/opie-login/loginwindowimpl.h
new file mode 100644
index 0000000..16c42e6
--- a/dev/null
+++ b/core/opie-login/loginwindowimpl.h
@@ -0,0 +1,33 @@
1#ifndef __OPIE_LOGINWINDOW_IMPL_H__
2#define __OPIE_LOGINWINDOW_IMPL_H__
3
4#include "loginwindow.h"
5
6class InputMethods;
7
8class LoginWindowImpl : public LoginWindow {
9 Q_OBJECT
10
11public:
12 LoginWindowImpl ( );
13 virtual ~LoginWindowImpl ( );
14
15protected slots:
16 void restart ( );
17 void showIM ( );
18 void suspend ( );
19 void backlight ( );
20 void login ( );
21 void toggleEchoMode ( bool );
22
23protected:
24 virtual void keyPressEvent ( QKeyEvent *e );
25
26 QStringList getAllUsers ( );
27 bool changeIdentity ( const char *user );
28
29private:
30 InputMethods *m_input;
31};
32
33#endif
diff --git a/core/opie-login/main.cpp b/core/opie-login/main.cpp
new file mode 100644
index 0000000..9d52b75
--- a/dev/null
+++ b/core/opie-login/main.cpp
@@ -0,0 +1,178 @@
1#include <sys/time.h>
2#include <sys/resource.h>
3#include <unistd.h>
4#include <syslog.h>
5#include <sys/types.h>
6#include <sys/wait.h>
7#include <stdio.h>
8
9#include <qpe/qpeapplication.h>
10#include <qpe/qcopenvelope_qws.h>
11
12#include <opie/odevice.h>
13
14#include <qwindowsystem_qws.h>
15#include <qfile.h>
16
17#include "loginwindowimpl.h"
18#include "calibrate.h"
19
20int login_main ( int argc, char **argv );
21
22
23int main ( int argc, char **argv )
24{
25 if ( geteuid ( ) != 0 ) {
26 fprintf ( stderr, "%s can only be executed by root. (or chmod +s)", argv [0] );
27 return 1;
28 }
29
30 //struct rlimit rl;
31 //getrlimit ( RLIMIT_NOFILE, &rl );
32
33 //for ( unsigned int i = 0; i < rl. rlim_cur; i++ )
34 // close ( i );
35
36 setpgid ( 0, 0 );
37 setsid ( );
38
39 openlog ( "opie-login", LOG_CONS, LOG_AUTHPRIV );
40
41 while ( true ) {
42 pid_t child = fork ( );
43
44 if ( child < 0 ) {
45 syslog ( LOG_ERR, "Could not fork process" );
46 break;
47
48 }
49 else if ( child > 0 ) {
50 int status = 0;
51
52 while ( waitpid ( child, &status, 0 ) < 0 ) { }
53 }
54 else {
55 exit ( login_main ( argc, argv ));
56 }
57 }
58 closelog ( );
59}
60
61
62class ModelKeyFilter : public QObject, public QWSServer::KeyboardFilter
63{
64public:
65 ModelKeyFilter ( ) : QObject ( 0, "MODEL_KEY_FILTER" )
66 {
67 bool doinst = false;
68
69 m_model = ODevice::inst ( )-> model ( );
70 m_power_timer = 0;
71
72 switch ( m_model ) {
73 case OMODEL_iPAQ_H31xx:
74 case OMODEL_iPAQ_H36xx:
75 case OMODEL_iPAQ_H37xx:
76 case OMODEL_iPAQ_H38xx: doinst = true;
77 break;
78 default : break;
79 }
80 if ( doinst )
81 QWSServer::setKeyboardFilter ( this );
82 }
83
84 virtual bool filter ( int /*unicode*/, int keycode, int modifiers, bool isPress, bool autoRepeat )
85 {
86 bool kill = false;
87
88 // Rotate cursor keys 180°
89 switch ( m_model ) {
90 case OMODEL_iPAQ_H31xx:
91 case OMODEL_iPAQ_H38xx: {
92 int newkeycode = keycode;
93
94 switch ( keycode ) {
95 case Key_Left : newkeycode = Key_Right; break;
96 case Key_Right: newkeycode = Key_Left; break;
97 case Key_Up : newkeycode = Key_Down; break;
98 case Key_Down : newkeycode = Key_Up; break;
99 }
100 if ( newkeycode != keycode ) {
101 QWSServer::sendKeyEvent ( -1, newkeycode, modifiers, isPress, autoRepeat );
102 kill = true;
103 }
104 break;
105 }
106 default: break;
107 }
108
109 // map Power Button short/long press to F34/F35
110 switch ( m_model ) {
111 case OMODEL_iPAQ_H31xx:
112 case OMODEL_iPAQ_H36xx:
113 case OMODEL_iPAQ_H37xx:
114 case OMODEL_iPAQ_H38xx: {
115 if ( keycode == Key_SysReq ) {
116 if ( isPress ) {
117 m_power_timer = startTimer ( 500 );
118 }
119 else if ( m_power_timer ) {
120 killTimer ( m_power_timer );
121 m_power_timer = 0;
122 QWSServer::sendKeyEvent ( -1, Key_F34, 0, true, false );
123 QWSServer::sendKeyEvent ( -1, Key_F34, 0, false, false );
124 }
125 kill = true;
126 }
127 break;
128 }
129 default: break;
130 }
131 return kill;
132 }
133
134 virtual void timerEvent ( QTimerEvent * )
135 {
136 killTimer ( m_power_timer );
137 m_power_timer = 0;
138 QWSServer::sendKeyEvent ( -1, Key_F35, 0, true, false );
139 QWSServer::sendKeyEvent ( -1, Key_F35, 0, false, false );
140 }
141
142private:
143 OModel m_model;
144 int m_power_timer;
145};
146
147
148
149
150int login_main ( int argc, char **argv )
151{
152 QWSServer::setDesktopBackground( QImage() );
153 QPEApplication app ( argc, argv, QApplication::GuiServer );
154
155 (void) new ModelKeyFilter ( );
156
157 {
158 QCopEnvelope e("QPE/System", "setBacklight(int)" );
159 e << -3; // Forced on
160 }
161
162#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
163 if ( !QFile::exists ( "/etc/pointercal" )) {
164 // Make sure calibration widget starts on top.
165 Calibrate *cal = new Calibrate;
166 cal-> exec ( );
167 delete cal;
168 }
169#endif
170
171 LoginWindowImpl *lw = new LoginWindowImpl ( );
172 app. setMainWidget ( lw );
173 lw-> setGeometry ( 0, 0, app. desktop ( )-> width ( ), app. desktop ( )-> height ( ));
174 lw-> show ( );
175
176 return app. exec ( );
177}
178
diff --git a/core/opie-login/opie-login.pro b/core/opie-login/opie-login.pro
new file mode 100644
index 0000000..35c1ed0
--- a/dev/null
+++ b/core/opie-login/opie-login.pro
@@ -0,0 +1,25 @@
1TEMPLATE = app
2CONFIG = qt warn_on debug usepam
3
4HEADERS = loginwindowimpl.h \
5 ../launcher/inputmethods.h \
6 ../apps/calibrate/calibrate.h
7
8SOURCES = loginwindowimpl.cpp \
9 ../launcher/inputmethods.cpp \
10 ../apps/calibrate/calibrate.cpp \
11 main.cpp
12
13INTERFACES = loginwindow.ui
14
15INCLUDEPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate
16DEPENDPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate
17
18LIBS += -lqpe -lopie
19
20usepam:LIBS += -lpam
21usepam:DEFINES += USEPAM
22
23DESTDIR = $(OPIEDIR)/bin
24TARGET = opie-login
25