Browse Source

kernel: more directory permissions

K. Lange 2 years ago
parent
commit
c1dcfca920
3 changed files with 13 additions and 4 deletions
  1. 8 3
      apps/ls.c
  2. 1 1
      apps/sh.c
  3. 4 0
      kernel/sys/syscall.c

+ 8 - 3
apps/ls.c

@@ -20,6 +20,7 @@
 #include <termios.h>
 #include <time.h>
 #include <pwd.h>
+#include <errno.h>
 
 #include <sys/ioctl.h>
 #include <sys/stat.h>
@@ -417,7 +418,9 @@ int main (int argc, char * argv[]) {
 
 	if (argc == 1 || optind == argc) {
 		TRACE("no file to look up");
-		display_dir(p);
+		if (display_dir(p) == 2) {
+			fprintf(stderr, "%s: %s: %s\n", argv[0], p, strerror(errno));
+		}
 	} else {
 		list_t * files = list_create();
 		while (p) {
@@ -427,7 +430,7 @@ int main (int argc, char * argv[]) {
 			int t = lstat(p, &f->statbuf);
 
 			if (t < 0) {
-				printf("ls: cannot access %s: No such file or directory\n", p);
+				fprintf(stderr, "%s: %s: %s\n", argv[0], p, strerror(errno));
 				free(f);
 				out = 2;
 			} else {
@@ -476,7 +479,9 @@ int main (int argc, char * argv[]) {
 			if (i != 0) {
 				printf("\n");
 			}
-			display_dir(file_arr[i]->name);
+			if (display_dir(file_arr[i]->name) == 2) {
+				fprintf(stderr, "%s: %s: %s\n", argv[0], file_arr[i]->name, strerror(errno));
+			}
 		}
 	}
 

+ 1 - 1
apps/sh.c

@@ -1633,7 +1633,7 @@ uint32_t shell_cmd_cd(int argc, char * argv[]) {
 	}
 	return 0;
 cd_error:
-	fprintf(stderr, "%s: could not cd '%s': no such file or directory\n", argv[0], argv[1]);
+	fprintf(stderr, "%s: could not cd '%s': %s\n", argv[0], argv[1], strerror(errno));
 	return 1;
 }
 

+ 4 - 0
kernel/sys/syscall.c

@@ -500,6 +500,10 @@ static int sys_chdir(char * newdir) {
 			close_fs(chd);
 			return -ENOTDIR;
 		}
+		if (!has_permission(chd, 01)) {
+			close_fs(chd);
+			return -EACCES;
+		}
 		close_fs(chd);
 		free(current_process->wd_name);
 		current_process->wd_name = malloc(strlen(path) + 1);