-rw-r--r-- | core/opie-login/loginapplication.cpp | 15 |
1 files changed, 11 insertions, 4 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 | |||
@@ -4,66 +4,73 @@ | |||
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This file is free software; you can | 5 | _;:, .> :=|. This file is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This file is distributed in the hope that | 12 | .i_,=:_. -<s. This file is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
17 | ..}^=.= = ; Public License for more details. | 17 | ..}^=.= = ; Public License for more details. |
18 | ++= -. .` .: | 18 | ++= -. .` .: |
19 | : = ...= . :.=- You should have received a copy of the GNU | 19 | : = ...= . :.=- You should have received a copy of the GNU |
20 | -. .:....=;==+<; General Public License along with this file; | 20 | -. .:....=;==+<; General Public License along with this file; |
21 | -_. . . )=. = see the file COPYING. If not, write to the | 21 | -_. . . )=. = see the file COPYING. If not, write to the |
22 | -- :-=` Free Software Foundation, Inc., | 22 | -- :-=` Free Software Foundation, Inc., |
23 | 59 Temple Place - Suite 330, | 23 | 59 Temple Place - Suite 330, |
24 | Boston, MA 02111-1307, USA. | 24 | Boston, MA 02111-1307, USA. |
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> |
31 | #include <stdlib.h> | 39 | #include <stdlib.h> |
32 | #include <signal.h> | 40 | #include <signal.h> |
33 | #include <sys/stat.h> | 41 | #include <sys/stat.h> |
34 | #include <sys/wait.h> | 42 | #include <sys/wait.h> |
35 | 43 | ||
36 | #ifdef USEPAM | 44 | #ifdef USEPAM |
37 | extern "C" { | 45 | extern "C" { |
38 | #include <security/pam_appl.h> | 46 | #include <security/pam_appl.h> |
39 | } | 47 | } |
40 | #else | 48 | #else |
41 | #include <crypt.h> | 49 | #include <crypt.h> |
42 | #include <shadow.h> | 50 | #include <shadow.h> |
43 | #endif | 51 | #endif |
44 | 52 | ||
45 | #include "loginapplication.h" | ||
46 | 53 | ||
47 | LoginApplication *lApp; | 54 | LoginApplication *lApp; |
48 | 55 | ||
49 | LoginApplication::LoginApplication ( int &argc, char **argv, pid_t parentpid ) | 56 | LoginApplication::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 | ||
56 | const char *LoginApplication::s_username = 0; | 63 | const char *LoginApplication::s_username = 0; |
57 | 64 | ||
58 | #ifdef USEPAM | 65 | #ifdef USEPAM |
59 | 66 | ||
60 | const char *LoginApplication::s_pam_password = 0; | 67 | const char *LoginApplication::s_pam_password = 0; |
61 | 68 | ||
62 | int LoginApplication::pam_helper ( int num_msg, const struct pam_message **msg, struct pam_response **resp, void * ) | 69 | int 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 ) { |
@@ -141,82 +148,82 @@ bool LoginApplication::checkPassword ( const char *user, const char *pass ) | |||
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 | ||
152 | bool LoginApplication::changeIdentity ( ) | 159 | bool 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 | ||
184 | bool LoginApplication::login ( ) | 191 | bool 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 | ||
194 | void LoginApplication::logout ( ) | 201 | void 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 | ||
202 | static char *buildarg ( const char *base, const char *script ) | 209 | static 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 | ||
214 | bool LoginApplication::runRootScript ( const char *base, const char *script, const char *param ) | 221 | bool 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 | ||