3 int check_config(FILE *log_fp,
const char *
const file,
const int is_dir) {
6 printf(
"checking file: %s\n", file);
8 if (!
is_nlnk(log_fp, file, &st)) {
13 if (!S_ISDIR(st.st_mode)) {
14 fprintf(stderr,
"Error: %s is not a directory\n", file);
17 fprintf(log_fp,
"Error: %s is not a directory\n", file);
23 if (!S_ISREG(st.st_mode)) {
24 fprintf(stderr,
"Error: %s is not a regular file\n", file);
27 fprintf(log_fp,
"Error: %s is not a regular file\n", file);
41 int is_nlnk(FILE *log_fp,
const char *
const file,
struct stat *
const st) {
42 int exist = lstat(file, st);
44 if (exist == -1 && errno == ENOENT) {
45 fprintf(stderr,
"%s does not exist\n", file);
48 fprintf(log_fp,
"Error: %s does not exist\n", file);
53 if (S_ISLNK(st->st_mode)) {
54 fprintf(stderr,
"Error: %s is a link\n", file);
57 fprintf(log_fp,
"Error: %s is a link\n", file);
64 int check_perm(FILE *log_fp,
const char *
const file,
const struct stat *
const st,
const int is_dir) {
78 if ( ((st->st_mode >> 6) & 0x7) != perm) {
79 fprintf(stderr,
"Error: Owner type does not have %s permission set to %d\n", file, perm);
81 fprintf(log_fp,
"Error: Owner type does not have %s permission set to %d\n", file, perm);
86 if (st->st_mode & S_IWGRP) {
87 fprintf(stderr,
"Error: Group has write permission to %s\n", file);
89 fprintf(log_fp,
"Error: Group has write permission to %s\n", file);
93 if (st->st_mode & S_IWOTH) {
94 fprintf(stderr,
"Error: Other has write permission to %s\n", file);
96 fprintf(log_fp,
"Error: Other has write permission to %s\n", file);
102 if (st->st_uid != 0) {
103 fprintf(stderr,
"Error: %s is not owned by root\n", file);
105 fprintf(log_fp,
"Error: %s is not owned by root\n", file);
int is_nlnk(FILE *log_fp, const char *const file, struct stat *const st)
int check_perm(FILE *log_fp, const char *const file, const struct stat *const st, const int is_dir)
int check_config(FILE *log_fp, const char *const file, const int is_dir)
: Where security checks and security tools are placed