sfakeroot.h (2370B)
1 /* sfakeroot 2 * 3 * Copyright © 2020 - 2025 Richard Ipsum 4 * 5 * This file is part of sfakeroot. 6 * 7 * sfakeroot is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, version 3 of the License. 10 * 11 * sfakeroot is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with sfakeroot. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 22 #include <stdarg.h> 23 #include <stdbool.h> 24 #include <sys/stat.h> 25 26 #define SOCK_PATH ".sfakeroot_socket" 27 #define MAX_PATHLEN 8192 28 29 #if defined(HAVE_STATX) && HAVE_STATX && defined(__linux__) 30 #define USE_STATX 1 31 #else 32 #define USE_STATX 0 33 #endif 34 35 static void debug(const char *fmt, ...) 36 { 37 #ifdef DEBUG 38 va_list ap; 39 va_start(ap, fmt); 40 vfprintf(stderr, fmt, ap); 41 va_end(ap); 42 //puts((USE_STATX == 1) ? "STATX ENABLED" : "STATX DISABLED"); 43 #else 44 (void) fmt; 45 #endif 46 } 47 48 struct sfakeroot_ent { 49 struct stat st; 50 struct sfakeroot_ent *next; 51 bool stale; 52 }; 53 54 enum sfakeroot_msg_type { 55 SFAKEROOT_MSG_STAT, 56 SFAKEROOT_MSG_LSTAT, 57 SFAKEROOT_MSG_FSTAT, 58 SFAKEROOT_MSG_FSTATAT, 59 SFAKEROOT_MSG_CHOWN, 60 SFAKEROOT_MSG_LCHOWN, 61 SFAKEROOT_MSG_FCHOWN, 62 SFAKEROOT_MSG_FCHOWNAT, 63 SFAKEROOT_MSG_CHMOD, 64 SFAKEROOT_MSG_FINISH, 65 SFAKEROOT_MSG_STATX 66 }; 67 68 struct sfakeroot_msg { 69 /* message type */ 70 enum sfakeroot_msg_type type; 71 72 /* current working directory of client process */ 73 char working_dir[MAX_PATHLEN]; 74 75 /* system call parameters */ 76 char path[MAX_PATHLEN]; 77 int fd; 78 int flag; 79 unsigned int mask; 80 struct stat st; 81 uid_t uid; 82 gid_t gid; 83 mode_t mode; 84 85 /* system call return data */ 86 int retcode; 87 int reterrno; 88 89 #if USE_STATX 90 struct statx statxbuf; 91 #endif 92 }; 93 94 int sfakeroot_recvmsg(int fd, struct sfakeroot_msg *m); 95 int sfakeroot_sendmsg(int fd, struct sfakeroot_msg *m, int send_fds[], int send_fds_len); 96 97 int sfakeroot_stat(const char *path, struct stat *s, bool lstat); 98 bool sfakeroot_daemon_running(void); 99 100 size_t strlcpy(char *, const char *, size_t);