summaryrefslogtreecommitdiff
path: root/core/opie-login
authorar <ar>2004-05-02 21:32:48 (UTC)
committer ar <ar>2004-05-02 21:32:48 (UTC)
commit0a4cac124105a5732e55cb34c6b37be75083a395 (patch) (unidiff)
tree33b4d2cab08c9b58893540b4ddee089b69fc9c61 /core/opie-login
parent109ed5f2a1cdfeb3680c9ec057a1083fcf8fab95 (diff)
downloadopie-0a4cac124105a5732e55cb34c6b37be75083a395.zip
opie-0a4cac124105a5732e55cb34c6b37be75083a395.tar.gz
opie-0a4cac124105a5732e55cb34c6b37be75083a395.tar.bz2
- convert qWarning to owarn
Diffstat (limited to 'core/opie-login') (more/less context) (ignore whitespace changes)
-rw-r--r--core/opie-login/loginapplication.cpp315
1 files changed, 161 insertions, 154 deletions
diff --git a/core/opie-login/loginapplication.cpp b/core/opie-login/loginapplication.cpp
index 1facf2d..764b24b 100644
--- a/core/opie-login/loginapplication.cpp
+++ b/core/opie-login/loginapplication.cpp
@@ -25,6 +25,14 @@
25 25
26*/ 26*/
27 27
28#include "loginapplication.h"
29
30/* OPIE */
31#include <opie2/odebug.h>
32
33/* QT */
34
35/* STD */
28#include <pwd.h> 36#include <pwd.h>
29#include <grp.h> 37#include <grp.h>
30#include <unistd.h> 38#include <unistd.h>
@@ -42,15 +50,14 @@ extern "C" {
42#include <shadow.h> 50#include <shadow.h>
43#endif 51#endif
44 52
45#include "loginapplication.h"
46 53
47LoginApplication *lApp; 54LoginApplication *lApp;
48 55
49LoginApplication::LoginApplication ( int &argc, char **argv, pid_t parentpid ) 56LoginApplication::LoginApplication ( int &argc, char **argv, pid_t parentpid )
50 : QPEApplication ( argc, argv, GuiServer ) 57 : QPEApplication ( argc, argv, GuiServer )
51{ 58{
52 lApp = this; 59 lApp = this;
53 m_parentpid = parentpid; 60 m_parentpid = parentpid;
54} 61}
55 62
56const char *LoginApplication::s_username = 0; 63const char *LoginApplication::s_username = 0;
@@ -61,221 +68,221 @@ const char *LoginApplication::s_pam_password = 0;
61 68
62int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ) 69int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * )
63{ 70{
64 int replies = 0; 71 int replies = 0;
65 struct pam_response *reply = 0; 72 struct pam_response *reply = 0;
66 int size = sizeof( struct pam_response ); 73 int size = sizeof( struct pam_response );
67 74
68 for ( int i = 0; i < num_msg; i++ ) { 75 for ( int i = 0; i < num_msg; i++ ) {
69 switch ( msg [i]-> msg_style ) { 76 switch ( msg [i]-> msg_style ) {
70 case PAM_PROMPT_ECHO_ON: // user name given to PAM already 77 case PAM_PROMPT_ECHO_ON: // user name given to PAM already
71 return PAM_CONV_ERR; 78 return PAM_CONV_ERR;
72 79
73 case PAM_PROMPT_ECHO_OFF: // wants password 80 case PAM_PROMPT_ECHO_OFF: // wants password
74 reply = (struct pam_response *) ::realloc ( reply, size ); 81 reply = (struct pam_response *) ::realloc ( reply, size );
75 if ( !reply ) 82 if ( !reply )
76 return PAM_CONV_ERR; 83 return PAM_CONV_ERR;
77 size += sizeof( struct pam_response ); 84 size += sizeof( struct pam_response );
78 85
79 reply [replies]. resp_retcode = PAM_SUCCESS; 86 reply [replies]. resp_retcode = PAM_SUCCESS;
80 reply [replies]. resp = ::strdup ( s_pam_password ); 87 reply [replies]. resp = ::strdup ( s_pam_password );
81 replies++; // PAM frees resp 88 replies++; // PAM frees resp
82 break; 89 break;
83 90
84 case PAM_TEXT_INFO: 91 case PAM_TEXT_INFO:
85 break; 92 break;
86 93
87 default: 94 default:
88 /* unknown or PAM_ERROR_MSG */ 95 /* unknown or PAM_ERROR_MSG */
89 if ( reply ) 96 if ( reply )
90 ::free ( reply ); 97 ::free ( reply );
91 return PAM_CONV_ERR; 98 return PAM_CONV_ERR;
92 } 99 }
93 } 100 }
94 if ( reply ) 101 if ( reply )
95 *resp = reply; 102 *resp = reply;
96 return PAM_SUCCESS; 103 return PAM_SUCCESS;
97} 104}
98 105
99 106
100bool LoginApplication::checkPassword ( const char *user, const char *pass ) 107bool LoginApplication::checkPassword ( const char *user, const char *pass )
101{ 108{
102 static struct pam_conv conv = { &LoginApplication::pam_helper, 0 }; 109 static struct pam_conv conv = { &LoginApplication::pam_helper, 0 };
103 110
104 int pam_error; 111 int pam_error;
105 pam_handle_t *pamh = 0; 112 pam_handle_t *pamh = 0;
106 113
107 pam_error = ::pam_start( "xdm", user, &conv, &pamh ); 114 pam_error = ::pam_start( "xdm", user, &conv, &pamh );
108 if ( pam_error == PAM_SUCCESS ) { 115 if ( pam_error == PAM_SUCCESS ) {
109 s_pam_password = pass; 116 s_pam_password = pass;
110 pam_error = ::pam_authenticate ( pamh, 0 ); 117 pam_error = ::pam_authenticate ( pamh, 0 );
111 s_pam_password = 0; 118 s_pam_password = 0;
112 } 119 }
113 ::pam_end ( pamh, pam_error ); 120 ::pam_end ( pamh, pam_error );
114 return ( pam_error == PAM_SUCCESS ); 121 return ( pam_error == PAM_SUCCESS );
115} 122}
116 123
117#else 124#else
118 125
119bool LoginApplication::checkPassword ( const char *user, const char *pass ) 126bool LoginApplication::checkPassword ( const char *user, const char *pass )
120{ 127{
121 char *encrypted, *correct; 128 char *encrypted, *correct;
122 struct passwd *pw; 129 struct passwd *pw;
123 130
124 if ( !user || !pass ) 131 if ( !user || !pass )
125 return false; 132 return false;
126 133
127 pw = ::getpwnam ( user ); 134 pw = ::getpwnam ( user );
128 135
129 if ( !pw ) 136 if ( !pw )
130 return false; 137 return false;
131 138
132 if (( ::strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( ::strcmp ( pw-> pw_passwd, "*" ) == 0 )) { 139 if (( ::strcmp ( pw-> pw_passwd, "x" ) == 0 ) || ( ::strcmp ( pw-> pw_passwd, "*" ) == 0 )) {
133 struct spwd *sp = ::getspnam ( pw-> pw_name ); 140 struct spwd *sp = ::getspnam ( pw-> pw_name );
134 141
135 if ( !sp ) 142 if ( !sp )
136 return false; 143 return false;
137 144
138 correct = sp-> sp_pwdp; 145 correct = sp-> sp_pwdp;
139 } 146 }
140 else 147 else
141 correct = pw-> pw_passwd; 148 correct = pw-> pw_passwd;
142 149
143 if ( correct == 0 || correct[0] == '\0' ) 150 if ( correct == 0 || correct[0] == '\0' )
144 return true; 151 return true;
145 152
146 encrypted = ::crypt ( pass, correct ); 153 encrypted = ::crypt ( pass, correct );
147 return ( ::strcmp ( encrypted, correct ) == 0 ); 154 return ( ::strcmp ( encrypted, correct ) == 0 );
148} 155}
149 156
150#endif 157#endif
151 158
152bool LoginApplication::changeIdentity ( ) 159bool LoginApplication::changeIdentity ( )
153{ 160{
154 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin"; 161 const char *DEFAULT_LOGIN_PATH = "/bin:/usr/bin";
155 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin"; 162 const char *DEFAULT_ROOT_LOGIN_PATH = "/usr/sbin:/bin:/usr/bin:/sbin";
156 163
157 if ( !s_username ) 164 if ( !s_username )
158 return false; 165 return false;
159 struct passwd *pw = ::getpwnam ( s_username ); 166 struct passwd *pw = ::getpwnam ( s_username );
160 if ( !pw ) 167 if ( !pw )
161 return false; 168 return false;
162 169
163 // we are still root at this point - try to run the pre-session script 170 // we are still root at this point - try to run the pre-session script
164 if ( !runRootScript ( "OPIEDIR", "share/opie-login/pre-session", s_username )) 171 if ( !runRootScript ( "OPIEDIR", "share/opie-login/pre-session", s_username ))
165 qWarning ( "failed to run $OPIEDIR/share/opie-login/pre-session" ); 172 owarn << "failed to run $OPIEDIR/share/opie-login/pre-session" << oendl;
166 173
167 bool fail = false; 174 bool fail = false;
168 fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid )); 175 fail |= ( ::initgroups ( pw-> pw_name, pw-> pw_gid ));
169 ::endgrent ( ); 176 ::endgrent ( );
170 fail |= ( ::setgid ( pw-> pw_gid )); 177 fail |= ( ::setgid ( pw-> pw_gid ));
171 fail |= ( ::setuid ( pw-> pw_uid )); 178 fail |= ( ::setuid ( pw-> pw_uid ));
172 179
173 fail |= ( ::chdir ( pw-> pw_dir ) && ::chdir ( "/" )); 180 fail |= ( ::chdir ( pw-> pw_dir ) && ::chdir ( "/" ));
174 181
175 fail |= ( ::setenv ( "HOME", pw-> pw_dir, 1 )); 182 fail |= ( ::setenv ( "HOME", pw-> pw_dir, 1 ));
176 fail |= ( ::setenv ( "SHELL", pw-> pw_shell, 1 )); 183 fail |= ( ::setenv ( "SHELL", pw-> pw_shell, 1 ));
177 fail |= ( ::setenv ( "USER", pw-> pw_name, 1 )); 184 fail |= ( ::setenv ( "USER", pw-> pw_name, 1 ));
178 fail |= ( ::setenv ( "LOGNAME", pw-> pw_name, 1 )); 185 fail |= ( ::setenv ( "LOGNAME", pw-> pw_name, 1 ));
179 fail |= ( ::setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 )); 186 fail |= ( ::setenv ( "PATH", ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ), 1 ));
180 187
181 return !fail; 188 return !fail;
182} 189}
183 190
184bool LoginApplication::login ( ) 191bool LoginApplication::login ( )
185{ 192{
186 execUserScript ( "HOME", ".opie-session" ); 193 execUserScript ( "HOME", ".opie-session" );
187 execUserScript ( "OPIEDIR", "share/opie-login/opie-session" ); 194 execUserScript ( "OPIEDIR", "share/opie-login/opie-session" );
188 execUserScript ( "OPIEDIR", "bin/qpe" ); 195 execUserScript ( "OPIEDIR", "bin/qpe" );
189 196
190 qWarning ( "failed to start an Opie session" ); 197 owarn << "failed to start an Opie session" << oendl;
191 return false; 198 return false;
192} 199}
193 200
194void LoginApplication::logout ( ) 201void LoginApplication::logout ( )
195{ 202{
196 // we are now root again - try to run the post-session script 203 // we are now root again - try to run the post-session script
197 if ( !runRootScript ( "OPIEDIR", "share/opie-login/post-session" )) 204 if ( !runRootScript ( "OPIEDIR", "share/opie-login/post-session" ))
198 qWarning ( "failed to run $OPIEDIR/scripts/post-session" ); 205 owarn << "failed to run $OPIEDIR/scripts/post-session" << oendl;
199} 206}
200 207
201 208
202static char *buildarg ( const char *base, const char *script ) 209static char *buildarg ( const char *base, const char *script )
203{ 210{
204 const char *dir = base ? ::getenv ( base ) : "/"; 211 const char *dir = base ? ::getenv ( base ) : "/";
205 char *arg = new char [::strlen ( dir ) + ::strlen ( script ) + 2]; 212 char *arg = new char [::strlen ( dir ) + ::strlen ( script ) + 2];
206 213
207 ::strcpy ( arg, dir ); 214 ::strcpy ( arg, dir );
208 ::strcat ( arg, "/" ); 215 ::strcat ( arg, "/" );
209 ::strcat ( arg, script ); 216 ::strcat ( arg, script );
210 217
211 return arg; 218 return arg;
212} 219}
213 220
214bool LoginApplication::runRootScript ( const char *base, const char *script, const char *param ) 221bool LoginApplication::runRootScript ( const char *base, const char *script, const char *param )
215{ 222{
216 bool res = false; 223 bool res = false;
217 char *arg = buildarg ( base, script ); 224 char *arg = buildarg ( base, script );
218 225
219 struct stat st; 226 struct stat st;
220 if (( ::stat ( arg, &st ) == 0 ) && ( st. st_uid == 0 )) { 227 if (( ::stat ( arg, &st ) == 0 ) && ( st. st_uid == 0 )) {
221 pid_t child = ::fork ( ); 228 pid_t child = ::fork ( );
222 229
223 if ( child == 0 ) { 230 if ( child == 0 ) {
224 ::execl ( "/bin/sh", "-sh", arg, param, 0 ); 231 ::execl ( "/bin/sh", "-sh", arg, param, 0 );
225 ::_exit ( -1 ); 232 ::_exit ( -1 );
226 } 233 }
227 else if ( child > 0 ) { 234 else if ( child > 0 ) {
228 int status = 0; 235 int status = 0;
229 236
230 while ( ::waitpid ( child, &status, 0 ) < 0 ) { } 237 while ( ::waitpid ( child, &status, 0 ) < 0 ) { }
231 res = ( WIFEXITED( status )) && ( WEXITSTATUS( status ) == 0 ); 238 res = ( WIFEXITED( status )) && ( WEXITSTATUS( status ) == 0 );
232 } 239 }
233 } 240 }
234 241
235 delete [] arg; 242 delete [] arg;
236 return res; 243 return res;
237} 244}
238 245
239void LoginApplication::execUserScript ( const char *base, const char *script ) 246void LoginApplication::execUserScript ( const char *base, const char *script )
240{ 247{
241 char *arg = buildarg ( base, script ); 248 char *arg = buildarg ( base, script );
242 249
243 struct stat st; 250 struct stat st;
244 if ( ::stat ( arg, &st ) == 0 ) { 251 if ( ::stat ( arg, &st ) == 0 ) {
245 if ( st. st_mode & S_IXUSR ) 252 if ( st. st_mode & S_IXUSR )
246 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 ); 253 ::execl ( "/bin/sh", "-sh", "-c", arg, 0 );
247 else 254 else
248 ::execl ( "/bin/sh", "-sh", arg, 0 ); 255 ::execl ( "/bin/sh", "-sh", arg, 0 );
249 } 256 }
250} 257}
251 258
252const char *LoginApplication::loginAs ( ) 259const char *LoginApplication::loginAs ( )
253{ 260{
254 return s_username; 261 return s_username;
255} 262}
256 263
257void LoginApplication::setLoginAs ( const char *name ) 264void LoginApplication::setLoginAs ( const char *name )
258{ 265{
259 s_username = name; 266 s_username = name;
260} 267}
261 268
262QStringList LoginApplication::allUsers ( ) 269QStringList LoginApplication::allUsers ( )
263{ 270{
264 struct passwd *pwd; 271 struct passwd *pwd;
265 QStringList sl; 272 QStringList sl;
266 273
267 while (( pwd = ::getpwent ( ))) { 274 while (( pwd = ::getpwent ( ))) {
268 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 )) 275 if (( pwd-> pw_uid == 0 ) || ( pwd-> pw_uid >= 500 && pwd-> pw_uid < 65534 ))
269 sl << QString ( pwd-> pw_name ); 276 sl << QString ( pwd-> pw_name );
270 } 277 }
271 278
272 ::endpwent ( ); 279 ::endpwent ( );
273 280
274 return sl; 281 return sl;
275} 282}
276 283
277void LoginApplication::quitToConsole ( ) 284void LoginApplication::quitToConsole ( )
278{ 285{
279 QPEApplication::quit ( ); 286 QPEApplication::quit ( );
280 ::kill ( m_parentpid, SIGTERM ); 287 ::kill ( m_parentpid, SIGTERM );
281} 288}