Browse Source

Mark files that make use of POSIX ACLs

Přemysl Janouch 1 year ago
parent
commit
fb73fc8292
Signed by: Přemysl Janouch <p.janouch@gmail.com> GPG Key ID: B715679E3A361BE6
3 changed files with 15 additions and 4 deletions
  1. 1
    1
      CMakeLists.txt
  2. 1
    1
      Makefile
  3. 13
    2
      sdn.cpp

+ 1
- 1
CMakeLists.txt View File

@@ -20,7 +20,7 @@ pkg_check_modules (NCURSESW QUIET ncursesw)
20 20
 
21 21
 add_executable (${PROJECT_NAME} ${PROJECT_NAME}.cpp)
22 22
 target_include_directories (${PROJECT_NAME} PUBLIC ${NCURSESW_INCLUDE_DIRS})
23
-target_link_libraries (${PROJECT_NAME} PUBLIC ${NCURSESW_LIBRARIES})
23
+target_link_libraries (${PROJECT_NAME} PUBLIC ${NCURSESW_LIBRARIES} acl)
24 24
 target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_14)
25 25
 target_compile_definitions (${PROJECT_NAME} PUBLIC
26 26
 	-DPROJECT_NAME=\"${PROJECT_NAME}\" -DPROJECT_VERSION=\"${version}\")

+ 1
- 1
Makefile View File

@@ -3,7 +3,7 @@ CXXFLAGS = -g -std=c++14 -Wall -Wextra -pedantic -static-libstdc++
3 3
 
4 4
 all: sdn
5 5
 %: %.cpp CMakeLists.txt
6
-	$(CXX) $(CXXFLAGS) $< -o $@ `pkg-config --libs --cflags ncursesw` \
6
+	$(CXX) $(CXXFLAGS) $< -o $@ `pkg-config --libs --cflags ncursesw` -lacl \
7 7
 	`sed -ne 's/^project (\([^ )]*\).*/-DPROJECT_NAME="\1"/p' \
8 8
 	-e 's/^set (version \([^ )]*\).*/-DPROJECT_VERSION="\1"/p' CMakeLists.txt`
9 9
 clean:

+ 13
- 2
sdn.cpp View File

@@ -26,15 +26,18 @@
26 26
 #include <cstdlib>
27 27
 #include <fstream>
28 28
 
29
-#include <ncurses.h>
30 29
 #include <unistd.h>
31 30
 #include <dirent.h>
32 31
 #include <sys/stat.h>
33 32
 #include <sys/inotify.h>
33
+#include <sys/acl.h>
34 34
 #include <fcntl.h>
35 35
 #include <pwd.h>
36 36
 #include <grp.h>
37 37
 
38
+#include <acl/libacl.h>
39
+#include <ncurses.h>
40
+
38 41
 // Unicode is complex enough already and we might make assumptions
39 42
 #ifndef __STDC_ISO_10646__
40 43
 #error Unicode required for wchar_t
@@ -288,7 +291,15 @@ static struct {
288 291
 
289 292
 fun make_row (const string &filename, const struct stat &info) -> row {
290 293
 	row r;
291
-	r.cols[row::MODES] = apply_attrs (decode_mode (info.st_mode), 0);
294
+	auto mode = decode_mode (info.st_mode);
295
+	if (auto acl = acl_get_file (filename.c_str (), ACL_TYPE_ACCESS)) {
296
+		mode_t m;
297
+		// This is a Linux-only extension
298
+		if (!acl_equiv_mode (acl, &m) && (m ^ info.st_mode) & 0777)
299
+			mode += L"+";
300
+		acl_free (acl);
301
+	}
302
+	r.cols[row::MODES] = apply_attrs (mode, 0);
292 303
 
293 304
 	auto user = to_wstring (info.st_uid);
294 305
 	if (auto u = getpwuid (info.st_uid))

Loading…
Cancel
Save