aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-03-27 23:04:42 +0000
committerRob Landley <rob@landley.net>2006-03-27 23:04:42 +0000
commitd1f8c1c1258d400610e2fa136fb15cc8dfb4ffe6 (patch)
treee1d5fc56e925feb6d3cfd984ee22809babbe44f6
parent164a5be04ebe59c9b5e0df97faa2543b8af2d7e8 (diff)
downloadbusybox-w32-d1f8c1c1258d400610e2fa136fb15cc8dfb4ffe6.tar.gz
busybox-w32-d1f8c1c1258d400610e2fa136fb15cc8dfb4ffe6.tar.bz2
busybox-w32-d1f8c1c1258d400610e2fa136fb15cc8dfb4ffe6.zip
From Jan Kiszka: This patch fixes the security labelling of the login terminal
and process... There still remains some stuff to clean up (the whole set_current_security_context() appears unnecessary complex to me), but this is now at least working.
-rw-r--r--loginutils/login.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/loginutils/login.c b/loginutils/login.c
index eadb17ddc..277fc98ee 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -79,7 +79,7 @@ int login_main(int argc, char **argv)
79 char *opt_host = 0; 79 char *opt_host = 0;
80 int alarmstarted = 0; 80 int alarmstarted = 0;
81#ifdef CONFIG_SELINUX 81#ifdef CONFIG_SELINUX
82 security_context_t stat_sid = NULL, sid = NULL, old_tty_sid=NULL, new_tty_sid=NULL; 82 security_context_t user_sid = NULL;
83#endif 83#endif
84 84
85 username[0]=0; 85 username[0]=0;
@@ -223,22 +223,19 @@ auth_ok:
223#ifdef CONFIG_SELINUX 223#ifdef CONFIG_SELINUX
224 if (is_selinux_enabled()) 224 if (is_selinux_enabled())
225 { 225 {
226 struct stat st; 226 security_context_t old_tty_sid, new_tty_sid;
227 int rc;
228 227
229 if (get_default_context(username, NULL, &sid)) 228 if (get_default_context(username, NULL, &user_sid))
230 { 229 {
231 fprintf(stderr, "Unable to get SID for %s\n", username); 230 fprintf(stderr, "Unable to get SID for %s\n", username);
232 exit(1); 231 exit(1);
233 } 232 }
234 rc = getfilecon(full_tty,&stat_sid); 233 if (getfilecon(full_tty, &old_tty_sid) < 0)
235 freecon(stat_sid);
236 if ((rc<0) || (stat(full_tty, &st)<0))
237 { 234 {
238 fprintf(stderr, "stat_secure(%.100s) failed: %.100s\n", full_tty, strerror(errno)); 235 fprintf(stderr, "getfilecon(%.100s) failed: %.100s\n", full_tty, strerror(errno));
239 return EXIT_FAILURE; 236 return EXIT_FAILURE;
240 } 237 }
241 if (security_compute_relabel (sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0) 238 if (security_compute_relabel(user_sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0)
242 { 239 {
243 fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", full_tty, strerror(errno)); 240 fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", full_tty, strerror(errno));
244 return EXIT_FAILURE; 241 return EXIT_FAILURE;
@@ -248,9 +245,6 @@ auth_ok:
248 fprintf(stderr, "chsid(%.100s, %s) failed: %.100s\n", full_tty, new_tty_sid, strerror(errno)); 245 fprintf(stderr, "chsid(%.100s, %s) failed: %.100s\n", full_tty, new_tty_sid, strerror(errno));
249 return EXIT_FAILURE; 246 return EXIT_FAILURE;
250 } 247 }
251 freecon(sid);
252 freecon(old_tty_sid);
253 freecon(new_tty_sid);
254 } 248 }
255#endif 249#endif
256 if ( !is_my_tty ( full_tty )) 250 if ( !is_my_tty ( full_tty ))
@@ -273,7 +267,9 @@ auth_ok:
273 if ( pw-> pw_uid == 0 ) 267 if ( pw-> pw_uid == 0 )
274 syslog ( LOG_INFO, "root login %s\n", fromhost ); 268 syslog ( LOG_INFO, "root login %s\n", fromhost );
275#ifdef CONFIG_SELINUX 269#ifdef CONFIG_SELINUX
276 set_current_security_context(sid); 270 /* well, a simple setexeccon() here would do the job as well,
271 * but let's play the game for now */
272 set_current_security_context(user_sid);
277#endif 273#endif
278 run_shell ( tmp, 1, 0, 0); /* exec the shell finally. */ 274 run_shell ( tmp, 1, 0, 0); /* exec the shell finally. */
279 275