1 Star 0 Fork 49

问书/systemd_bak

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
10017-fileio-introduce-warn_file_is_world_accessible.patch 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
From e4c4f0bc712e43776c4f58712f47260711607098 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Mon, 8 Apr 2019 03:48:30 +0900
Subject: [PATCH] fileio: introduce warn_file_is_world_accessible()
(cherry picked from commit fc0895034d4811e8c6b263c0d902b31535613d76)
Signed-off-by: Guorui Yu <GuoRui.Yu@linux.alibaba.com>
---
src/basic/fileio.c | 25 +++++++++++++++++++++++++
src/basic/fileio.h | 3 +++
2 files changed, 28 insertions(+)
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index cf7c92ebc7..2e74aac554 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -1797,3 +1797,28 @@ int read_line(FILE *f, size_t limit, char **ret) {
return (int) count;
}
+
+int warn_file_is_world_accessible(const char *filename, struct stat *st, const char *unit, unsigned line) {
+ struct stat _st;
+
+ if (!filename)
+ return 0;
+
+ if (!st) {
+ if (stat(filename, &_st) < 0)
+ return -errno;
+ st = &_st;
+ }
+
+ if ((st->st_mode & S_IRWXO) == 0)
+ return 0;
+
+ if (unit)
+ log_syntax(unit, LOG_WARNING, filename, line, 0,
+ "%s has %04o mode that is too permissive, please adjust the access mode.",
+ filename, st->st_mode & 07777);
+ else
+ log_warning("%s has %04o mode that is too permissive, please adjust the access mode.",
+ filename, st->st_mode & 07777);
+ return 0;
+}
diff --git a/src/basic/fileio.h b/src/basic/fileio.h
index 06649ef7e6..2c9ce4355b 100644
--- a/src/basic/fileio.h
+++ b/src/basic/fileio.h
@@ -5,6 +5,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include "macro.h"
@@ -105,3 +106,5 @@ int read_nul_string(FILE *f, char **ret);
int mkdtemp_malloc(const char *template, char **ret);
int read_line(FILE *f, size_t limit, char **ret);
+
+int warn_file_is_world_accessible(const char *filename, struct stat *st, const char *unit, unsigned line);
--
2.39.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Weisson/systemd_bak.git
git@gitee.com:Weisson/systemd_bak.git
Weisson
systemd_bak
systemd_bak
a8

搜索帮助

0d507c66 1850385 C8b1a773 1850385