Fazlul Shahriar avatar Fazlul Shahriar committed cc3a5ea

Coraid ssh2 support + qid fixes (Thanks Steve Simon)

Comments (0)

Files changed (6)

-CONTACT
-
-	Fazlul Shahriar <fshahriar@gmail.com>
-
-
-Installing OpenSSH (if ssh1 doesn't work)
-
-	# if you don't have the contrib tools
- 	/n/sources/contrib/fgb/root/rc/bin/contrib/install fgb/contrib
- 	
-	contrib/install fgb/openssl
-	contrib/install fgb/openssh
-
+AUTHOR		Fazlul Shahriar <fshahriar@gmail.com>
 
 BUGS
+	openssh server bugs:
+		READDIR gives 0 entries if the directory has no executable permission,
+		but is readable.
 
-	openssh server bugs:
-	
-	READDIR gives 0 entries if the directory has no executable permission,
-	but is readable.
+Small changes for ssh2 by Steve Simon, Apr 2012.
+
 typedef struct Conn Conn;
 struct Conn{
 	char	*host;
-	int		sshver;
+	char		sshver;
 	char	*serverpath;
 	Map		*map;
 	
 	dup(p[1], 1);
 	close(p[1]);
 	
-	if(conn.sshver == 1)
-		procexecl(nil, "/bin/ssh", "ssh", "-P", "-m",
-			"-I", "-f", conn.host,
-			conn.serverpath, nil);
-	else
-		procexecl(nil, "/bin/openssh/ssh",
-			"ssh", "-x", "-a", "-oClearAllForwardings=yes",
-			"-2", conn.host, "-s", "sftp", nil);
+	switch(conn.sshver){
+	case '1':
+		procexecl(nil, "/bin/ssh1", "ssh1", "-P", "-m", "-I", "-f",
+			conn.host, conn.serverpath, nil);
+		break;
+	case '2':
+		procexecl(nil, "/bin/ssh", "ssh", "-m", "-i", "-C", "-s", "sftp", conn.host, nil);
+		break;
+	case 'o':
+		procexecl(nil, "/bin/openssh/ssh", "ssh", "-x", "-a",
+			"-oClearAllForwardings=yes", "-2", conn.host, "-s", "sftp", nil);
+		break;
+	}
 	sysfatal("exec ssh: %r");
 }
 
 		if(readn(fd, buf, 4) != 4)
 			goto sendreply;
 		get4(&n, buf);
+		if(n >= sizeof(conn.buf))
+			sysfatal("reply silly big (%d > %d)\n", n, sizeof(conn.buf));
 		if(debug)
 			fprint(2, "response length: %d\n", n);
 		if(readn(fd, buf+4, n) != n)
 }
 
 int
-fxpinit(char *host, int ver, char *path)
+fxpinit(char *host, char ver, char *path)
 {
 	int *p, n;
 	
 	uchar	*s;
 };
 
-extern	int	fxpinit(char*,int,char*);
+extern	int	fxpinit(char*,char,char*);
 extern	void	fxpterm(void);
 extern	FHandle*	fxpopendir(char*);
 extern	int	fxpclose(FHandle*);
 
 install:V:
 	cp $TARG.man /sys/man/4/$TARG
+
+dist:V:
+	mk nuke
+	@{cd ..; tar cv sftpfs | bzip2 > /n/sources/contrib/steve/sftpfs.tbz }
 	int	ndir;
 };
 
-static Rune*
-utf2runes(char *utf)
-{
-	int nr, i;
-	Rune *r;
-	char *s;
-	
-	nr = utflen(utf)+1;
-	r = emalloc9p(nr*sizeof(Rune));
-	s = utf;
-	for(i = 0; i < nr; i++)
-		s += chartorune(&r[i], s);
-	r[nr-1] = 0;
-	return r;
-}
+static ulong Seed;
 
 /*
  * http://9fans.net/archive/2003/05/56
  * http://9fans.net/archive/2003/05/57
  */
 static uvlong
-hash(Rune *p, ulong seed)
+hash(char *p, char *n, ulong seed)
 {
 	ulong x;
 	uvlong xx;
 	x = seed;
 	while(*p)
 		x = x*1103515245 + 12345 + *p++;
+	if(n){
+		x = x*1103515245 + 12345 + '/';		/* for neatness only */
+		while(*n)
+			x = x*1103515245 + 12345 + *n++;
+	}
 	xx = x;
 	xx <<= 32;
 	xx |= seed;
 }
 
 static Qid
-getqid(char *path, Dir *d)
+getqid(char *path, char *name, Dir *d)
 {
-	char *p;
-	Rune *r;
 	Qid q;
 	
-	path = estrdup9p(path);
-	p = cleanname(path);
-	r = utf2runes(p);
-	free(path);
-	/* this isn't quiet right.
-		path shouldn't change on every modification */
-	q.path = hash(r, d->mtime);
-	free(r);
+	q.path = hash(path, name, Seed);
 	q.type = d->mode&DMDIR ? QTDIR : QTFILE;
 	q.vers = d->mtime;
 	return q;
 		responderror(r);
 		return;
 	}
-	r->fid->qid = getqid("/", d);
+	r->fid->qid = getqid("/", "", d);
 	freedir(d);
 	r->ofcall.qid = r->fid->qid;
 	fa = newfaux("/");
 	d = fxpstat1(fa->path, &err);
 	if(d == nil)
 		return err;
-	fid->qid = getqid(fa->path, d);
+	fid->qid = getqid(fa->path, "", d);
 	*qid = fid->qid;
 	freedir(d);
 	
 		responderror(r);
 		return;
 	}
-	r->fid->qid = getqid(fa->path, d);
+	r->fid->qid = getqid(fa->path, "", d);
 	freedir(d);
 	r->ofcall.qid = r->fid->qid;
 	r->fid->aux = fa;
 	if(n >= fa->ndir)
 		return -1;
 	e = fa->dir[n];
-	d->qid = getqid(fa->path, e);
+	d->qid = getqid(fa->path, e->name, e);
 	d->mode = e->mode;
 	d->atime = e->atime;
 	d->mtime = e->mtime;
 		responderror(r);
 		return;
 	}
-	r->d.qid = getqid(fa->path, d);
+	r->d.qid = getqid(fa->path, "", d);
 	r->d.mode = d->mode;
 	r->d.atime = d->atime;
 	r->d.mtime = d->mtime;
 void
 usage(void)
 {
-	fprint(2, "usage: sftpfs [-1DU] [-m mountpoint] [-p serverpath ] [-s srvname] [-u passwd group] [user@]hostname\n");
+	fprint(2, "usage: sftpfs [-12oDU] [-m mountpoint] [-p serverpath ] [-s srvname] [-u passwd group] [user@]hostname\n");
 	threadexitsall("usage");
 }
 
 static char *mntpt;
 static char *serverpath = "/usr/lib/sftp-server";
 static int bigu;
-static int sshver = 2;
+static char sshver = '2';
 
 void
 threadmain(int argc, char **argv)
 {
 	char mpath[50], ppath[50], gpath[50];
-	
+
 	ARGBEGIN{
 	default:
 		usage();
 		break;
 	case '1':
 	case '2':
-		sshver = ARGC()-'0';
+	case 'o':
+		sshver = ARGC();
 		break;
 	case 'D':
 		chatty9p++;
 		snprint(gpath, sizeof(gpath), "%s/etc/group", mntpt);
 		gfile = gpath;
 	}
+
+	/*
+	 * try to ensure two mounts of the same host get the same qids,
+	 * but two mounts of similar hosts get different ones.
+	 */
+	Seed = hash(host, nil, 0);
+
 	threadpostmountsrv(&fs, srvname, mntpt, MREPL|MCREATE);
 	
 	if(gfile != nil && pfile != nil)
 .SH SYNOPSIS
 .B sftpfs
 [
-.B -1DU
+.B -12oDU
 ] [
 .B -m
 .I mountpoint
 .BI /n/ host \fR)
 the root file tree of
 .IR host .
-
+.LP
 If the
 .B -s
 option is given, the file system is posted as
 if given.  Otherwise, login is attempted using the user name from
 .BR /dev/user .
 Authentication is entirely the reponsibility of the SSH client.
-
-If the
-.B -1
-flag is given, SSH version 1 (SSH1) is used.  Otherwise version 2 is
-used.
+.LP
+The
+.B -1 -2 -o
+flags control whether the Bell Lab's ssh client,
+Coraid's ssh client, or the OpenSSH client respectively are
+used for the session.
 .I Serverpath
 (default
 .BR /usr/lib/sftp-server )
 specifies the path of the SFTP server used in SSH1.  A path without
 slash character is looked up in the executable search path.  Some
 common places for SFTP server to live are:
-
+.LP
 .RS
 .EX
 /usr/lib/sftp-server
 /usr/lib/ssh/sftp-server
 .EE
 .RE
-
+.LP
 .I Passwd
 and
 .I group
 as the Unix password and group file. It overrides the
 .B -u
 flag.
-
+.LP
 The
 .B -D
 flag causes a transcript of the 9P conversation to be written to
 .B /sys/src/cmd/sftpfs
 .SH "SEE ALSO"
 .IR ssh (1),
+.IR ssh2 (1),
 .IR srvssh (4),
 .IR openssh (1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.