From fcc13d72ad5794a58e81198241881ed13cf48810 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Sat, 30 Jan 2021 15:08:25 +0800 Subject: [PATCH] Improve code Signed-off-by: Jianhui Zhao --- src/file.c | 6 +++--- src/utils.c | 6 +++--- src/utils.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/file.c b/src/file.c index 0fc8e5f..474bcf9 100644 --- a/src/file.c +++ b/src/file.c @@ -192,12 +192,12 @@ bool detect_file_operation(uint8_t *buf, int len, int sid, struct file_context * memcpy(&pid, buf + 4, 4); - if (!getuid_pid(pid, &uid)) { + if (!getuid_by_pid(pid, &uid)) { kill(pid, SIGTERM); return true; } - if (!getgid_pid(pid, &gid)) { + if (!getgid_by_pid(pid, &gid)) { kill(pid, SIGTERM); return true; } @@ -228,7 +228,7 @@ bool detect_file_operation(uint8_t *buf, int len, int sid, struct file_context * send_file_control_msg(ctlfd, RTTY_FILE_MSG_REQUEST_ACCEPT, NULL, 0); memset(savepath, 0, sizeof(savepath)); - getcwd_pid(pid, savepath, sizeof(savepath) - 1); + getcwd_by_pid(pid, savepath, sizeof(savepath) - 1); strcat(savepath, "/"); ctx->uid = uid; diff --git a/src/utils.c b/src/utils.c index 3b5f3cd..af25199 100644 --- a/src/utils.c +++ b/src/utils.c @@ -160,7 +160,7 @@ struct mntent *find_mount_point(const char *name) * getcwd_pid does not append a null byte to buf. It will (silently) truncate the contents (to * a length of bufsiz characters), in case the buffer is too small to hold all of the contents. */ -ssize_t getcwd_pid(pid_t pid, char *buf, size_t bufsiz) +ssize_t getcwd_by_pid(pid_t pid, char *buf, size_t bufsiz) { char link[128]; @@ -169,7 +169,7 @@ ssize_t getcwd_pid(pid_t pid, char *buf, size_t bufsiz) return readlink(link, buf, bufsiz); } -bool getuid_pid(pid_t pid, uid_t *uid) +bool getuid_by_pid(pid_t pid, uid_t *uid) { char status[128]; char line[128]; @@ -196,7 +196,7 @@ bool getuid_pid(pid_t pid, uid_t *uid) return true; } -bool getgid_pid(pid_t pid, gid_t *gid) +bool getgid_by_pid(pid_t pid, gid_t *gid) { char status[128]; char line[128]; diff --git a/src/utils.h b/src/utils.h index 822ef7e..a1dcbdf 100644 --- a/src/utils.h +++ b/src/utils.h @@ -38,10 +38,10 @@ const char *format_size(size_t size); struct mntent *find_mount_point(const char *name); -ssize_t getcwd_pid(pid_t pid, char *buf, size_t bufsiz); +ssize_t getcwd_by_pid(pid_t pid, char *buf, size_t bufsiz); -bool getuid_pid(pid_t pid, uid_t *uid); +bool getuid_by_pid(pid_t pid, uid_t *uid); -bool getgid_pid(pid_t pid, gid_t *gid); +bool getgid_by_pid(pid_t pid, gid_t *gid); #endif