sfakeroot.h (2022B)
1 /* sfakeroot 2 * 3 * Copyright © 2020 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 <sys/stat.h> 24 25 #define SOCK_PATH ".sfakeroot_socket" 26 #define MAX_PATHLEN 8192 27 28 static void debug(const char *fmt, ...) 29 { 30 #ifdef DEBUG 31 va_list ap; 32 va_start(ap, fmt); 33 vfprintf(stderr, fmt, ap); 34 va_end(ap); 35 #else 36 (void) fmt; 37 #endif 38 } 39 40 struct sfakeroot_ent { 41 struct stat st; 42 struct sfakeroot_ent *next; 43 bool stale; 44 }; 45 46 enum sfakeroot_msg_type { 47 SFAKEROOT_MSG_STAT, 48 SFAKEROOT_MSG_LSTAT, 49 SFAKEROOT_MSG_FSTAT, 50 SFAKEROOT_MSG_FSTATAT, 51 SFAKEROOT_MSG_CHOWN, 52 SFAKEROOT_MSG_LCHOWN, 53 SFAKEROOT_MSG_FCHOWN, 54 SFAKEROOT_MSG_FCHOWNAT, 55 SFAKEROOT_MSG_CHMOD, 56 SFAKEROOT_MSG_FINISH 57 }; 58 59 struct sfakeroot_msg { 60 /* message type */ 61 enum sfakeroot_msg_type type; 62 63 /* current working directory of client process */ 64 char working_dir[MAX_PATHLEN]; 65 66 /* system call parameters */ 67 char path[MAX_PATHLEN]; 68 int fd; 69 int flag; 70 struct stat st; 71 uid_t uid; 72 gid_t gid; 73 mode_t mode; 74 75 /* system call return data */ 76 int retcode; 77 int reterrno; 78 }; 79 80 int sfakeroot_recvmsg(int fd, struct sfakeroot_msg *m); 81 int sfakeroot_sendmsg(int fd, struct sfakeroot_msg *m); 82 83 int sfakeroot_stat(const char *path, struct stat *s, bool lstat); 84 bool sfakeroot_daemon_running(void); 85 86 size_t strlcpy(char *, const char *, size_t);