提交 afb486da 编写于 作者: C chengjinsong2 提交者: cheng_jinsong

根据配置修改实际设备的权限

Signed-off-by: Nchengjinsong2 <chengjinsong2@huawei.com>
上级 5434b02f
......@@ -53,7 +53,7 @@ struct FirmwareUdevConf {
extern "C" {
#endif
void ParseUeventdConfigFile(const char *file);
void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode);
int GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode);
void ChangeSysAttributePermissions(const char *sysPath);
int ParseUeventConfig(char *buffer);
struct DeviceUdevConf *GetDeviceUdevConfByDevNode(const char *devNode);
......
......@@ -37,16 +37,39 @@
#include <policycoreutils.h>
#endif
static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid, gid_t gid, mode_t mode)
{
if (INVALIDSTRING(deviceNode)) {
return;
}
if (chown(deviceNode, uid, gid) != 0) {
INIT_LOGW("Failed to change \" %s \" owner, errno %d", deviceNode, errno);
}
if (chmod(deviceNode, mode) != 0) {
INIT_LOGW("Failed to change \" %s \" mode, errno %d", deviceNode, errno);
}
}
static void CreateSymbolLinks(const char *deviceNode, char **symLinks)
{
if (INVALIDSTRING(deviceNode) || symLinks == NULL) {
return;
}
uid_t uid = 0;
gid_t gid = 0;
mode_t mode = DEVMODE;
for (int i = 0; symLinks[i] != NULL; i++) {
const char *linkName = symLinks[i];
char linkBuf[DEVICE_FILE_SIZE] = {};
if (strstr(linkName, "/dev/block/by-name") != NULL) {
int res = GetDeviceNodePermissions(linkName, &uid, &gid, &mode);
INIT_CHECK(res != 0, AdjustDeviceNodePermissions(deviceNode, uid, gid, mode));
}
if (strncpy_s(linkBuf, DEVICE_FILE_SIZE - 1, linkName, strlen(linkName)) != EOK) {
INIT_LOGE("Failed to copy link name");
return;
......@@ -67,20 +90,6 @@ static void CreateSymbolLinks(const char *deviceNode, char **symLinks)
}
}
static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid, gid_t gid, mode_t mode)
{
if (INVALIDSTRING(deviceNode)) {
return;
}
if (chown(deviceNode, uid, gid) != 0) {
INIT_LOGW("Failed to change \" %s \" owner, errno %d", deviceNode, errno);
}
if (chmod(deviceNode, mode) != 0) {
INIT_LOGW("Failed to change \" %s \" mode, errno %d", deviceNode, errno);
}
}
#if defined(WITH_SELINUX) && !defined(__RAMDISK__)
static void SetDeviceLable(const char *path)
{
......@@ -151,7 +160,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode,
return rc;
}
GetDeviceNodePermissions(deviceNode, &uid, &gid, &mode);
(void)GetDeviceNodePermissions(deviceNode, &uid, &gid, &mode);
mode |= isBlock ? S_IFBLK : S_IFCHR;
dev_t dev = makedev(major, minor);
setegid(0);
......
......@@ -337,13 +337,14 @@ struct DeviceUdevConf *GetDeviceUdevConfByDevNode(const char *devNode)
}
}
}
return NULL;
}
void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode)
int GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_t *mode)
{
if (INVALIDSTRING(devNode)) {
return;
return -1;
}
struct ListNode *node = NULL;
......@@ -354,11 +355,11 @@ void GetDeviceNodePermissions(const char *devNode, uid_t *uid, gid_t *gid, mode_
*uid = config->uid;
*gid = config->gid;
*mode = config->mode;
break;
return 0;
}
}
}
return;
return -1;
}
void ChangeSysAttributePermissions(const char *sysPath)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册