summaryrefslogtreecommitdiff
authorsandman <sandman>2002-08-01 14:05:32 (UTC)
committer sandman <sandman>2002-08-01 14:05:32 (UTC)
commit66c4051568427ae3ffd5d8707e1cc91ce8ffbe62 (patch) (unidiff)
treeefeb6b333374349c4e08fbd8c3c16acc727f394b
parent32b7fdb0e9e5ec6cb6f791962efe68c40564b178 (diff)
downloadopie-66c4051568427ae3ffd5d8707e1cc91ce8ffbe62.zip
opie-66c4051568427ae3ffd5d8707e1cc91ce8ffbe62.tar.gz
opie-66c4051568427ae3ffd5d8707e1cc91ce8ffbe62.tar.bz2
Revert the non-gcc3-fix part of the gcc3-fix from Harlekin
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginwindowimpl.cpp1
-rw-r--r--core/opie-login/opie-login.pro4
2 files changed, 2 insertions, 3 deletions
diff --git a/core/opie-login/loginwindowimpl.cpp b/core/opie-login/loginwindowimpl.cpp
index 26d9225..3265b46 100644
--- a/core/opie-login/loginwindowimpl.cpp
+++ b/core/opie-login/loginwindowimpl.cpp
@@ -1,324 +1,323 @@
1#include <qapplication.h> 1#include <qapplication.h>
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qlayout.h> 3#include <qlayout.h>
4#include <qframe.h> 4#include <qframe.h>
5#include <qlineedit.h> 5#include <qlineedit.h>
6#include <qtimer.h> 6#include <qtimer.h>
7#include <qcombobox.h> 7#include <qcombobox.h>
8#include <qpixmap.h> 8#include <qpixmap.h>
9#include <qlabel.h> 9#include <qlabel.h>
10#include <qpopupmenu.h> 10#include <qpopupmenu.h>
11#include <qmessagebox.h> 11#include <qmessagebox.h>
12 12
13#include <qpe/qcopenvelope_qws.h> 13#include <qpe/qcopenvelope_qws.h>
14 14
15#include <opie/odevice.h> 15#include <opie/odevice.h>
16 16
17#include <stdio.h> 17#include <stdio.h>
18 18
19#include <pwd.h> 19#include <pwd.h>
20#include <grp.h> 20#include <grp.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <stdlib.h> 22#include <stdlib.h>
23 23
24#undef USEPAM // FOR my toolchain
25#ifdef USEPAM 24#ifdef USEPAM
26extern "C" { 25extern "C" {
27#include <security/pam_appl.h> 26#include <security/pam_appl.h>
28} 27}
29#else 28#else
30#include <crypt.h> 29#include <crypt.h>
31#include <shadow.h> 30#include <shadow.h>
32#endif 31#endif
33 32
34#include "loginwindowimpl.h" 33#include "loginwindowimpl.h"
35#include "inputmethods.h" 34#include "inputmethods.h"
36 35
37LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose ) 36LoginWindowImpl::LoginWindowImpl ( ) : LoginWindow ( 0, "LOGIN-WINDOW", WStyle_Customize | WStyle_NoBorder | WDestructiveClose )
38{ 37{
39 QPopupMenu *pop = new QPopupMenu ( this ); 38 QPopupMenu *pop = new QPopupMenu ( this );
40 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( ))); 39 pop-> insertItem ( tr( "Restart" ), this, SLOT( restart ( )));
41 m_menu-> setPopup ( pop ); 40 m_menu-> setPopup ( pop );
42 41
43 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 ); 42 QHBoxLayout *lay = new QHBoxLayout ( m_taskbar, 4, 4 );
44 m_input = new InputMethods ( m_taskbar ); 43 m_input = new InputMethods ( m_taskbar );
45 lay-> addWidget ( m_input ); 44 lay-> addWidget ( m_input );
46 lay-> addStretch ( 10 ); 45 lay-> addStretch ( 10 );
47 46
48 setActiveWindow ( ); 47 setActiveWindow ( );
49 m_password-> setFocus ( ); 48 m_password-> setFocus ( );
50 49
51 m_user-> insertStringList ( getAllUsers ( )); 50 m_user-> insertStringList ( getAllUsers ( ));
52 51
53 QTimer::singleShot ( 0, this, SLOT( showIM ( ))); 52 QTimer::singleShot ( 0, this, SLOT( showIM ( )));
54 53
55 QString opiedir = ::getenv ( "OPIEDIR" ); 54 QString opiedir = ::getenv ( "OPIEDIR" );
56 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" ); 55 QPixmap bgpix ( opiedir + "/pics/launcher/opie-background.jpg" );
57 56
58 if ( !bgpix. isNull ( )) 57 if ( !bgpix. isNull ( ))
59 setBackgroundPixmap ( bgpix ); 58 setBackgroundPixmap ( bgpix );
60 59
61 m_caption-> setText ( m_caption-> text ( ) + tr( "<center><h1><u>%1 %2</u></h1></center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( ))); 60 m_caption-> setText ( m_caption-> text ( ) + tr( "<center><h1><u>%1 %2</u></h1></center>" ). arg ( ODevice::inst ( )-> systemString ( )). arg ( ODevice::inst ( )-> systemVersionString ( )));
62} 61}
63 62
64LoginWindowImpl::~LoginWindowImpl ( ) 63LoginWindowImpl::~LoginWindowImpl ( )
65{ 64{
66} 65}
67 66
68void LoginWindowImpl::keyPressEvent ( QKeyEvent *e ) 67void LoginWindowImpl::keyPressEvent ( QKeyEvent *e )
69{ 68{
70 switch ( e-> key ( )) { 69 switch ( e-> key ( )) {
71 case Key_F34: suspend ( ); 70 case Key_F34: suspend ( );
72 break; 71 break;
73 case Key_F35: backlight ( ); 72 case Key_F35: backlight ( );
74 break; 73 break;
75 default : e-> ignore ( ); 74 default : e-> ignore ( );
76 break; 75 break;
77 } 76 }
78 LoginWindow::keyPressEvent ( e ); 77 LoginWindow::keyPressEvent ( e );
79} 78}
80 79
81 80
82void LoginWindowImpl::toggleEchoMode ( bool t ) 81void LoginWindowImpl::toggleEchoMode ( bool t )
83{ 82{
84 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password ); 83 m_password-> setEchoMode ( t ? QLineEdit::Normal : QLineEdit::Password );
85} 84}
86 85
87QStringList LoginWindowImpl::getAllUsers ( ) 86QStringList LoginWindowImpl::getAllUsers ( )
88{ 87{
89 struct passwd *pwd; 88 struct passwd *pwd;
90 QStringList sl; 89 QStringList sl;
91 90
92 while (( pwd = getpwent ( ))) { 91 while (( pwd = getpwent ( ))) {
93 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) 92 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 ))
94 sl << QString ( pwd-> pw_name ); 93 sl << QString ( pwd-> pw_name );
95 } 94 }
96 95
97 endpwent ( ); 96 endpwent ( );
98 97
99 return sl; 98 return sl;
100} 99}
101 100
102void LoginWindowImpl::showIM ( ) 101void LoginWindowImpl::showIM ( )
103{ 102{
104 m_input-> showInputMethod ( ); 103 m_input-> showInputMethod ( );
105} 104}
106 105
107void LoginWindowImpl::restart ( ) 106void LoginWindowImpl::restart ( )
108{ 107{
109 qApp-> quit ( ); 108 qApp-> quit ( );
110} 109}
111 110
112void LoginWindowImpl::suspend ( ) 111void LoginWindowImpl::suspend ( )
113{ 112{
114 system ( "apm -s" ); 113 system ( "apm -s" );
115 usleep ( 1 * 1000 * 1000 ); 114 usleep ( 1 * 1000 * 1000 );
116 { 115 {
117 QCopEnvelope e("QPE/System", "setBacklight(int)"); 116 QCopEnvelope e("QPE/System", "setBacklight(int)");
118 e << -3; // Force on 117 e << -3; // Force on
119 } 118 }
120} 119}
121 120
122void LoginWindowImpl::backlight ( ) 121void LoginWindowImpl::backlight ( )
123{ 122{
124 { 123 {
125 QCopEnvelope e("QPE/System", "setBacklight(int)"); 124 QCopEnvelope e("QPE/System", "setBacklight(int)");
126 e << -2; // toggle 125 e << -2; // toggle
127 } 126 }
128} 127}
129 128
130#ifdef USEPAM 129#ifdef USEPAM
131 130
132static const char *_PAM_SERVICE = "xdm"; 131static const char *_PAM_SERVICE = "xdm";
133static const char *PAM_password; 132static const char *PAM_password;
134 133
135typedef const struct pam_message pam_message_type; 134typedef const struct pam_message pam_message_type;
136 135
137static int PAM_conv( int, pam_message_type **, struct pam_response **, void * ); 136static int PAM_conv( int, pam_message_type **, struct pam_response **, void * );
138 137
139static struct pam_conv PAM_conversation = { 138static struct pam_conv PAM_conversation = {
140 &PAM_conv, 139 &PAM_conv,
141 NULL 140 NULL
142}; 141};
143 142
144//---------------------------------------------------------------------------- 143//----------------------------------------------------------------------------
145 144
146static char *COPY_STRING( const char * s ) { 145static char *COPY_STRING( const char * s ) {
147 return (s) ? strdup(s) : (char *)NULL; 146 return (s) ? strdup(s) : (char *)NULL;
148} 147}
149 148
150#define GET_MEM if (reply) realloc(reply, size);\ 149#define GET_MEM if (reply) realloc(reply, size);\
151 else reply = (struct pam_response *)malloc(size); \ 150 else reply = (struct pam_response *)malloc(size); \
152 if (!reply) return PAM_CONV_ERR; \ 151 if (!reply) return PAM_CONV_ERR; \
153 size += sizeof(struct pam_response) 152 size += sizeof(struct pam_response)
154 153
155 154
156static int PAM_conv( int num_msg, pam_message_type **msg, 155static int PAM_conv( int num_msg, pam_message_type **msg,
157 struct pam_response **resp, void *) 156 struct pam_response **resp, void *)
158{ 157{
159 int count = 0, replies = 0; 158 int count = 0, replies = 0;
160 struct pam_response *reply = NULL; 159 struct pam_response *reply = NULL;
161 int size = sizeof(struct pam_response); 160 int size = sizeof(struct pam_response);
162 161
163 for( count = 0; count < num_msg; count++ ) { 162 for( count = 0; count < num_msg; count++ ) {
164 switch (msg[count]->msg_style) { 163 switch (msg[count]->msg_style) {
165 case PAM_PROMPT_ECHO_ON: 164 case PAM_PROMPT_ECHO_ON:
166 /* user name given to PAM already */ 165 /* user name given to PAM already */
167 return PAM_CONV_ERR; 166 return PAM_CONV_ERR;
168 167
169 case PAM_PROMPT_ECHO_OFF: 168 case PAM_PROMPT_ECHO_OFF:
170 /* wants password */ 169 /* wants password */
171 GET_MEM; 170 GET_MEM;
172 reply[replies].resp_retcode = PAM_SUCCESS; 171 reply[replies].resp_retcode = PAM_SUCCESS;
173 reply[replies].resp = COPY_STRING(PAM_password); 172 reply[replies].resp = COPY_STRING(PAM_password);
174 replies++; 173 replies++;
175 /* PAM frees resp */ 174 /* PAM frees resp */
176 break; 175 break;
177 case PAM_TEXT_INFO: 176 case PAM_TEXT_INFO:
178 break; 177 break;
179 default: 178 default:
180 /* unknown or PAM_ERROR_MSG */ 179 /* unknown or PAM_ERROR_MSG */
181 if (reply) free (reply); 180 if (reply) free (reply);
182 return PAM_CONV_ERR; 181 return PAM_CONV_ERR;
183 } 182 }
184 } 183 }
185 if (reply) *resp = reply; 184 if (reply) *resp = reply;
186 return PAM_SUCCESS; 185 return PAM_SUCCESS;
187} 186}
188 187
189 188
190static bool pwcheck_PAM( const char *user, const char *password ) 189static bool pwcheck_PAM( const char *user, const char *password )
191{ 190{
192 bool pw_correct = false; 191 bool pw_correct = false;
193 int pam_error; 192 int pam_error;
194 int pam_return = 0; 193 int pam_return = 0;
195 pam_handle_t *pamh = 0; 194 pam_handle_t *pamh = 0;
196 PAM_password = password; 195 PAM_password = password;
197 196
198 pam_error = pam_start( _PAM_SERVICE, user, &PAM_conversation, &pamh ); 197 pam_error = pam_start( _PAM_SERVICE, user, &PAM_conversation, &pamh );
199 if( pam_error == PAM_SUCCESS ) { 198 if( pam_error == PAM_SUCCESS ) {
200 pam_error = pam_authenticate( pamh, 0 ); 199 pam_error = pam_authenticate( pamh, 0 );
201 if( pam_error == PAM_SUCCESS ) { 200 if( pam_error == PAM_SUCCESS ) {
202 //-- password correct 201 //-- password correct
203 pw_correct = true; 202 pw_correct = true;
204 pam_return = PAM_SUCCESS; 203 pam_return = PAM_SUCCESS;
205 } else { 204 } else {
206 pam_return = pam_error; 205 pam_return = pam_error;
207 } 206 }
208 } else { 207 } else {
209 // cerr << "PAM error: " << pam_strerror( pamh, pam_error ) << endl; 208 // cerr << "PAM error: " << pam_strerror( pamh, pam_error ) << endl;
210 } 209 }
211 pam_end( pamh, pam_return ); 210 pam_end( pamh, pam_return );
212 return pw_correct; 211 return pw_correct;
213} 212}
214 213
215#else 214#else
216 215
217//---------------------------------------------------------------------------- 216//----------------------------------------------------------------------------
218 217
219static bool pwcheck_Unix( const char *user, const char *pass ) 218static bool pwcheck_Unix( const char *user, const char *pass )
220{ 219{
221 char *encrypted, *correct; 220 char *encrypted, *correct;
222 struct passwd *pw; 221 struct passwd *pw;
223 222
224 if ( !user || !pass ) 223 if ( !user || !pass )
225 return false; 224 return false;
226 225
227 pw = getpwnam ( user ); 226 pw = getpwnam ( user );
228 227
229 if ( !pw ) 228 if ( !pw )
230 return false; 229 return false;
231 230
232 if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) { 231 if (( strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
233 struct spwd *sp = getspnam ( pw-> pw_name ); 232 struct spwd *sp = getspnam ( pw-> pw_name );
234 233
235 if ( !sp ) 234 if ( !sp )
236 return false; 235 return false;
237 236
238 correct = sp-> sp_pwdp; 237 correct = sp-> sp_pwdp;
239 } 238 }
240 else 239 else
241 correct = pw-> pw_passwd; 240 correct = pw-> pw_passwd;
242 241
243 if ( correct == 0 || correct[0] == '\0' ) 242 if ( correct == 0 || correct[0] == '\0' )
244 return true; 243 return true;
245 244
246 encrypted = crypt ( pass, correct ); 245 encrypted = crypt ( pass, correct );
247 return ( strcmp ( encrypted, correct ) == 0 ); 246 return ( strcmp ( encrypted, correct ) == 0 );
248} 247}
249 248
250#endif 249#endif
251 250
252 251
253bool LoginWindowImpl::changeIdentity ( const char *user ) 252bool LoginWindowImpl::changeIdentity ( const char *user )
254{ 253{
255 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; 254 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin";
256 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; 255 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin";
257 256
258 bool fail = false; 257 bool fail = false;
259 struct passwd *pw = getpwnam ( user ); 258 struct passwd *pw = getpwnam ( user );
260 259
261 fail |= ( pw == 0 ); 260 fail |= ( pw == 0 );
262 printf ( "1 %d\n", fail ); 261 printf ( "1 %d\n", fail );
263 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid )); 262 fail |= ( initgroups ( pw-> pw_name, pw-> pw_gid ));
264 endgrent ( ); 263 endgrent ( );
265 printf ( "2 %d\n", fail ); 264 printf ( "2 %d\n", fail );
266 fail |= ( setgid ( pw-> pw_gid )); 265 fail |= ( setgid ( pw-> pw_gid ));
267 printf ( "3 %d\n", fail ); 266 printf ( "3 %d\n", fail );
268 fail |= ( setuid ( pw-> pw_uid )); 267 fail |= ( setuid ( pw-> pw_uid ));
269 268
270 printf ( "4 %d\n", fail ); 269 printf ( "4 %d\n", fail );
271 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" )); 270 fail |= ( chdir ( pw-> pw_dir ) && chdir ( "/" ));
272 271
273 printf ( "5 %d\n", fail ); 272 printf ( "5 %d\n", fail );
274 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 )); 273 fail |= ( setenv ( "HOME", pw-> pw_dir, 1 ));
275 printf ( "6 %d\n", fail ); 274 printf ( "6 %d\n", fail );
276 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 )); 275 fail |= ( setenv ( "SHELL", pw-> pw_shell, 1 ));
277 printf ( "7 %d\n", fail ); 276 printf ( "7 %d\n", fail );
278 fail |= ( setenv ( "USER", pw-> pw_name, 1 )); 277 fail |= ( setenv ( "USER", pw-> pw_name, 1 ));
279 printf ( "8 %d\n", fail ); 278 printf ( "8 %d\n", fail );
280 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 )); 279 fail |= ( setenv ( "LOGNAME", pw-> pw_name, 1 ));
281 printf ( "9 %d\n", fail ); 280 printf ( "9 %d\n", fail );
282 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); 281 fail |= ( setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 ));
283 printf ( "10 %d\n", fail ); 282 printf ( "10 %d\n", fail );
284 283
285 return !fail; 284 return !fail;
286} 285}
287 286
288void LoginWindowImpl::login ( ) 287void LoginWindowImpl::login ( )
289{ 288{
290 const char *user = strdup ( m_user-> currentText ( ). local8Bit ( )); 289 const char *user = strdup ( m_user-> currentText ( ). local8Bit ( ));
291 const char *pass = strdup ( m_password-> text ( ). local8Bit ( )); 290 const char *pass = strdup ( m_password-> text ( ). local8Bit ( ));
292 bool ok; 291 bool ok;
293 292
294 if ( !user || !user [0] ) 293 if ( !user || !user [0] )
295 return; 294 return;
296 if ( !pass ) 295 if ( !pass )
297 pass = ""; 296 pass = "";
298 297
299#if defined( USEPAM ) 298#if defined( USEPAM )
300 ok = pwcheck_PAM ( user, pass ); 299 ok = pwcheck_PAM ( user, pass );
301#else 300#else
302 ok = pwcheck_Unix ( user, pass ); 301 ok = pwcheck_Unix ( user, pass );
303#endif 302#endif
304 303
305 if ( ok ) { 304 if ( ok ) {
306 if ( changeIdentity ( user )) { 305 if ( changeIdentity ( user )) {
307 QString opie = getenv ( "OPIEDIR" ); 306 QString opie = getenv ( "OPIEDIR" );
308 opie += "/bin/qpe"; 307 opie += "/bin/qpe";
309 308
310 execl ( opie. latin1 ( ), "qpe", 0 ); 309 execl ( opie. latin1 ( ), "qpe", 0 );
311 310
312 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE." )); 311 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not start OPIE." ));
313 restart ( ); 312 restart ( );
314 } 313 }
315 else { 314 else {
316 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" )); 315 QMessageBox::critical ( this, tr( "Failure" ), tr( "Could not switch to new user identity" ));
317 restart ( ); 316 restart ( );
318 } 317 }
319 } 318 }
320 else { 319 else {
321 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." )); 320 QMessageBox::warning ( this, tr( "Wrong password" ), tr( "The given password is incorrect." ));
322 m_password-> clear ( ); 321 m_password-> clear ( );
323 } 322 }
324} 323}
diff --git a/core/opie-login/opie-login.pro b/core/opie-login/opie-login.pro
index ef449ab..35c1ed0 100644
--- a/core/opie-login/opie-login.pro
+++ b/core/opie-login/opie-login.pro
@@ -1,25 +1,25 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on debug usepam 2CONFIG = qt warn_on debug usepam
3 3
4HEADERS = loginwindowimpl.h \ 4HEADERS = loginwindowimpl.h \
5 ../launcher/inputmethods.h \ 5 ../launcher/inputmethods.h \
6 ../apps/calibrate/calibrate.h 6 ../apps/calibrate/calibrate.h
7 7
8SOURCES = loginwindowimpl.cpp \ 8SOURCES = loginwindowimpl.cpp \
9 ../launcher/inputmethods.cpp \ 9 ../launcher/inputmethods.cpp \
10 ../apps/calibrate/calibrate.cpp \ 10 ../apps/calibrate/calibrate.cpp \
11 main.cpp 11 main.cpp
12 12
13INTERFACES = loginwindow.ui 13INTERFACES = loginwindow.ui
14 14
15INCLUDEPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate 15INCLUDEPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate
16DEPENDPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate 16DEPENDPATH += $(OPIEDIR)/include ../launcher ../apps/calibrate
17 17
18LIBS += -lqpe -lopie 18LIBS += -lqpe -lopie
19 19
20#usepam:LIBS += -lpam 20usepam:LIBS += -lpam
21#usepam:DEFINES += USEPAM 21usepam:DEFINES += USEPAM
22 22
23DESTDIR = $(OPIEDIR)/bin 23DESTDIR = $(OPIEDIR)/bin
24TARGET = opie-login 24TARGET = opie-login
25 25