File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,28 @@ void closeFTLtoml(FILE *fp)
60
60
if (fclose (fp ) != 0 )
61
61
log_err ("Cannot close FTL's config file: %s" , strerror (errno ));
62
62
63
+ // Chown file if we are root
64
+ if (geteuid () == 0 )
65
+ {
66
+ // Get UID and GID of user with name "pihole"
67
+ struct passwd * pwd = getpwnam ("pihole" );
68
+ if (pwd == NULL )
69
+ {
70
+ log_warn ("Cannot get UID and GID of user pihole: %s" , strerror (errno ));
71
+ }
72
+ else
73
+ {
74
+ const uid_t pihole_uid = pwd -> pw_uid ;
75
+ const gid_t pihole_gid = pwd -> pw_gid ;
76
+ // Chown file to pihole user
77
+ if (chown (GLOBALTOMLPATH , pihole_uid , pihole_gid ) != 0 )
78
+ log_warn ("Cannot chown " GLOBALTOMLPATH " to pihole:pihole (%u:%u): %s" ,
79
+ (unsigned int )pihole_uid , (unsigned int )pihole_gid , strerror (errno ));
80
+ else
81
+ log_debug (DEBUG_CONFIG , "Chown-ed " GLOBALTOMLPATH " to pihole:pihole (%u:%u)" ,
82
+ (unsigned int )pihole_uid , (unsigned int )pihole_gid );
83
+ }
84
+ }
63
85
return ;
64
86
}
65
87
You can’t perform that action at this time.
0 commit comments