Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/puffs/mount_psshfs Add -u and -g, which allow to re...



details:   https://anonhg.NetBSD.org/src/rev/91c822f480f4
branches:  trunk
changeset: 750591:91c822f480f4
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Jan 07 21:05:50 2010 +0000

description:
Add -u and -g, which allow to remap one (local,remote) uidgid, i.e.
umapfs without the fuss.

diffstat:

 usr.sbin/puffs/mount_psshfs/mount_psshfs.8 |  27 +++++++++++++++++++++++++--
 usr.sbin/puffs/mount_psshfs/node.c         |  14 +++++++-------
 usr.sbin/puffs/mount_psshfs/psbuf.c        |  21 ++++++++++++++++-----
 usr.sbin/puffs/mount_psshfs/psshfs.c       |  18 ++++++++++++++----
 usr.sbin/puffs/mount_psshfs/psshfs.h       |   9 +++++++--
 usr.sbin/puffs/mount_psshfs/subr.c         |  14 +++++++++++---
 6 files changed, 80 insertions(+), 23 deletions(-)

diffs (truncated from 307 to 300 lines):

diff -r 4f7ea13b8666 -r 91c822f480f4 usr.sbin/puffs/mount_psshfs/mount_psshfs.8
--- a/usr.sbin/puffs/mount_psshfs/mount_psshfs.8        Thu Jan 07 20:47:47 2010 +0000
+++ b/usr.sbin/puffs/mount_psshfs/mount_psshfs.8        Thu Jan 07 21:05:50 2010 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mount_psshfs.8,v 1.21 2009/05/20 14:08:21 pooka Exp $
+.\"    $NetBSD: mount_psshfs.8,v 1.22 2010/01/07 21:05:50 pooka Exp $
 .\"
 .\" Copyright (c) 2007-2009 Antti Kantee.  All rights reserved.
 .\"
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 20, 2009
+.Dd Jan 7, 2010
 .Dt MOUNT_PSSHFS 8
 .Os
 .Sh NAME
@@ -88,6 +88,12 @@
 .Pa configfile
 instead of
 .Pa ~/.ssh/config .
+.It Fl g Ar manglegid
+Converts remote
+.Ar manglegid
+to the effective gid of the file server and vice versa.
+See
+.Fl u .
 .It Fl o Ar [no]option
 This flag can be used to give standard mount options and options
 to puffs.
@@ -135,6 +141,23 @@
 kernel and will lose all cached information in doing so.
 How frequently this happens depends on system activity and the total
 number of available vnodes in the system (kern.maxvnodes).
+.It Fl u Ar mangleuid
+Converts remote
+.Ar mangleuid
+to the effective uid of the file server and vice versa.
+This is a simple special case of the functionality of
+.Xr mount_umap 8 .
+For example: you mount remote me@darkmoon as the local user "me".
+If the uid of "me" on the local system is 101 and on
+darkmoon it is 202, you would use
+.Fl u
+.Ar 202
+to see files owned by 202 on darkmoon as owned by 101 when browsing the
+mount point.
+Apart from the cosmetic effect, this makes things like
+"chown me file" work.
+See
+.Fl g .
 .El
 .Sh EXAMPLES
 The following example illustrates how to mount the directory
diff -r 4f7ea13b8666 -r 91c822f480f4 usr.sbin/puffs/mount_psshfs/node.c
--- a/usr.sbin/puffs/mount_psshfs/node.c        Thu Jan 07 20:47:47 2010 +0000
+++ b/usr.sbin/puffs/mount_psshfs/node.c        Thu Jan 07 21:05:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: node.c,v 1.59 2009/11/05 13:28:18 pooka Exp $  */
+/*     $NetBSD: node.c,v 1.60 2010/01/07 21:05:50 pooka Exp $  */
 
 /*
  * Copyright (c) 2006-2009  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: node.c,v 1.59 2009/11/05 13:28:18 pooka Exp $");
+__RCSID("$NetBSD: node.c,v 1.60 2010/01/07 21:05:50 pooka Exp $");
 #endif /* !lint */
 
 #include <assert.h>
@@ -147,7 +147,7 @@
                        kludgeva.va_atime.tv_sec = va->va_mtime.tv_sec;
        }
                        
-       psbuf_put_vattr(pb, &kludgeva);
+       psbuf_put_vattr(pb, &kludgeva, pctx);
        GETRESPONSE(pb, pctx->sshfd);
 
        rv = psbuf_expect_status(pb);
@@ -172,7 +172,7 @@
        /* Create node on server first */
        psbuf_req_str(pb, SSH_FXP_OPEN, reqid, PCNPATH(pcn));
        psbuf_put_4(pb, SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC);
-       psbuf_put_vattr(pb, va);
+       psbuf_put_vattr(pb, va, pctx);
        GETRESPONSE(pb, pctx->sshfd);
        rv = psbuf_expect_handle(pb, &fhand, &fhandlen);
        if (rv)
@@ -246,7 +246,7 @@
                reqid = NEXTREQ(pctx);
                psbuf_req_str(pb, SSH_FXP_OPEN, reqid, PNPATH(pn));
                psbuf_put_4(pb, SSH_FXF_READ);
-               psbuf_put_vattr(pb, &va);
+               psbuf_put_vattr(pb, &va, pctx);
 
                if (puffs_framev_enqueue_cb(pu, pctx->sshfd_data, pb,
                    lazyopen_rresp, psn, 0) == -1) {
@@ -264,7 +264,7 @@
                reqid = NEXTREQ(pctx);
                psbuf_req_str(pb2, SSH_FXP_OPEN, reqid, PNPATH(pn));
                psbuf_put_4(pb2, SSH_FXF_WRITE);
-               psbuf_put_vattr(pb2, &va);
+               psbuf_put_vattr(pb2, &va, pctx);
 
                if (puffs_framev_enqueue_cb(pu, pctx->sshfd_data, pb2,
                    lazyopen_wresp, psn, 0) == -1) {
@@ -715,7 +715,7 @@
        struct puffs_node *pn_new;
 
        psbuf_req_str(pb, SSH_FXP_MKDIR, reqid, PCNPATH(pcn));
-       psbuf_put_vattr(pb, va);
+       psbuf_put_vattr(pb, va, pctx);
        GETRESPONSE(pb, pctx->sshfd);
 
        rv = psbuf_expect_status(pb);
diff -r 4f7ea13b8666 -r 91c822f480f4 usr.sbin/puffs/mount_psshfs/psbuf.c
--- a/usr.sbin/puffs/mount_psshfs/psbuf.c       Thu Jan 07 20:47:47 2010 +0000
+++ b/usr.sbin/puffs/mount_psshfs/psbuf.c       Thu Jan 07 21:05:50 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: psbuf.c,v 1.15 2009/11/05 13:28:20 pooka Exp $        */
+/*      $NetBSD: psbuf.c,v 1.16 2010/01/07 21:05:50 pooka Exp $        */
 
 /*
  * Copyright (c) 2006-2009  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: psbuf.c,v 1.15 2009/11/05 13:28:20 pooka Exp $");
+__RCSID("$NetBSD: psbuf.c,v 1.16 2010/01/07 21:05:50 pooka Exp $");
 #endif /* !lint */
 
 /*
@@ -256,7 +256,8 @@
 }
 
 void
-psbuf_put_vattr(struct puffs_framebuf *pb, const struct vattr *va)
+psbuf_put_vattr(struct puffs_framebuf *pb, const struct vattr *va,
+       const struct psshfs_ctx *pctx)
 {
        uint32_t flags;
        flags = 0;
@@ -275,8 +276,18 @@
        if (flags & SSH_FILEXFER_ATTR_SIZE)
                psbuf_put_8(pb, va->va_size);
        if (flags & SSH_FILEXFER_ATTR_UIDGID) {
-               psbuf_put_4(pb, va->va_uid);
-               psbuf_put_4(pb, va->va_gid);
+               uid_t theuid;
+               gid_t thegid;
+
+               theuid = va->va_uid;
+               if (pctx->domangleuid && theuid == pctx->myuid)
+                       theuid = pctx->mangleuid;
+               thegid = va->va_gid;
+               if (pctx->domanglegid && thegid == pctx->mygid)
+                       thegid = pctx->manglegid;
+
+               psbuf_put_4(pb, theuid);
+               psbuf_put_4(pb, thegid);
        }
        if (flags & SSH_FILEXFER_ATTR_PERMISSIONS)
                psbuf_put_4(pb, va->va_mode);
diff -r 4f7ea13b8666 -r 91c822f480f4 usr.sbin/puffs/mount_psshfs/psshfs.c
--- a/usr.sbin/puffs/mount_psshfs/psshfs.c      Thu Jan 07 20:47:47 2010 +0000
+++ b/usr.sbin/puffs/mount_psshfs/psshfs.c      Thu Jan 07 21:05:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: psshfs.c,v 1.55 2009/11/05 11:40:24 pooka Exp $        */
+/*     $NetBSD: psshfs.c,v 1.56 2010/01/07 21:05:50 pooka Exp $        */
 
 /*
  * Copyright (c) 2006-2009  Antti Kantee.  All Rights Reserved.
@@ -41,7 +41,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: psshfs.c,v 1.55 2009/11/05 11:40:24 pooka Exp $");
+__RCSID("$NetBSD: psshfs.c,v 1.56 2010/01/07 21:05:50 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -125,6 +125,7 @@
        if (argc < 3)
                usage();
 
+       memset(&pctx, 0, sizeof(pctx));
        mntflags = pflags = exportfs = nargs = 0;
        numconnections = 1;
        detach = 1;
@@ -135,7 +136,7 @@
        add_ssharg(&sshargs, &nargs, "-axs");
        add_ssharg(&sshargs, &nargs, "-oClearAllForwardings=yes");
 
-       while ((ch = getopt(argc, argv, "c:eF:o:O:pr:st:")) != -1) {
+       while ((ch = getopt(argc, argv, "c:eF:g:o:O:pr:st:u:")) != -1) {
                switch (ch) {
                case 'c':
                        numconnections = atoi(optarg);
@@ -153,6 +154,11 @@
                        add_ssharg(&sshargs, &nargs, "-F");
                        add_ssharg(&sshargs, &nargs, optarg);
                        break;
+               case 'g':
+                       pctx.domanglegid = 1;
+                       pctx.manglegid = atoi(optarg);
+                       pctx.mygid = getegid();
+                       break;
                case 'O':
                        add_ssharg(&sshargs, &nargs, "-o");
                        add_ssharg(&sshargs, &nargs, optarg);
@@ -177,6 +183,11 @@
                        if (refreshival < 0 && refreshival != -1)
                                errx(1, "invalid timeout %d", refreshival);
                        break;
+               case 'u':
+                       pctx.domangleuid = 1;
+                       pctx.mangleuid = atoi(optarg);
+                       pctx.myuid = geteuid();
+                       break;
                default:
                        usage();
                        /*NOTREACHED*/
@@ -222,7 +233,6 @@
        if (pu == NULL)
                err(1, "puffs_init");
 
-       memset(&pctx, 0, sizeof(pctx));
        pctx.mounttime = time(NULL);
        pctx.refreshival = refreshival;
        pctx.numconnections = numconnections;
diff -r 4f7ea13b8666 -r 91c822f480f4 usr.sbin/puffs/mount_psshfs/psshfs.h
--- a/usr.sbin/puffs/mount_psshfs/psshfs.h      Thu Jan 07 20:47:47 2010 +0000
+++ b/usr.sbin/puffs/mount_psshfs/psshfs.h      Thu Jan 07 21:05:50 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: psshfs.h,v 1.38 2009/11/05 13:28:20 pooka Exp $        */
+/*     $NetBSD: psshfs.h,v 1.39 2010/01/07 21:05:50 pooka Exp $        */
 
 /*
  * Copyright (c) 2006-2009  Antti Kantee.  All Rights Reserved.
@@ -176,6 +176,10 @@
        time_t mounttime;
 
        int refreshival;
+
+       int domangleuid, domanglegid;
+       uid_t mangleuid, myuid;
+       gid_t manglegid, mygid;
 };
 #define PSSHFD_META 0
 #define PSSHFD_DATA 1
@@ -196,7 +200,8 @@
 void   psbuf_put_8(struct puffs_framebuf *, uint64_t);
 void   psbuf_put_str(struct puffs_framebuf *, const char *);
 void   psbuf_put_data(struct puffs_framebuf *, const void *, uint32_t);
-void   psbuf_put_vattr(struct puffs_framebuf *, const struct vattr *);
+void   psbuf_put_vattr(struct puffs_framebuf *, const struct vattr *,
+                       const struct psshfs_ctx *);
 
 uint8_t                psbuf_get_type(struct puffs_framebuf *);
 uint32_t       psbuf_get_len(struct puffs_framebuf *);
diff -r 4f7ea13b8666 -r 91c822f480f4 usr.sbin/puffs/mount_psshfs/subr.c
--- a/usr.sbin/puffs/mount_psshfs/subr.c        Thu Jan 07 20:47:47 2010 +0000
+++ b/usr.sbin/puffs/mount_psshfs/subr.c        Thu Jan 07 21:05:50 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: subr.c,v 1.47 2009/11/05 13:28:20 pooka Exp $        */
+/*      $NetBSD: subr.c,v 1.48 2010/01/07 21:05:50 pooka Exp $        */
 
 /*
  * Copyright (c) 2006  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: subr.c,v 1.47 2009/11/05 13:28:20 pooka Exp $");
+__RCSID("$NetBSD: subr.c,v 1.48 2010/01/07 21:05:50 pooka Exp $");
 #endif /* !lint */
 
 #include <assert.h>
@@ -69,7 +69,9 @@
 setpnva(struct puffs_usermount *pu, struct puffs_node *pn,
        const struct vattr *vap)
 {
+       struct psshfs_ctx *pctx = puffs_getspecific(pu);
        struct psshfs_node *psn = pn->pn_data;
+       struct vattr modva;
 
        /*
         * Check if the file was modified from below us.
@@ -81,7 +83,13 @@
                    && pn->pn_va.va_type == VREG)
                        puffs_inval_pagecache_node(pu, pn);
 
-       puffs_setvattr(&pn->pn_va, vap);
+       modva = *vap;
+       if (pctx->domangleuid && modva.va_uid == pctx->mangleuid)
+               modva.va_uid = pctx->myuid;



Home | Main Index | Thread Index | Old Index