Module Name: src Committed By: manu Date: Tue Sep 7 02:11:04 UTC 2010
Modified Files: src/lib/libperfuse: ops.c perfuse.c perfuse_if.h src/usr.sbin/perfused: msg.c perfused.c Log Message: - Do not checkfor peer credentials when perfused is autostarted and therefore runs with filesystem privileges - shut up warnings and debug messages when perfused is autostarted - make perfused patch modifiable with CFLAGS for easier pkgsrc integration - Fix build warnings To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/lib/libperfuse/ops.c cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/perfuse.c cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/perfuse_if.h cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/perfused/msg.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/perfused/perfused.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libperfuse/ops.c diff -u src/lib/libperfuse/ops.c:1.11 src/lib/libperfuse/ops.c:1.12 --- src/lib/libperfuse/ops.c:1.11 Mon Sep 6 01:40:24 2010 +++ src/lib/libperfuse/ops.c Tue Sep 7 02:11:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ops.c,v 1.11 2010/09/06 01:40:24 manu Exp $ */ +/* $NetBSD: ops.c,v 1.12 2010/09/07 02:11:04 manu Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -41,6 +41,8 @@ #include "perfuse_priv.h" #include "fuse.h" +extern int perfuse_diagflags; + static int node_close_common(struct puffs_usermount *, puffs_cookie_t, int); static int no_access(puffs_cookie_t, const struct puffs_cred *, mode_t); static void fuse_attr_to_vap(struct perfuse_state *, Index: src/lib/libperfuse/perfuse.c diff -u src/lib/libperfuse/perfuse.c:1.4 src/lib/libperfuse/perfuse.c:1.5 --- src/lib/libperfuse/perfuse.c:1.4 Mon Sep 6 01:40:24 2010 +++ src/lib/libperfuse/perfuse.c Tue Sep 7 02:11:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: perfuse.c,v 1.4 2010/09/06 01:40:24 manu Exp $ */ +/* $NetBSD: perfuse.c,v 1.5 2010/09/07 02:11:04 manu Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -115,8 +115,7 @@ if ((sv[0] = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) { #ifdef PERFUSE_DEBUG - printf("%s:%d socket failed: %s\n", - __func__, __LINE__, strerror(errno)); + DWARN("%s:%d socket failed: %s", __func__, __LINE__); #endif return -1; } @@ -138,8 +137,7 @@ */ if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) != 0) { #ifdef PERFUSE_DEBUG - printf("%s:%d: socketpair failed: %s\n", - __func__, __LINE__, strerror(errno)); + DWARN("%s:%d: socketpair failed", __func__, __LINE__); #endif return -1; } @@ -149,8 +147,7 @@ switch(fork()) { case -1: #ifdef PERFUSE_DEBUG - printf("%s:%d: fork failed: %s\n", - __func__, __LINE__, strerror(errno)); + DWARN("%s:%d: fork failed", __func__, __LINE__); #endif return -1; /* NOTREACHED */ @@ -158,8 +155,7 @@ case 0: (void)execve(argv[0], argv, envp); #ifdef PERFUSE_DEBUG - printf("%s:%d: execve failed: %s\n", - __func__, __LINE__, strerror(errno)); + DWARN("%s:%d: execve failed", __func__, __LINE__); #endif return -1; /* NOTREACHED */ @@ -181,32 +177,19 @@ const void *data; { int s; -#if 0 - struct sockaddr_un sun; -#endif size_t len; struct perfuse_mount_out pmo; #ifdef PERFUSE_DEBUG - printf("%s(\"%s\", \"%s\", \"%s\", 0x%lx, \"%s\")\n", __func__, - source, target, filesystemtype, mountflags, (const char *)data); + if (perfuse_diagflags & PDF_MISC) + DPRINTF("%s(\"%s\", \"%s\", \"%s\", 0x%lx, \"%s\")\n", + __func__, source, target, filesystemtype, + mountflags, (const char *)data); #endif -#if 0 - if ((s = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) - err(EX_OSERR, "socket failed"); - - sun.sun_len = sizeof(sun); - sun.sun_family = AF_LOCAL; - (void)strcpy(sun.sun_path, _PATH_FUSE); - - if (connect(s, (struct sockaddr *)&sun, sun.sun_len) == -1) - err(EX_UNAVAILABLE, "cannot connect to \"%s\"", _PATH_FUSE); -#endif if ((s = get_fd(data)) == -1) return -1; - pmo.pmo_len = sizeof(pmo); pmo.pmo_len += source ? (uint32_t)strlen(source) : 0; pmo.pmo_len += target ? (uint32_t)strlen(target) : 0; @@ -226,7 +209,8 @@ if (write(s, &pmo, sizeof(pmo)) != sizeof(pmo)) { #ifdef PERFUSE_DEBUG - printf("%s:%d short write\n", __func__, __LINE__); + if (perfuse_diagflags & PDF_MISC) + DPRINTF("%s:%d short write\n", __func__, __LINE__); #endif return -1; } @@ -235,7 +219,7 @@ len = pmo.pmo_source_len; if (write(s, source, len) != (ssize_t)len) { #ifdef PERFUSE_DEBUG - printf("%s:%d short write\n", __func__, __LINE__); + DWARNX("%s:%d short write\n", __func__, __LINE__); #endif return -1; } @@ -245,7 +229,7 @@ len = pmo.pmo_target_len; if (write(s, target, len) != (ssize_t)len) { #ifdef PERFUSE_DEBUG - printf("%s:%d short write\n", __func__, __LINE__); + DWARNX("%s:%d short write\n", __func__, __LINE__); #endif return -1; } @@ -255,7 +239,7 @@ len = pmo.pmo_filesystemtype_len; if (write(s, filesystemtype, len) != (ssize_t)len) { #ifdef PERFUSE_DEBUG - printf("%s:%d short write\n", __func__, __LINE__); + DWARNX("%s:%d short write\n", __func__, __LINE__); #endif return -1; } @@ -265,7 +249,7 @@ len = pmo.pmo_data_len; if (write(s, data, len) != (ssize_t)len) { #ifdef PERFUSE_DEBUG - printf("%s:%d short write\n", __func__, __LINE__); + DWARNX("%s:%d short write\n", __func__, __LINE__); #endif return -1; } Index: src/lib/libperfuse/perfuse_if.h diff -u src/lib/libperfuse/perfuse_if.h:1.6 src/lib/libperfuse/perfuse_if.h:1.7 --- src/lib/libperfuse/perfuse_if.h:1.6 Mon Sep 6 01:40:24 2010 +++ src/lib/libperfuse/perfuse_if.h Tue Sep 7 02:11:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: perfuse_if.h,v 1.6 2010/09/06 01:40:24 manu Exp $ */ +/* $NetBSD: perfuse_if.h,v 1.7 2010/09/07 02:11:04 manu Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -28,8 +28,10 @@ #ifndef _REFUSE_PERFUSE_H #define _REFUSE_PERFUSE_H -#define _PATH_FUSE "/dev/fuse" +#ifndef _PATH_PERFUSED #define _PATH_PERFUSED "/usr/sbin/perfused" +#endif /* _PATH_PERFUSED */ +#define _PATH_FUSE "/dev/fuse" #define FUSE_COMMFD_ENV "_FUSE_COMMFD" #define PERFUSE_MOUNT_MAGIC "noFuseRq" #define PERFUSE_UNKNOWN_INO 0xffffffff Index: src/usr.sbin/perfused/msg.c diff -u src/usr.sbin/perfused/msg.c:1.4 src/usr.sbin/perfused/msg.c:1.5 --- src/usr.sbin/perfused/msg.c:1.4 Mon Sep 6 01:40:24 2010 +++ src/usr.sbin/perfused/msg.c Tue Sep 7 02:11:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: msg.c,v 1.4 2010/09/06 01:40:24 manu Exp $ */ +/* $NetBSD: msg.c,v 1.5 2010/09/07 02:11:04 manu Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -87,7 +87,7 @@ if ((buf = malloc(len + 1)) == NULL) err(EX_OSERR, "malloc(%zd) failed", len); - if (read(fd, buf, len) != len) { + if (read(fd, buf, len) != (ssize_t)len) { DWARN("short read"); return NULL; } Index: src/usr.sbin/perfused/perfused.c diff -u src/usr.sbin/perfused/perfused.c:1.6 src/usr.sbin/perfused/perfused.c:1.7 --- src/usr.sbin/perfused/perfused.c:1.6 Mon Sep 6 13:15:29 2010 +++ src/usr.sbin/perfused/perfused.c Tue Sep 7 02:11:04 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: perfused.c,v 1.6 2010/09/06 13:15:29 wiz Exp $ */ +/* $NetBSD: perfused.c,v 1.7 2010/09/07 02:11:04 manu Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -52,13 +52,19 @@ static int getpeerid(int, pid_t *, uid_t *, gid_t *); static int access_mount(const char *, uid_t, int); -static void new_mount(int); +static void new_mount(int, int); static int parse_debug(char *); static void siginfo_handler(int); static int parse_options(int, char **); static void get_mount_info(int, struct perfuse_mount_info *); int main(int, char **); +/* + * Flags for new_mount() + */ +#define PMNT_DEVFUSE 0x0 /* We use /dev/fuse */ +#define PMNT_SOCKPAIR 0x1 /* We use socketpair */ + static int getpeerid(s, pidp, uidp, gidp) @@ -137,12 +143,12 @@ } #ifdef PERFUSE_DEBUG - DPRINTF("perfuse lengths: source = %"PRId32", target = %"PRId32", " - "filesystemtype = %"PRId32", data = %"PRId32"\n", - pmo->pmo_source_len, - pmo->pmo_target_len, - pmo->pmo_filesystemtype_len, - pmo->pmo_data_len); + if (perfuse_diagflags & PDF_MISC) + DPRINTF("perfuse lengths: source = %"PRId32", " + "target = %"PRId32", filesystemtype = %"PRId32", " + "data = %"PRId32"\n", pmo->pmo_source_len, + pmo->pmo_target_len, pmo->pmo_filesystemtype_len, + pmo->pmo_data_len); #endif len = pmo->pmo_source_len; source = perfuse_recv_early(fd, len); @@ -159,8 +165,10 @@ data = perfuse_recv_early(fd, len); #ifdef PERFUSE_DEBUG - DPRINTF("%s(\"%s\", \"%s\", \"%s\", 0x%lx, \"%s\")\n", __func__, - source, target, filesystemtype, mountflags, (const char *)data); + if (perfuse_diagflags & PDF_MISC) + DPRINTF("%s(\"%s\", \"%s\", \"%s\", 0x%lx, \"%s\")\n", + __func__, source, target, filesystemtype, + mountflags, (const char *)data); #endif pmi->pmi_source = source; pmi->pmi_target = target; @@ -172,8 +180,9 @@ } static void -new_mount(fd) +new_mount(fd, pmnt_flags) int fd; + int pmnt_flags; { struct puffs_usermount *pu; struct perfuse_mount_info pmi; @@ -202,17 +211,24 @@ get_mount_info(fd, &pmi); /* - * Get peer identity + * Get peer identity. If we use socketpair (-i option), + * peer identity if the same as us. */ - if (getpeerid(fd, NULL, &pmi.pmi_uid, NULL) != 0) - DWARNX("Unable to retrieve peer identity"); + if (pmnt_flags & PMNT_SOCKPAIR) { + pmi.pmi_uid = getuid(); + } else { + if (getpeerid(fd, NULL, &pmi.pmi_uid, NULL) != 0) { + DWARNX("Unable to retreive peer identity"); + pmi.pmi_uid = (uid_t)-1; + } + } /* * Check that peer owns mountpoint and read (and write) on it? */ ro_flag = pmi.pmi_mountflags & MNT_RDONLY; if (access_mount(pmi.pmi_target, pmi.pmi_uid, ro_flag) != 0) - DERRX(EX_NOPERM, "insufficient privileges to mount %s", + DERRX(EX_NOPERM, "insuficient privileges to mount on %s", pmi.pmi_target); @@ -337,6 +353,7 @@ break; case 'f': foreground = 1; + perfuse_diagflags |= PDF_MISC; break; case 'i': retval = atoi(optarg); @@ -371,7 +388,7 @@ DERR(EX_OSERR, "daemon failed"); if (s != -1) { - new_mount(s); + new_mount(s, PMNT_SOCKPAIR); DERRX(EX_SOFTWARE, "new_mount exit while -i is used"); } @@ -395,7 +412,7 @@ if (perfuse_diagflags & PDF_MISC) DPRINTF("connexion accepted\n"); #endif - new_mount(fd); + new_mount(fd, PMNT_DEVFUSE); } while (1 /* CONSTCOND */); /* NOTREACHED */