aboutsummaryrefslogtreecommitdiff
path: root/coreutils/ls.c
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-05-03 06:25:50 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-05-03 06:25:50 +0000
commit406bbe0151d55bb191d8f65e9dfb4b281c3396e8 (patch)
treefe97ec71775deb1f3078c6db0cb8db554bc6b76f /coreutils/ls.c
parent6e34669c94a04dd5462996b1fdf85f7cbba02351 (diff)
downloadbusybox-w32-406bbe0151d55bb191d8f65e9dfb4b281c3396e8.tar.gz
busybox-w32-406bbe0151d55bb191d8f65e9dfb4b281c3396e8.tar.bz2
busybox-w32-406bbe0151d55bb191d8f65e9dfb4b281c3396e8.zip
A patch from Takeharu KATO to update/fix SE-Linux support.
git-svn-id: svn://busybox.net/trunk/busybox@10238 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/ls.c')
-rw-r--r--coreutils/ls.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 4e21454ce..92e150966 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -64,9 +64,7 @@ enum {
64#include <sys/sysmacros.h> /* major() and minor() */ 64#include <sys/sysmacros.h> /* major() and minor() */
65#include "busybox.h" 65#include "busybox.h"
66#ifdef CONFIG_SELINUX 66#ifdef CONFIG_SELINUX
67#include <fs_secure.h> 67#include <selinux/selinux.h> /* for is_selinux_enabled() */
68#include <flask_util.h>
69#include <ss.h>
70#endif 68#endif
71 69
72#ifdef CONFIG_FEATURE_LS_TIMESTAMPS 70#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
@@ -182,7 +180,7 @@ struct dnode { /* the basic node */
182 char *fullname; /* the dir entry name */ 180 char *fullname; /* the dir entry name */
183 struct stat dstat; /* the file stat info */ 181 struct stat dstat; /* the file stat info */
184#ifdef CONFIG_SELINUX 182#ifdef CONFIG_SELINUX
185 security_id_t sid; 183 security_context_t sid;
186#endif 184#endif
187 struct dnode *next; /* point at the next node */ 185 struct dnode *next; /* point at the next node */
188}; 186};
@@ -195,7 +193,7 @@ static int list_single(struct dnode *);
195static unsigned int all_fmt; 193static unsigned int all_fmt;
196 194
197#ifdef CONFIG_SELINUX 195#ifdef CONFIG_SELINUX
198static int is_flask_enabled_flag; 196static int selinux_enabled= 0;
199#endif 197#endif
200 198
201#ifdef CONFIG_FEATURE_AUTOWIDTH 199#ifdef CONFIG_FEATURE_AUTOWIDTH
@@ -213,18 +211,19 @@ static struct dnode *my_stat(char *fullname, char *name)
213 struct stat dstat; 211 struct stat dstat;
214 struct dnode *cur; 212 struct dnode *cur;
215#ifdef CONFIG_SELINUX 213#ifdef CONFIG_SELINUX
216 security_id_t sid; 214 security_context_t sid=NULL;
217#endif 215#endif
218 int rc; 216 int rc;
219 217
220#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS 218#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
221 if (all_fmt & FOLLOW_LINKS) { 219 if (all_fmt & FOLLOW_LINKS) {
222#ifdef CONFIG_SELINUX 220#ifdef CONFIG_SELINUX
223 if(is_flask_enabled_flag) 221 if (is_selinux_enabled()) {
224 rc = stat_secure(fullname, &dstat, &sid); 222 rc=0; /* Set the number which means success before hand. */
225 else 223 rc = getfilecon(fullname,&sid);
224 }
226#endif 225#endif
227 rc = stat(fullname, &dstat); 226 rc = stat(fullname, &dstat);
228 if(rc) 227 if(rc)
229 { 228 {
230 bb_perror_msg("%s", fullname); 229 bb_perror_msg("%s", fullname);
@@ -235,11 +234,12 @@ static struct dnode *my_stat(char *fullname, char *name)
235#endif 234#endif
236 { 235 {
237#ifdef CONFIG_SELINUX 236#ifdef CONFIG_SELINUX
238 if(is_flask_enabled_flag) 237 if (is_selinux_enabled()) {
239 rc = lstat_secure(fullname, &dstat, &sid); 238 rc=0; /* Set the number which means success before hand. */
240 else 239 rc = lgetfilecon(fullname,&sid);
240 }
241#endif 241#endif
242 rc = lstat(fullname, &dstat); 242 rc = lstat(fullname, &dstat);
243 if(rc) 243 if(rc)
244 { 244 {
245 bb_perror_msg("%s", fullname); 245 bb_perror_msg("%s", fullname);
@@ -736,12 +736,16 @@ static int list_single(struct dnode *dn)
736#ifdef CONFIG_SELINUX 736#ifdef CONFIG_SELINUX
737 case LIST_CONTEXT: 737 case LIST_CONTEXT:
738 { 738 {
739 char context[64]; 739 char context[80];
740 int len = sizeof(context); 740 int len;
741 if(security_sid_to_context(dn->sid, context, &len)) 741
742 { 742 if (dn->sid) {
743 strcpy(context, "unknown"); 743 /* I assume sid initilized with NULL */
744 len = 7; 744 len = strlen(dn->sid)+1;
745 safe_strncpy(context, dn->sid, len);
746 freecon(dn->sid);
747 }else {
748 safe_strncpy(context, "unknown",8);
745 } 749 }
746 printf("%-32s ", context); 750 printf("%-32s ", context);
747 column += MAX(33, len); 751 column += MAX(33, len);
@@ -963,10 +967,6 @@ extern int ls_main(int argc, char **argv)
963 char *terminal_width_str = NULL; 967 char *terminal_width_str = NULL;
964#endif 968#endif
965 969
966#ifdef CONFIG_SELINUX
967 is_flask_enabled_flag = is_flask_enabled();
968#endif
969
970 all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO 970 all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO
971#ifdef CONFIG_FEATURE_LS_TIMESTAMPS 971#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
972 | TIME_MOD 972 | TIME_MOD