|
1 | 1 | #include <dirent.h>
|
| 2 | +#include <errno.h> |
2 | 3 | #include <fcntl.h>
|
3 | 4 | #include <stdio.h>
|
4 | 5 | #include <stdlib.h>
|
@@ -39,6 +40,11 @@ const char *help_string[] = {
|
39 | 40 | "timestamp.",
|
40 | 41 | "umask {mode}: Change the umask of the current session."};
|
41 | 42 |
|
| 43 | +int set_euid_egid(int euid, int egid) { |
| 44 | + if (setegid(egid) == -1) return -1; |
| 45 | + return seteuid(euid); |
| 46 | +} |
| 47 | + |
42 | 48 | const char *get_file_type(int mode) {
|
43 | 49 | const char *file_type[] = {"named pipe (fifo)",
|
44 | 50 | "character special file",
|
@@ -199,20 +205,23 @@ int builtin_stat(char *line) {
|
199 | 205 | struct stat info;
|
200 | 206 | int ret = stat(arg, &info);
|
201 | 207 | // if (ret == -1)
|
| 208 | + char atime[N], mtime[N], ctime[N]; |
| 209 | + strftime(atime, N, "%F %T %z", localtime(&info.st_atime)); |
| 210 | + strftime(mtime, N, "%F %T %z", localtime(&info.st_mtime)); |
| 211 | + strftime(ctime, N, "%F %T %z", localtime(&info.st_ctime)); |
202 | 212 | printf(
|
203 | 213 | "\
|
204 | 214 | File: %s\n\
|
205 |
| - Size: %lld Blocks: %lld IO Block: %ld %s\n\ |
206 |
| -Device: %s Inode: %ld Links: %d\n\ |
207 |
| -Access: (%lo) Uid: (%ld) Gid: (%ld)\n\ |
208 |
| -Access: %s\ |
209 |
| -Modify: %s\ |
210 |
| -Change: %s", |
| 215 | + Size: %ld Blocks: %ld IO Block: %ld %s\n\ |
| 216 | +Device: %lxh/%lud Inode: %ld Links: %lu\n\ |
| 217 | +Access: (%u) Uid: (%5u) Gid: (%5u)\n\ |
| 218 | +Access: %s\n\ |
| 219 | +Modify: %s\n\ |
| 220 | +Change: %s\n", |
211 | 221 | arg, info.st_size, info.st_blocks, info.st_blksize,
|
212 |
| - get_file_type(info.st_mode & S_IFMT), |
213 |
| - "", // info.st_dev, |
| 222 | + get_file_type(info.st_mode & S_IFMT), info.st_dev, info.st_dev, |
214 | 223 | info.st_ino, info.st_nlink, info.st_mode & 0777, info.st_uid, info.st_gid,
|
215 |
| - ctime(&info.st_atime), ctime(&info.st_mtime), ctime(&info.st_ctime)); |
| 224 | + atime, mtime, ctime); |
216 | 225 | return 0;
|
217 | 226 | }
|
218 | 227 |
|
|
0 commit comments