Module Name:    src
Committed By:   pooka
Date:           Thu Jan  7 21:05:50 UTC 2010

Modified Files:
        src/usr.sbin/puffs/mount_psshfs: mount_psshfs.8 node.c psbuf.c psshfs.c
            psshfs.h subr.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/puffs/mount_psshfs/mount_psshfs.8
cvs rdiff -u -r1.59 -r1.60 src/usr.sbin/puffs/mount_psshfs/node.c
cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/puffs/mount_psshfs/psbuf.c
cvs rdiff -u -r1.55 -r1.56 src/usr.sbin/puffs/mount_psshfs/psshfs.c
cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/puffs/mount_psshfs/psshfs.h
cvs rdiff -u -r1.47 -r1.48 src/usr.sbin/puffs/mount_psshfs/subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/puffs/mount_psshfs/mount_psshfs.8
diff -u src/usr.sbin/puffs/mount_psshfs/mount_psshfs.8:1.21 src/usr.sbin/puffs/mount_psshfs/mount_psshfs.8:1.22
--- src/usr.sbin/puffs/mount_psshfs/mount_psshfs.8:1.21	Wed May 20 14:08:21 2009
+++ src/usr.sbin/puffs/mount_psshfs/mount_psshfs.8	Thu Jan  7 21:05:50 2010
@@ -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 m...@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

Index: src/usr.sbin/puffs/mount_psshfs/node.c
diff -u src/usr.sbin/puffs/mount_psshfs/node.c:1.59 src/usr.sbin/puffs/mount_psshfs/node.c:1.60
--- src/usr.sbin/puffs/mount_psshfs/node.c:1.59	Thu Nov  5 13:28:18 2009
+++ src/usr.sbin/puffs/mount_psshfs/node.c	Thu Jan  7 21:05:50 2010
@@ -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);

Index: src/usr.sbin/puffs/mount_psshfs/psbuf.c
diff -u src/usr.sbin/puffs/mount_psshfs/psbuf.c:1.15 src/usr.sbin/puffs/mount_psshfs/psbuf.c:1.16
--- src/usr.sbin/puffs/mount_psshfs/psbuf.c:1.15	Thu Nov  5 13:28:20 2009
+++ src/usr.sbin/puffs/mount_psshfs/psbuf.c	Thu Jan  7 21:05:50 2010
@@ -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);

Index: src/usr.sbin/puffs/mount_psshfs/psshfs.c
diff -u src/usr.sbin/puffs/mount_psshfs/psshfs.c:1.55 src/usr.sbin/puffs/mount_psshfs/psshfs.c:1.56
--- src/usr.sbin/puffs/mount_psshfs/psshfs.c:1.55	Thu Nov  5 11:40:24 2009
+++ src/usr.sbin/puffs/mount_psshfs/psshfs.c	Thu Jan  7 21:05:50 2010
@@ -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;

Index: src/usr.sbin/puffs/mount_psshfs/psshfs.h
diff -u src/usr.sbin/puffs/mount_psshfs/psshfs.h:1.38 src/usr.sbin/puffs/mount_psshfs/psshfs.h:1.39
--- src/usr.sbin/puffs/mount_psshfs/psshfs.h:1.38	Thu Nov  5 13:28:20 2009
+++ src/usr.sbin/puffs/mount_psshfs/psshfs.h	Thu Jan  7 21:05:50 2010
@@ -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 *);

Index: src/usr.sbin/puffs/mount_psshfs/subr.c
diff -u src/usr.sbin/puffs/mount_psshfs/subr.c:1.47 src/usr.sbin/puffs/mount_psshfs/subr.c:1.48
--- src/usr.sbin/puffs/mount_psshfs/subr.c:1.47	Thu Nov  5 13:28:20 2009
+++ src/usr.sbin/puffs/mount_psshfs/subr.c	Thu Jan  7 21:05:50 2010
@@ -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;
+	if (pctx->domanglegid && modva.va_gid == pctx->manglegid)
+		modva.va_gid = pctx->mygid;
+
+	puffs_setvattr(&pn->pn_va, &modva);
 	psn->attrread = time(NULL);
 }
 

Reply via email to