Found 79397 results in 2673 files, showing top 50 files (show more).
go.googlesource.com/crypto:ssh/knownhosts/knownhosts.go: [ master, ]
31: type addr struct{ host, port string }
509: func hashHost(hostname string, salt []byte) []byte {
517: 	hash []byte
45: type hostPattern struct {
59: type hostPatterns []hostPattern
127: type hostKeyDB struct {
466: func HashHostname(hostname string) string {
479: func decodeHash(encoded string) (hashType string, salt, hash []byte, err error) {
500: func encodeHash(typ string, salt []byte, hash []byte) string {
515: type hashedHost struct {
522: func newHashedHost(encoded string) (*hashedHost, error) {
520: const sha1HashType = "1"
8: package knownhosts
133: func newHostKeyDB() *hostKeyDB {
146: func (db *hostKeyDB) IsHostAuthority(remote ssh.PublicKey, address string) bool {
249: func newHostnameMatcher(pattern string) (matcher, error) {
6: // host key database, and provides utility functions for writing
24: 	"golang.org/x/crypto/ssh"
28: // (http://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT) for
34: 	h := a.host
110: 	return wildcardMatch([]byte(p.addr.host), []byte(a.host)) && p.addr.port == a.port
119: func serialize(k ssh.PublicKey) string {
141: func keyEq(a, b ssh.PublicKey) bool {
145: // IsAuthorityForHost can be used as a callback in ssh.CertChecker
151: 	a := addr{host: h, port: p}
161: // IsRevoked can be used as a callback in ssh.CertChecker
162: func (db *hostKeyDB) IsRevoked(key *ssh.Certificate) bool {
179: func parseLine(line []byte) (marker, host string, key ssh.PublicKey, err error) {
185: 	host, line = nextWord(line)
187: 		return "", "", nil, errors.New("knownhosts: missing host pattern")
202: 	key, err = ssh.ParsePublicKey(keyBytes)
207: 	return marker, host, key, nil
269: 			a.host, a.port, err = net.SplitHostPort(p)
274: 			a.host, a.port, err = net.SplitHostPort(p)
276: 				a.host = p
290: 	Key      ssh.PublicKey
299: // KeyError is returned if we did not find the key in the host key
304: 	// Want holds the accepted host keys. For each key algorithm,
305: 	// there can be one hostkey.  If Want is empty, the host is
327: // check checks a key against the host database. This should not be
329: func (db *hostKeyDB) check(address string, remote net.Addr, remoteKey ssh.PublicKey) error {
334: 	host, port, err := net.SplitHostPort(remote.String())
339: 	hostToCheck := addr{host, port}
342: 		host, port, err := net.SplitHostPort(address)
347: 		hostToCheck = addr{host, port}
356: func (db *hostKeyDB) checkAddr(a addr, remoteKey ssh.PublicKey) error {
377: 	// Unknown remote host.
382: 	// If the remote host starts using a different, unknown key type, we
411: // New creates a host key callback from the given OpenSSH host key
413: // ssh.ClientConfig.HostKeyCallback. By preference, the key check
415: // IP address, the host key check will still succeed, even though a
417: func New(files ...string) (ssh.HostKeyCallback, error) {
430: 	var certChecker ssh.CertChecker
440: 	host, port, err := net.SplitHostPort(address)
442: 		host = address
445: 	entry := host
448: 	} else if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
455: func Line(addresses []string, key ssh.PublicKey) string {
475: 	hash := hashHost(hostname, salt)
476: 	return encodeHash(sha1HashType, salt, hash)
481: 		err = errors.New("knownhosts: hashed host must start with '|'")
494: 	if hash, err = base64.StdEncoding.DecodeString(components[3]); err != nil {
504: 		base64.StdEncoding.EncodeToString(hash),
523: 	typ, salt, hash, err := decodeHash(encoded)
532: 		return nil, fmt.Errorf("knownhosts: got hash type %s, must be '1'", typ)
535: 	return &hashedHost{salt: salt, hash: hash}, nil
539: 	return bytes.Equal(hashHost(Normalize(a.String()), h.salt), h.hash)
5: // Package knownhosts implements a parser for the OpenSSH known_hosts
7: // OpenSSH compliant known_hosts files.
27: // See the sshd manpage
50: func (p *hostPattern) String() string {
61: func (ps hostPatterns) match(a addr) bool {
76: // https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/addrmatch.c
109: func (p *hostPattern) match(a addr) bool {
134: 	db := &hostKeyDB{
210: func (db *hostKeyDB) parseLine(line []byte, filename string, linenum int) error {
236: 		entry.matcher, err = newHashedHost(pattern)
250: 	var hps hostPatterns
264: 			return nil, errors.New("knownhosts: negation without following hostname")
280: 		hps = append(hps, hostPattern{
288: // KnownKey represents a key declared in a known_hosts file.
341: 		// Give preference to the hostname if available.
350: 	return db.checkAddr(hostToCheck, remoteKey)
355: // or only the hostname, then this still succeeds.
359: 	// hostname?
392: func (db *hostKeyDB) Read(r io.Reader, filename string) error {
414: // operates on the hostname if available, i.e. if a server changes its
433: 	certChecker.HostKeyFallback = db.check
438: // Normalize normalizes an address into the form used in known_hosts
454: // Line returns a line to add append to the known_hosts files.
464: // HashHostname hashes the given hostname. The hostname is not
465: // normalized before hashing.
490: 	hashType = components[1]
508: // See https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
511: 	mac.Write([]byte(hostname))
529: 	// actually hardcoded in openssh currently, see
530: 	// https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
531: 	if typ != sha1HashType {
538: func (h *hashedHost) match(a addr) bool {
147: 	h, p, err := net.SplitHostPort(address)
193: 		return "", "", nil, errors.New("knownhosts: missing key type pattern")
238: 		entry.matcher, err = newHostnameMatcher(pattern)
313: 		return "knownhosts: key is unknown"
315: 	return "knownhosts: key mismatch"
324: 	return "knownhosts: key is revoked"
336: 		return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", remote, err)
344: 			return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", address, err)
405: 			return fmt.Errorf("knownhosts: %s:%d: %v", filename, lineNum, err)
418: 	db := newHostKeyDB()
431: 	certChecker.IsHostAuthority = db.IsHostAuthority
435: 	return certChecker.CheckHostKey, nil
486: 		err = fmt.Errorf("knownhosts: got %d components, want 3", len(components))
github.com/GoogleCloudPlatform/terraformer:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/kubernetes/publishing-bot:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ]
30: type addr struct{ host, port string }
510: func hashHost(hostname string, salt []byte) []byte {
518: 	hash []byte
44: type hostPattern struct {
58: type hostPatterns []hostPattern
129: type hostKeyDB struct {
467: func HashHostname(hostname string) string {
480: func decodeHash(encoded string) (hashType string, salt, hash []byte, err error) {
501: func encodeHash(typ string, salt []byte, hash []byte) string {
516: type hashedHost struct {
523: func newHashedHost(encoded string) (*hashedHost, error) {
521: const sha1HashType = "1"
7: package knownhosts
135: func newHostKeyDB() *hostKeyDB {
148: func (db *hostKeyDB) IsHostAuthority(remote ssh.PublicKey, address string) bool {
251: func newHostnameMatcher(pattern string) (matcher, error) {
6: // known_hosts host key database.
23: 	"golang.org/x/crypto/ssh"
27: // (http://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT) for
33: 	h := a.host
112: 	return wildcardMatch([]byte(l.addr.host), []byte(a.host)) && l.addr.port == a.port
121: func serialize(k ssh.PublicKey) string {
143: func keyEq(a, b ssh.PublicKey) bool {
147: // IsAuthorityForHost can be used as a callback in ssh.CertChecker
153: 	a := addr{host: h, port: p}
163: // IsRevoked can be used as a callback in ssh.CertChecker
164: func (db *hostKeyDB) IsRevoked(key *ssh.Certificate) bool {
181: func parseLine(line []byte) (marker, host string, key ssh.PublicKey, err error) {
187: 	host, line = nextWord(line)
189: 		return "", "", nil, errors.New("knownhosts: missing host pattern")
204: 	key, err = ssh.ParsePublicKey(keyBytes)
209: 	return marker, host, key, nil
271: 			a.host, a.port, err = net.SplitHostPort(p)
276: 			a.host, a.port, err = net.SplitHostPort(p)
278: 				a.host = p
292: 	Key      ssh.PublicKey
301: // KeyError is returned if we did not find the key in the host key
306: 	// Want holds the accepted host keys. For each key algorithm,
307: 	// there can be one hostkey.  If Want is empty, the host is
329: // check checks a key against the host database. This should not be
331: func (db *hostKeyDB) check(address string, remote net.Addr, remoteKey ssh.PublicKey) error {
336: 	host, port, err := net.SplitHostPort(remote.String())
342: 		{host, port},
346: 		host, port, err := net.SplitHostPort(address)
351: 		addrs = append(addrs, addr{host, port})
360: func (db *hostKeyDB) checkAddrs(addrs []addr, remoteKey ssh.PublicKey) error {
381: 	// Unknown remote host.
386: 	// If the remote host starts using a different, unknown key type, we
415: // New creates a host key callback from the given OpenSSH host key
417: // ssh.ClientConfig.HostKeyCallback. Hashed hostnames are not supported.
418: func New(files ...string) (ssh.HostKeyCallback, error) {
431: 	var certChecker ssh.CertChecker
441: 	host, port, err := net.SplitHostPort(address)
443: 		host = address
446: 	entry := host
449: 	} else if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
456: func Line(addresses []string, key ssh.PublicKey) string {
476: 	hash := hashHost(hostname, salt)
477: 	return encodeHash(sha1HashType, salt, hash)
482: 		err = errors.New("knownhosts: hashed host must start with '|'")
495: 	if hash, err = base64.StdEncoding.DecodeString(components[3]); err != nil {
505: 		base64.StdEncoding.EncodeToString(hash),
524: 	typ, salt, hash, err := decodeHash(encoded)
533: 		return nil, fmt.Errorf("knownhosts: got hash type %s, must be '1'", typ)
536: 	return &hashedHost{salt: salt, hash: hash}, nil
541: 		if bytes.Equal(hashHost(Normalize(a.String()), h.salt), h.hash) {
5: // Package knownhosts implements a parser for the OpenSSH
26: // See the sshd manpage
49: func (p *hostPattern) String() string {
60: func (ps hostPatterns) match(addrs []addr) bool {
78: // https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/addrmatch.c
111: func (l *hostPattern) match(a addr) bool {
136: 	db := &hostKeyDB{
212: func (db *hostKeyDB) parseLine(line []byte, filename string, linenum int) error {
238: 		entry.matcher, err = newHashedHost(pattern)
252: 	var hps hostPatterns
266: 			return nil, errors.New("knownhosts: negation without following hostname")
282: 		hps = append(hps, hostPattern{
290: // KnownKey represents a key declared in a known_hosts file.
359: // or only the hostname, then this still succeeds.
363: 	// hostname?
396: func (db *hostKeyDB) Read(r io.Reader, filename string) error {
434: 	certChecker.HostKeyFallback = db.check
439: // Normalize normalizes an address into the form used in known_hosts
455: // Line returns a line to add append to the known_hosts files.
465: // HashHostname hashes the given hostname. The hostname is not
466: // normalized before hashing.
491: 	hashType = components[1]
509: // See https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
512: 	mac.Write([]byte(hostname))
530: 	// actually hardcoded in openssh currently, see
531: 	// https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
532: 	if typ != sha1HashType {
539: func (h *hashedHost) match(addrs []addr) bool {
149: 	h, p, err := net.SplitHostPort(address)
195: 		return "", "", nil, errors.New("knownhosts: missing key type pattern")
240: 		entry.matcher, err = newHostnameMatcher(pattern)
315: 		return "knownhosts: key is unknown"
317: 	return "knownhosts: key mismatch"
326: 	return "knownhosts: key is revoked"
338: 		return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", remote, err)
348: 			return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", address, err)
409: 			return fmt.Errorf("knownhosts: %s:%d: %v", filename, lineNum, err)
419: 	db := newHostKeyDB()
432: 	certChecker.IsHostAuthority = db.IsHostAuthority
436: 	return certChecker.CheckHostKey, nil
487: 		err = fmt.Errorf("knownhosts: got %d components, want 3", len(components))
github.com/src-d/rovers:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ]
31: type addr struct{ host, port string }
509: func hashHost(hostname string, salt []byte) []byte {
517: 	hash []byte
45: type hostPattern struct {
59: type hostPatterns []hostPattern
127: type hostKeyDB struct {
466: func HashHostname(hostname string) string {
479: func decodeHash(encoded string) (hashType string, salt, hash []byte, err error) {
500: func encodeHash(typ string, salt []byte, hash []byte) string {
515: type hashedHost struct {
522: func newHashedHost(encoded string) (*hashedHost, error) {
520: const sha1HashType = "1"
8: package knownhosts
133: func newHostKeyDB() *hostKeyDB {
146: func (db *hostKeyDB) IsHostAuthority(remote ssh.PublicKey, address string) bool {
249: func newHostnameMatcher(pattern string) (matcher, error) {
6: // host key database, and provides utility functions for writing
24: 	"golang.org/x/crypto/ssh"
28: // (http://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT) for
34: 	h := a.host
110: 	return wildcardMatch([]byte(p.addr.host), []byte(a.host)) && p.addr.port == a.port
119: func serialize(k ssh.PublicKey) string {
141: func keyEq(a, b ssh.PublicKey) bool {
145: // IsAuthorityForHost can be used as a callback in ssh.CertChecker
151: 	a := addr{host: h, port: p}
161: // IsRevoked can be used as a callback in ssh.CertChecker
162: func (db *hostKeyDB) IsRevoked(key *ssh.Certificate) bool {
179: func parseLine(line []byte) (marker, host string, key ssh.PublicKey, err error) {
185: 	host, line = nextWord(line)
187: 		return "", "", nil, errors.New("knownhosts: missing host pattern")
202: 	key, err = ssh.ParsePublicKey(keyBytes)
207: 	return marker, host, key, nil
269: 			a.host, a.port, err = net.SplitHostPort(p)
274: 			a.host, a.port, err = net.SplitHostPort(p)
276: 				a.host = p
290: 	Key      ssh.PublicKey
299: // KeyError is returned if we did not find the key in the host key
304: 	// Want holds the accepted host keys. For each key algorithm,
305: 	// there can be one hostkey.  If Want is empty, the host is
327: // check checks a key against the host database. This should not be
329: func (db *hostKeyDB) check(address string, remote net.Addr, remoteKey ssh.PublicKey) error {
334: 	host, port, err := net.SplitHostPort(remote.String())
339: 	hostToCheck := addr{host, port}
342: 		host, port, err := net.SplitHostPort(address)
347: 		hostToCheck = addr{host, port}
356: func (db *hostKeyDB) checkAddr(a addr, remoteKey ssh.PublicKey) error {
377: 	// Unknown remote host.
382: 	// If the remote host starts using a different, unknown key type, we
411: // New creates a host key callback from the given OpenSSH host key
413: // ssh.ClientConfig.HostKeyCallback. By preference, the key check
415: // IP address, the host key check will still succeed, even though a
417: func New(files ...string) (ssh.HostKeyCallback, error) {
430: 	var certChecker ssh.CertChecker
440: 	host, port, err := net.SplitHostPort(address)
442: 		host = address
445: 	entry := host
448: 	} else if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
455: func Line(addresses []string, key ssh.PublicKey) string {
475: 	hash := hashHost(hostname, salt)
476: 	return encodeHash(sha1HashType, salt, hash)
481: 		err = errors.New("knownhosts: hashed host must start with '|'")
494: 	if hash, err = base64.StdEncoding.DecodeString(components[3]); err != nil {
504: 		base64.StdEncoding.EncodeToString(hash),
523: 	typ, salt, hash, err := decodeHash(encoded)
532: 		return nil, fmt.Errorf("knownhosts: got hash type %s, must be '1'", typ)
535: 	return &hashedHost{salt: salt, hash: hash}, nil
539: 	return bytes.Equal(hashHost(Normalize(a.String()), h.salt), h.hash)
5: // Package knownhosts implements a parser for the OpenSSH known_hosts
7: // OpenSSH compliant known_hosts files.
27: // See the sshd manpage
50: func (p *hostPattern) String() string {
61: func (ps hostPatterns) match(a addr) bool {
76: // https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/addrmatch.c
109: func (p *hostPattern) match(a addr) bool {
134: 	db := &hostKeyDB{
210: func (db *hostKeyDB) parseLine(line []byte, filename string, linenum int) error {
236: 		entry.matcher, err = newHashedHost(pattern)
250: 	var hps hostPatterns
264: 			return nil, errors.New("knownhosts: negation without following hostname")
280: 		hps = append(hps, hostPattern{
288: // KnownKey represents a key declared in a known_hosts file.
341: 		// Give preference to the hostname if available.
350: 	return db.checkAddr(hostToCheck, remoteKey)
355: // or only the hostname, then this still succeeds.
359: 	// hostname?
392: func (db *hostKeyDB) Read(r io.Reader, filename string) error {
414: // operates on the hostname if available, i.e. if a server changes its
433: 	certChecker.HostKeyFallback = db.check
438: // Normalize normalizes an address into the form used in known_hosts
454: // Line returns a line to add append to the known_hosts files.
464: // HashHostname hashes the given hostname. The hostname is not
465: // normalized before hashing.
490: 	hashType = components[1]
508: // See https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
511: 	mac.Write([]byte(hostname))
529: 	// actually hardcoded in openssh currently, see
530: 	// https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
531: 	if typ != sha1HashType {
538: func (h *hashedHost) match(a addr) bool {
147: 	h, p, err := net.SplitHostPort(address)
193: 		return "", "", nil, errors.New("knownhosts: missing key type pattern")
238: 		entry.matcher, err = newHostnameMatcher(pattern)
313: 		return "knownhosts: key is unknown"
315: 	return "knownhosts: key mismatch"
324: 	return "knownhosts: key is revoked"
336: 		return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", remote, err)
344: 			return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", address, err)
405: 			return fmt.Errorf("knownhosts: %s:%d: %v", filename, lineNum, err)
418: 	db := newHostKeyDB()
431: 	certChecker.IsHostAuthority = db.IsHostAuthority
435: 	return certChecker.CheckHostKey, nil
486: 		err = fmt.Errorf("knownhosts: got %d components, want 3", len(components))
github.com/apache/mynewt-newtmgr:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/src-d/engine:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/src-d/lookout:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/apache/mynewt-documentation:versions/v1_4_0/mynewt-newtmgr/vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/src-d/borges:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/GoogleCloudPlatform/k8s-sqldb-operator:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/sourcegraph/go-vcs:vcs/ssh/hostkey.go: [ master, ]
17: package ssh
47: 	Salt, Hash []byte // hashed hostname
38: 	sshHashDelim  = "|" // hostfile.h
39: 	sshHashPrefix = "|1|"
44: type KnownHost struct {
45: 	Hostnames []string // unhashed hostnames (represented as comma-separated names in the original file)
79: type KnownHosts []*KnownHost
97: func ReadStandardKnownHostsFiles() (KnownHosts, error) {
121: func ReadKnownHostsFile(path string) (KnownHosts, error) {
141: func ParseKnownHosts(r io.Reader) (KnownHosts, error) {
170: func parseKnownHostsLine(line []byte) (*KnownHost, error) {
34: 	"golang.org/x/crypto/ssh"
42: // A KnownHost is a hostname and a known host key associated with that
49: 	Key ssh.PublicKey
52: // Match returns whether hostname matches this known host entry's
63: 	if h.Salt != nil && h.Hash != nil {
66: 		hash := mac.Sum(nil)
67: 		if bytes.Equal(h.Hash, hash) {
75: // KnownHosts is a collection of known hosts and their host
77: // host keys for a hostname instead of simply iterating over them and
82: // the known hosts collection. It returns host keys that match the
83: // unhashed hostname and the hashed variant of it. If any host keys
85: func (khs KnownHosts) Lookup(hostname string) (hostKeys []ssh.PublicKey, found bool) {
96: // at /etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts.
99: 	kh, err := ReadKnownHostsFile("/etc/ssh/known_hosts")
110: 		kh1, err := ReadKnownHostsFile(filepath.Join(u.HomeDir, ".ssh/known_hosts"))
140: // ParseKnownHosts parses an SSH known_hosts file.
168: // ssh.PublicKey parsed from the line, and any error encountered
198: 		//  <host>     = the hostname/address to be hashed
200: 		//  <hash_b64> = base64(SHA1(<salt> <host>))
201: 		//  <salt/hash pair> = '|1|' salt_b64 '|' hash_b64
207: 		hash64 := hosts[delim+1:]
210: 		kh.Hash = make([]byte, b64.DecodedLen(len(hash64)))
216: 		if n, err := b64.Decode(kh.Hash, hash64); err != nil {
219: 			kh.Hash = kh.Hash[:n]
226: 	key, _, _, _, err := ssh.ParseAuthorizedKey(keyBytes)
43: // hostname. The hostname can be either unhashed or hashed.
53: // unhashed hostnames (separated by comma) or the hashed hostname.
54: func (h *KnownHost) Match(hostname string) bool {
55: 	// TODO(sqs): lowercase before comparing? will that break hashed hostname lookups?
57: 	for _, hn := range h.Hostnames {
58: 		if hn == hostname {
65: 		mac.Write([]byte(hostname))
76: // keys. Because hostname key may be hashed, use Lookup to get the
78: // checking the Hostname field.
81: // Lookup looks up hostname (which must be an unhashed hostname) in
87: 		if h.Match(hostname) {
88: 			hostKeys = append(hostKeys, h.Key)
92: 	return hostKeys, found
95: // ReadStandardKnownHostsFiles reads and parses the known_hosts files
98: 	// System known_hosts
104: 	// User known_hosts
120: // ReadKnownHostsFile reads the known_hosts file at path.
134: 		return nil, fmt.Errorf("known_hosts file %s must not be writable by others (mode %o)", path, fi.Mode().Perm())
151: 			return nil, fmt.Errorf("parsing known_hosts: %s (line %d)", err, n)
166: // parseKnownHostsLine parses a line from a known hosts file.  It
167: // returns a string containing the hosts section of the line, an
184: 	// Find the end of the hostname(s) portion.
189: 	hosts := line[:end]
192: 	kh := &KnownHost{}
194: 	// Check for hashed hostnames.
195: 	if bytes.HasPrefix(hosts, []byte(sshHashPrefix)) {
196: 		hosts = bytes.TrimPrefix(hosts, []byte(sshHashPrefix))
197: 		// Hashed hostname format:
202: 		delim := bytes.Index(hosts, []byte(sshHashDelim))
203: 		if delim <= 0 || delim >= len(hosts) {
204: 			return nil, errors.New("bad hashed hostname format")
206: 		salt64 := hosts[:delim]
222: 		kh.Hostnames = strings.Split(string(hosts), ",")
137: 	return ParseKnownHosts(f)
142: 	var khs KnownHosts
149: 		kh, err := parseKnownHostsLine(line)
github.com/src-d/regression-gitbase:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/sourcegraph/vcsstore:Godeps/_workspace/src/sourcegraph.com/sourcegraph/go-vcs/vcs/ssh/hostkey.go: [ master, ] Duplicate result
github.com/src-d/regression-borges:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/sourcegraph/zoekt-archived:vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ]
30: type addr struct{ host, port string }
510: func hashHost(hostname string, salt []byte) []byte {
518: 	hash []byte
44: type hostPattern struct {
58: type hostPatterns []hostPattern
129: type hostKeyDB struct {
467: func HashHostname(hostname string) string {
480: func decodeHash(encoded string) (hashType string, salt, hash []byte, err error) {
501: func encodeHash(typ string, salt []byte, hash []byte) string {
516: type hashedHost struct {
523: func newHashedHost(encoded string) (*hashedHost, error) {
521: const sha1HashType = "1"
7: package knownhosts
135: func newHostKeyDB() *hostKeyDB {
148: func (db *hostKeyDB) IsHostAuthority(remote ssh.PublicKey, address string) bool {
251: func newHostnameMatcher(pattern string) (matcher, error) {
6: // known_hosts host key database.
23: 	"golang.org/x/crypto/ssh"
27: // (http://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT) for
33: 	h := a.host
112: 	return wildcardMatch([]byte(p.addr.host), []byte(a.host)) && p.addr.port == a.port
121: func serialize(k ssh.PublicKey) string {
143: func keyEq(a, b ssh.PublicKey) bool {
147: // IsAuthorityForHost can be used as a callback in ssh.CertChecker
153: 	a := addr{host: h, port: p}
163: // IsRevoked can be used as a callback in ssh.CertChecker
164: func (db *hostKeyDB) IsRevoked(key *ssh.Certificate) bool {
181: func parseLine(line []byte) (marker, host string, key ssh.PublicKey, err error) {
187: 	host, line = nextWord(line)
189: 		return "", "", nil, errors.New("knownhosts: missing host pattern")
204: 	key, err = ssh.ParsePublicKey(keyBytes)
209: 	return marker, host, key, nil
271: 			a.host, a.port, err = net.SplitHostPort(p)
276: 			a.host, a.port, err = net.SplitHostPort(p)
278: 				a.host = p
292: 	Key      ssh.PublicKey
301: // KeyError is returned if we did not find the key in the host key
306: 	// Want holds the accepted host keys. For each key algorithm,
307: 	// there can be one hostkey.  If Want is empty, the host is
329: // check checks a key against the host database. This should not be
331: func (db *hostKeyDB) check(address string, remote net.Addr, remoteKey ssh.PublicKey) error {
336: 	host, port, err := net.SplitHostPort(remote.String())
342: 		{host, port},
346: 		host, port, err := net.SplitHostPort(address)
351: 		addrs = append(addrs, addr{host, port})
360: func (db *hostKeyDB) checkAddrs(addrs []addr, remoteKey ssh.PublicKey) error {
381: 	// Unknown remote host.
386: 	// If the remote host starts using a different, unknown key type, we
415: // New creates a host key callback from the given OpenSSH host key
417: // ssh.ClientConfig.HostKeyCallback.
418: func New(files ...string) (ssh.HostKeyCallback, error) {
431: 	var certChecker ssh.CertChecker
441: 	host, port, err := net.SplitHostPort(address)
443: 		host = address
446: 	entry := host
449: 	} else if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") {
456: func Line(addresses []string, key ssh.PublicKey) string {
476: 	hash := hashHost(hostname, salt)
477: 	return encodeHash(sha1HashType, salt, hash)
482: 		err = errors.New("knownhosts: hashed host must start with '|'")
495: 	if hash, err = base64.StdEncoding.DecodeString(components[3]); err != nil {
505: 		base64.StdEncoding.EncodeToString(hash),
524: 	typ, salt, hash, err := decodeHash(encoded)
533: 		return nil, fmt.Errorf("knownhosts: got hash type %s, must be '1'", typ)
536: 	return &hashedHost{salt: salt, hash: hash}, nil
541: 		if bytes.Equal(hashHost(Normalize(a.String()), h.salt), h.hash) {
5: // Package knownhosts implements a parser for the OpenSSH
26: // See the sshd manpage
49: func (p *hostPattern) String() string {
60: func (ps hostPatterns) match(addrs []addr) bool {
78: // https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/addrmatch.c
111: func (p *hostPattern) match(a addr) bool {
136: 	db := &hostKeyDB{
212: func (db *hostKeyDB) parseLine(line []byte, filename string, linenum int) error {
238: 		entry.matcher, err = newHashedHost(pattern)
252: 	var hps hostPatterns
266: 			return nil, errors.New("knownhosts: negation without following hostname")
282: 		hps = append(hps, hostPattern{
290: // KnownKey represents a key declared in a known_hosts file.
359: // or only the hostname, then this still succeeds.
363: 	// hostname?
396: func (db *hostKeyDB) Read(r io.Reader, filename string) error {
434: 	certChecker.HostKeyFallback = db.check
439: // Normalize normalizes an address into the form used in known_hosts
455: // Line returns a line to add append to the known_hosts files.
465: // HashHostname hashes the given hostname. The hostname is not
466: // normalized before hashing.
491: 	hashType = components[1]
509: // See https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
512: 	mac.Write([]byte(hostname))
530: 	// actually hardcoded in openssh currently, see
531: 	// https://android.googlesource.com/platform/external/openssh/+/ab28f5495c85297e7a597c1ba62e996416da7c7e/hostfile.c#120
532: 	if typ != sha1HashType {
539: func (h *hashedHost) match(addrs []addr) bool {
149: 	h, p, err := net.SplitHostPort(address)
195: 		return "", "", nil, errors.New("knownhosts: missing key type pattern")
240: 		entry.matcher, err = newHostnameMatcher(pattern)
315: 		return "knownhosts: key is unknown"
317: 	return "knownhosts: key mismatch"
326: 	return "knownhosts: key is revoked"
338: 		return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", remote, err)
348: 			return fmt.Errorf("knownhosts: SplitHostPort(%s): %v", address, err)
409: 			return fmt.Errorf("knownhosts: %s:%d: %v", filename, lineNum, err)
419: 	db := newHostKeyDB()
432: 	certChecker.IsHostAuthority = db.IsHostAuthority
436: 	return certChecker.CheckHostKey, nil
487: 		err = fmt.Errorf("knownhosts: got %d components, want 3", len(components))
github.com/src-d/lookout-sdk-ml:lookout/core/server/vendor/golang.org/x/crypto/ssh/knownhosts/knownhosts.go: [ master, ] Duplicate result
github.com/libfuse/sshfs:sshfs.c: [ master, ]
252: 	char *host;
65: #define SSH_FXP_INIT                1
66: #define SSH_FXP_VERSION             2
67: #define SSH_FXP_OPEN                3
68: #define SSH_FXP_CLOSE               4
69: #define SSH_FXP_READ                5
70: #define SSH_FXP_WRITE               6
71: #define SSH_FXP_LSTAT               7
72: #define SSH_FXP_FSTAT               8
73: #define SSH_FXP_SETSTAT             9
74: #define SSH_FXP_FSETSTAT           10
75: #define SSH_FXP_OPENDIR            11
76: #define SSH_FXP_READDIR            12
77: #define SSH_FXP_REMOVE             13
78: #define SSH_FXP_MKDIR              14
79: #define SSH_FXP_RMDIR              15
80: #define SSH_FXP_REALPATH           16
81: #define SSH_FXP_STAT               17
82: #define SSH_FXP_RENAME             18
83: #define SSH_FXP_READLINK           19
84: #define SSH_FXP_SYMLINK            20
85: #define SSH_FXP_STATUS            101
86: #define SSH_FXP_HANDLE            102
87: #define SSH_FXP_DATA              103
88: #define SSH_FXP_NAME              104
89: #define SSH_FXP_ATTRS             105
90: #define SSH_FXP_EXTENDED          200
91: #define SSH_FXP_EXTENDED_REPLY    201
93: #define SSH_FILEXFER_ATTR_SIZE          0x00000001
94: #define SSH_FILEXFER_ATTR_UIDGID        0x00000002
95: #define SSH_FILEXFER_ATTR_PERMISSIONS   0x00000004
96: #define SSH_FILEXFER_ATTR_ACMODTIME     0x00000008
97: #define SSH_FILEXFER_ATTR_EXTENDED      0x80000000
99: #define SSH_FX_OK                            0
100: #define SSH_FX_EOF                           1
101: #define SSH_FX_NO_SUCH_FILE                  2
102: #define SSH_FX_PERMISSION_DENIED             3
103: #define SSH_FX_FAILURE                       4
104: #define SSH_FX_BAD_MESSAGE                   5
105: #define SSH_FX_NO_CONNECTION                 6
106: #define SSH_FX_CONNECTION_LOST               7
107: #define SSH_FX_OP_UNSUPPORTED                8
109: #define SSH_FXF_READ            0x00000001
110: #define SSH_FXF_WRITE           0x00000002
111: #define SSH_FXF_APPEND          0x00000004
112: #define SSH_FXF_CREAT           0x00000008
113: #define SSH_FXF_TRUNC           0x00000010
114: #define SSH_FXF_EXCL            0x00000020
117: #define SSH2_FXE_STATVFS_ST_RDONLY	0x00000001
118: #define SSH2_FXE_STATVFS_ST_NOSUID	0x00000002
212: 	char *ssh_command;
214: 	struct fuse_args ssh_args;
243: 	unsigned ssh_ver;
297: static const char *ssh_opts[] = {
895: static void ssh_add_arg(const char *arg)
1002: static int start_ssh(void)
3703: static int ssh_connect(void)
142: static char sshfs_program_path[PATH_MAX] = { 0 };
174: struct sshfs_io {
197: struct sshfs_file {
210: struct sshfs {
295: static struct sshfs sshfs;
379: #define SSHFS_OPT(t, p, v) { t, offsetof(struct sshfs, p), v }
381: static struct fuse_opt sshfs_opts[] = {
1731: static void *sshfs_init(struct fuse_conn_info *conn,
1909: static int sshfs_access(const char *path, int mask)
1991: static int sshfs_readlink(const char *path, char *linkbuf, size_t size)
2033: static int sshfs_req_pending(struct request *req)
2138: static int sshfs_opendir(const char *path, struct fuse_file_info *fi)
2160: static int sshfs_readdir(const char *path, void *dbuf, fuse_fill_dir_t filler,
2178: static int sshfs_releasedir(const char *path, struct fuse_file_info *fi)
2192: static int sshfs_mkdir(const char *path, mode_t mode)
2205: static int sshfs_mknod(const char *path, mode_t mode, dev_t rdev)
2234: static int sshfs_symlink(const char *from, const char *to)
2252: static int sshfs_unlink(const char *path)
2263: static int sshfs_rmdir(const char *path)
2274: static int sshfs_do_rename(const char *from, const char *to)
2286: static int sshfs_ext_posix_rename(const char *from, const char *to)
2307: static int sshfs_rename(const char *from, const char *to, unsigned int flags)
2340: static int sshfs_link(const char *from, const char *to)
2359: static inline int sshfs_file_is_conn(struct sshfs_file *sf)
2375: static int sshfs_chmod(const char *path, mode_t mode,
2405: static int sshfs_chown(const char *path, uid_t uid, gid_t gid,
2450: static void sshfs_inc_modifver(void)
2457: static int sshfs_utimens(const char *path, const struct timespec tv[2],
2494: static int sshfs_open_common(const char *path, mode_t mode,
2583: static int sshfs_open(const char *path, struct fuse_file_info *fi)
2588: static int sshfs_flush(const char *path, struct fuse_file_info *fi)
2617: static int sshfs_fsync(const char *path, int isdatasync,
2640: static void sshfs_file_put(struct sshfs_file *sf)
2647: static void sshfs_file_get(struct sshfs_file *sf)
2652: static int sshfs_release(const char *path, struct fuse_file_info *fi)
2666: static void sshfs_read_end(struct request *req)
2705: static void sshfs_read_begin(struct request *req)
2711: static struct read_chunk *sshfs_send_read(struct sshfs_file *sf, size_t size,
2815: static int sshfs_sync_read(struct sshfs_file *sf, char *buf, size_t size,
2848: static int sshfs_async_read(struct sshfs_file *sf, char *rbuf, size_t size,
2898: static int sshfs_read(const char *path, char *rbuf, size_t size, off_t offset,
2913: static void sshfs_write_begin(struct request *req)
2921: static void sshfs_write_end(struct request *req)
2941: static int sshfs_async_write(struct sshfs_file *sf, const char *wbuf,
2971: static void sshfs_sync_write_begin(struct request *req)
2977: static void sshfs_sync_write_end(struct request *req)
2998: static int sshfs_sync_write(struct sshfs_file *sf, const char *wbuf,
3040: static int sshfs_write(const char *path, const char *wbuf, size_t size,
3061: static int sshfs_ext_statvfs(const char *path, struct statvfs *stbuf)
3081: static int sshfs_statfs(const char *path, struct statvfs *buf)
3099: static int sshfs_create(const char *path, mode_t mode,
3108: static int sshfs_truncate(const char *path, off_t size,
3141: static int sshfs_getattr(const char *path, struct stat *stbuf,
3177: static int sshfs_truncate_zero(const char *path)
3195: static int sshfs_truncate_shrink(const char *path, off_t size)
3241: static int sshfs_truncate_extend(const char *path, off_t size,
3276: static int sshfs_truncate_workaround(const char *path, off_t size,
3311: static struct fuse_operations sshfs_oper = {
3420: static int sshfs_opt_proc(void *data, const char *arg, int key,
3405: static int is_ssh_opt(const char *arg)
3637: static void set_ssh_command(void)
2370: static inline struct sshfs_file *get_sshfs_file(struct fuse_file_info *fi)
2:   SSH file system
383: 	SSHFS_OPT("ssh_command=%s",    ssh_command, 0),
387: 	SSHFS_OPT("ssh_protocol=%u",   ssh_ver, 0),
388: 	SSHFS_OPT("-1",                ssh_ver, 1),
469: 	case SSH_FXP_INIT:           return "INIT";
470: 	case SSH_FXP_VERSION:        return "VERSION";
471: 	case SSH_FXP_OPEN:           return "OPEN";
472: 	case SSH_FXP_CLOSE:          return "CLOSE";
473: 	case SSH_FXP_READ:           return "READ";
474: 	case SSH_FXP_WRITE:          return "WRITE";
475: 	case SSH_FXP_LSTAT:          return "LSTAT";
476: 	case SSH_FXP_FSTAT:          return "FSTAT";
477: 	case SSH_FXP_SETSTAT:        return "SETSTAT";
478: 	case SSH_FXP_FSETSTAT:       return "FSETSTAT";
479: 	case SSH_FXP_OPENDIR:        return "OPENDIR";
480: 	case SSH_FXP_READDIR:        return "READDIR";
481: 	case SSH_FXP_REMOVE:         return "REMOVE";
482: 	case SSH_FXP_MKDIR:          return "MKDIR";
483: 	case SSH_FXP_RMDIR:          return "RMDIR";
484: 	case SSH_FXP_REALPATH:       return "REALPATH";
485: 	case SSH_FXP_STAT:           return "STAT";
486: 	case SSH_FXP_RENAME:         return "RENAME";
487: 	case SSH_FXP_READLINK:       return "READLINK";
488: 	case SSH_FXP_SYMLINK:        return "SYMLINK";
489: 	case SSH_FXP_STATUS:         return "STATUS";
490: 	case SSH_FXP_HANDLE:         return "HANDLE";
491: 	case SSH_FXP_DATA:           return "DATA";
492: 	case SSH_FXP_NAME:           return "NAME";
493: 	case SSH_FXP_ATTRS:          return "ATTRS";
494: 	case SSH_FXP_EXTENDED:       return "EXTENDED";
495: 	case SSH_FXP_EXTENDED_REPLY: return "EXTENDED_REPLY";
542: 	if (g_hash_table_lookup_extended(map, GUINT_TO_POINTER(*id), NULL, &id_p)) {
759: 	if ((flags & SSH_FILEXFER_ATTR_SIZE) &&
762: 	if ((flags & SSH_FILEXFER_ATTR_UIDGID) &&
766: 	if ((flags & SSH_FILEXFER_ATTR_PERMISSIONS) &&
769: 	if ((flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
774: 	if ((flags & SSH_FILEXFER_ATTR_EXTENDED)) {
897: 	if (fuse_opt_add_arg(&sshfs.ssh_args, arg) == -1)
930: 			 * Something happened on stdout of ssh, this
1076: 			for (i = 0; i < sshfs.ssh_args.argc; i++)
1078: 					sshfs.ssh_args.argv[i]);
1082: 		execvp(sshfs.ssh_args.argv[0], sshfs.ssh_args.argv);
1084: 			sshfs.ssh_args.argv[0], strerror(errno));
1099: static int connect_to(char *host, char *port)
1110: 	err = getaddrinfo(host, port, &hint, &ai);
1112: 		fprintf(stderr, "failed to resolve %s:%s: %s\n", host, port,
1224: 			fprintf(stderr, "remote host has disconnected\n");
1325: 		g_hash_table_lookup(sshfs.reqtab, GUINT_TO_POINTER(id));
1337: 		g_hash_table_remove(sshfs.reqtab, GUINT_TO_POINTER(id));
1408: 	g_hash_table_foreach_remove(sshfs.reqtab, (GHRFunc) clean_req, NULL);
1435: 	if (type != SSH_FXP_VERSION)
1516: 	if (sftp_send_iov(SSH_FXP_INIT, PROTO_VERSION, NULL, 0) == -1)
1541: 	case SSH_FX_OK:                return 0;
1542: 	case SSH_FX_NO_SUCH_FILE:      return ENOENT;
1543: 	case SSH_FX_PERMISSION_DENIED: return EACCES;
1544: 	case SSH_FX_FAILURE:           return EPERM;
1545: 	case SSH_FX_BAD_MESSAGE:       return EBADMSG;
1546: 	case SSH_FX_NO_CONNECTION:     return ENOTCONN;
1547: 	case SSH_FX_CONNECTION_LOST:   return ECONNABORTED;
1548: 	case SSH_FX_OP_UNSUPPORTED:    return EOPNOTSUPP;
1566: 	if (sftp_send_iov(SSH_FXP_STAT, id, iov, 1) == -1)
1571: 	if (type != SSH_FXP_ATTRS && type != SSH_FXP_STATUS) {
1581: 	if (type == SSH_FXP_STATUS) {
1592: 	if (!(flags & SSH_FILEXFER_ATTR_UIDGID))
1624: 	if (sftp_send_iov(SSH_FXP_LSTAT, id, iov, 1) == -1)
1629: 	if (type != SSH_FXP_ATTRS && type != SSH_FXP_STATUS) {
1639: 	if (type == SSH_FXP_STATUS) {
1644: 		fprintf(stderr, "%s:%s: %s\n", sshfs.host, remote_dir,
1656: 	if (!(flags & SSH_FILEXFER_ATTR_PERMISSIONS))
1660: 		fprintf(stderr, "%s:%s: Not a directory\n", sshfs.host,
1679: 		err = connect_to(sshfs.host, sshfs.directport);
1681: 		err = start_ssh();
1769: 	    req->reply_type != SSH_FXP_STATUS) {
1773: 	if (req->reply_type == SSH_FXP_STATUS) {
1779: 		case SSH_FX_OK:
1780: 			if (expect_type == SSH_FXP_STATUS)
1786: 		case SSH_FX_EOF:
1787: 			if (type == SSH_FXP_READ || type == SSH_FXP_READDIR)
1793: 		case SSH_FX_FAILURE:
1794: 			if (type == SSH_FXP_RMDIR)
1848: 	g_hash_table_insert(sshfs.reqtab, GUINT_TO_POINTER(id), req);
1862: 		rmed = g_hash_table_remove(sshfs.reqtab, GUINT_TO_POINTER(id));
2004: 	err = sftp_request(SSH_FXP_READLINK, &buf, SSH_FXP_NAME, &name);
2029: 	return sftp_request_send(SSH_FXP_READDIR, &iov, 1, NULL, NULL,
2030: 				 SSH_FXP_NAME, NULL, req);
2035: 	if (g_hash_table_lookup(sshfs.reqtab, GUINT_TO_POINTER(req->id)))
2092: 			tmperr = sftp_request_wait(req, SSH_FXP_READDIR,
2093: 						    SSH_FXP_NAME, &name);
2126: 		err = sftp_request(SSH_FXP_READDIR, handle, SSH_FXP_NAME, &name);
2150: 	err = sftp_request(SSH_FXP_OPENDIR, &buf, SSH_FXP_HANDLE, handle);
2185: 	err = sftp_request(SSH_FXP_CLOSE, handle, 0, NULL);
2198: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2200: 	err = sftp_request(SSH_FXP_MKDIR, &buf, SSH_FXP_STATUS, NULL);
2217: 	buf_add_uint32(&buf, SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_EXCL);
2218: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2220: 	err = sftp_request(SSH_FXP_OPEN, &buf, SSH_FXP_HANDLE, &handle);
2224: 		err2 = sftp_request(SSH_FXP_CLOSE, &handle, SSH_FXP_STATUS,
2247: 	err = sftp_request(SSH_FXP_SYMLINK, &buf, SSH_FXP_STATUS, NULL);
2258: 	err = sftp_request(SSH_FXP_REMOVE, &buf, SSH_FXP_STATUS, NULL);
2269: 	err = sftp_request(SSH_FXP_RMDIR, &buf, SSH_FXP_STATUS, NULL);
2281: 	err = sftp_request(SSH_FXP_RENAME, &buf, SSH_FXP_STATUS, NULL);
2294: 	err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_STATUS, NULL);
2351: 		err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_STATUS,
2395: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2399: 	err = sftp_request(sf == NULL ? SSH_FXP_SETSTAT : SSH_FXP_FSETSTAT,
2400: 			   &buf, SSH_FXP_STATUS, NULL);
2437: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_UIDGID);
2441: 	err = sftp_request(sf == NULL ? SSH_FXP_SETSTAT : SSH_FXP_FSETSTAT,
2442: 			   &buf, SSH_FXP_STATUS, NULL);
2484: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_ACMODTIME);
2488: 	err = sftp_request(sf == NULL ? SSH_FXP_SETSTAT : SSH_FXP_FSETSTAT,
2489: 			   &buf, SSH_FXP_STATUS, NULL);
2513: 		pflags = SSH_FXF_READ;
2515: 		pflags = SSH_FXF_WRITE;
2517: 		pflags = SSH_FXF_READ | SSH_FXF_WRITE;
2522: 		pflags |= SSH_FXF_CREAT;
2525: 		pflags |= SSH_FXF_EXCL;
2528: 		pflags |= SSH_FXF_TRUNC;
2531: 		pflags |= SSH_FXF_APPEND;
2547: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2550: 	sftp_request_send(SSH_FXP_OPEN, &iov, 1, NULL, NULL, 1, NULL,
2554: 	type = sshfs.follow_symlinks ? SSH_FXP_STAT : SSH_FXP_LSTAT;
2555: 	err2 = sftp_request(type, &buf, SSH_FXP_ATTRS, &outbuf);
2560: 	err = sftp_request_wait(open_req, SSH_FXP_OPEN, SSH_FXP_HANDLE,
2564: 		sftp_request(SSH_FXP_CLOSE, &sf->handle, 0, NULL);
2635: 	err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_STATUS, NULL);
2658: 		sftp_request(SSH_FXP_CLOSE, handle, 0, NULL);
2674: 		if (req->reply_type == SSH_FXP_STATUS) {
2677: 				if (serr == SSH_FX_EOF)
2682: 		} else if (req->reply_type == SSH_FXP_DATA) {
2741: 		err = sftp_request_send(SSH_FXP_READ, iov, 1,
2929: 		if (req->reply_type != SSH_FXP_STATUS) {
2932: 			 serr != SSH_FX_OK) {
2959: 		err = sftp_request_send(SSH_FXP_WRITE, iov, 2,
2985: 		if (req->reply_type != SSH_FXP_STATUS) {
2988: 			 serr != SSH_FX_OK) {
3019: 		err = sftp_request_send(SSH_FXP_WRITE, iov, 2,
3069: 	err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_EXTENDED_REPLY,
3132: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_SIZE);
3134: 	err = sftp_request(sf == NULL ? SSH_FXP_SETSTAT : SSH_FXP_FSETSTAT,
3135: 			   &buf, SSH_FXP_STATUS, NULL);
3159: 		err = sftp_request(sshfs.follow_symlinks ? SSH_FXP_STAT : SSH_FXP_LSTAT,
3160: 				   &buf, SSH_FXP_ATTRS, &outbuf);
3164: 		err = sftp_request(SSH_FXP_FSTAT, &buf, SSH_FXP_ATTRS, &outbuf);
3266:  * SSH_FILEXFER_ATTR_SIZE in SETSTAT request.
3303: 	sshfs.reqtab = g_hash_table_new(NULL, NULL);
3305: 		fprintf(stderr, "failed to create hash table\n");
3343: "usage: %s [user@]host:[dir] mountpoint [options]\n"
3351: "    -F ssh_configfile      specifies alternative ssh configuration file\n"
3352: "    -1                     equivalent to '-o ssh_protocol=1'\n"
3389: "    -o ssh_command=CMD     execute CMD instead of 'ssh'\n"
3390: "    -o ssh_protocol=N      ssh protocol to use (default: 2)\n"
3392: "    -o directport=PORT     directly connect to PORT bypassing ssh\n"
3399: "    -o SSHOPT=VAL          ssh options (see man ssh_config)\n"
3410: 		for (o = ssh_opts; *o; o++) {
3428: 		if (is_ssh_opt(arg)) {
3430: 			ssh_add_arg(tmp);
3438: 		if (!sshfs.host && strchr(arg, ':')) {
3439: 			sshfs.host = strdup(arg);
3501: 		ssh_add_arg(tmp);
3506: 		ssh_add_arg("-oCompression=yes");
3511: 		ssh_add_arg(tmp);
3594: 	ssh_add_arg("-oNumberOfPasswordPrompts=1");
3642: 	token = tokenize_on_space(sshfs.ssh_command);
3645: 			replace_arg(&sshfs.ssh_args.argv[0], token);
3647: 			if (fuse_opt_insert_arg(&sshfs.ssh_args, i, token) == -1)
3658: 	char *s = sshfs.host;
3777: 	*idmap = g_hash_table_new(NULL, NULL);
3778: 	*r_idmap = g_hash_table_new(NULL, NULL);
3827: 		g_hash_table_insert(*idmap, GUINT_TO_POINTER(remote_id), GUINT_TO_POINTER(*local_id));
3828: 		g_hash_table_insert(*r_idmap, GUINT_TO_POINTER(*local_id), GUINT_TO_POINTER(remote_id));
3931: 	sshfs.ssh_ver = 2;
3955: 	ssh_add_arg("ssh");
3956: 	ssh_add_arg("-x");
3957: 	ssh_add_arg("-a");
3958: 	ssh_add_arg("-oClearAllForwardings=yes");
3977: 	} else if (!sshfs.host) {
3978: 		fprintf(stderr, "missing host\n");
4035: 	fsname = g_strdup(sshfs.host);
4038: 	if (sshfs.ssh_command)
4039: 		set_ssh_command();
4041: 	tmp = g_strdup_printf("-%i", sshfs.ssh_ver);
4042: 	ssh_add_arg(tmp);
4044: 	ssh_add_arg(sshfs.host);
4047: 	else if (sshfs.ssh_ver == 1)
4052: 	if (sshfs.ssh_ver != 1 && strchr(sftp_server, '/') == NULL)
4053: 		ssh_add_arg("-s");
4055: 	ssh_add_arg(sftp_server);
4106: 	res = ssh_connect();
4154: 	fuse_opt_free_args(&sshfs.ssh_args);
116: /* statvfs@openssh.com f_flag flags */
120: #define SFTP_EXT_POSIX_RENAME "posix-rename@openssh.com"
121: #define SFTP_EXT_STATVFS "statvfs@openssh.com"
122: #define SFTP_EXT_HARDLINK "hardlink@openssh.com"
123: #define SFTP_EXT_FSYNC "fsync@openssh.com"
181: 	struct sshfs_io *sio;
194: 	struct sshfs_io sio;
314: 	"FingerprintHash",
318: 	"HostbasedAuthentication",
319: 	"HostbasedKeyTypes",
320: 	"HostKeyAlgorithms",
321: 	"HostKeyAlias",
322: 	"HostName",
333: 	"NoHostAuthenticationForLocalhost",
382: 	SSHFS_OPT("directport=%s",     directport, 0),
384: 	SSHFS_OPT("sftp_server=%s",    sftp_server, 0),
385: 	SSHFS_OPT("max_read=%u",       max_read, 0),
386: 	SSHFS_OPT("max_write=%u",      max_write, 0),
389: 	SSHFS_OPT("workaround=%s",     workarounds, 0),
390: 	SSHFS_OPT("idmap=none",        idmap, IDMAP_NONE),
391: 	SSHFS_OPT("idmap=user",        idmap, IDMAP_USER),
392: 	SSHFS_OPT("idmap=file",        idmap, IDMAP_FILE),
393: 	SSHFS_OPT("uidfile=%s",        uid_file, 0),
394: 	SSHFS_OPT("gidfile=%s",        gid_file, 0),
395: 	SSHFS_OPT("nomap=ignore",      nomap, NOMAP_IGNORE),
396: 	SSHFS_OPT("nomap=error",       nomap, NOMAP_ERROR),
397: 	SSHFS_OPT("sshfs_sync",        sync_write, 1),
398: 	SSHFS_OPT("no_readahead",      sync_read, 1),
399: 	SSHFS_OPT("sync_readdir",      sync_readdir, 1),
400: 	SSHFS_OPT("sshfs_debug",       debug, 1),
401: 	SSHFS_OPT("reconnect",         reconnect, 1),
402: 	SSHFS_OPT("transform_symlinks", transform_symlinks, 1),
403: 	SSHFS_OPT("follow_symlinks",   follow_symlinks, 1),
404: 	SSHFS_OPT("no_check_root",     no_check_root, 1),
405: 	SSHFS_OPT("password_stdin",    password_stdin, 1),
406: 	SSHFS_OPT("delay_connect",     delay_connect, 1),
407: 	SSHFS_OPT("slave",             slave, 1),
408: 	SSHFS_OPT("disable_hardlink",  disable_hardlink, 1),
409: 	SSHFS_OPT("dir_cache=yes", dir_cache, 1),
410: 	SSHFS_OPT("dir_cache=no",  dir_cache, 0),
412: 	SSHFS_OPT("-h",		show_help, 1),
413: 	SSHFS_OPT("--help",	show_help, 1),
414: 	SSHFS_OPT("-V",		show_version, 1),
415: 	SSHFS_OPT("--version",	show_version, 1),
416: 	SSHFS_OPT("-d",		debug, 1),
417: 	SSHFS_OPT("debug",	debug, 1),
418: 	SSHFS_OPT("-f",		foreground, 1),
419: 	SSHFS_OPT("-s",		singlethread, 1),
426: 	SSHFS_OPT("cache=yes", dir_cache, 1),
427: 	SSHFS_OPT("cache=no",  dir_cache, 0),
444: 	SSHFS_OPT("none",       rename_workaround, 0),
445: 	SSHFS_OPT("none",       truncate_workaround, 0),
446: 	SSHFS_OPT("none",       buflimit_workaround, 0),
447: 	SSHFS_OPT("none",       fstat_workaround, 0),
448: 	SSHFS_OPT("rename",     rename_workaround, 1),
449: 	SSHFS_OPT("norename",   rename_workaround, 0),
450: 	SSHFS_OPT("renamexdev",   renamexdev_workaround, 1),
451: 	SSHFS_OPT("norenamexdev", renamexdev_workaround, 0),
452: 	SSHFS_OPT("truncate",   truncate_workaround, 1),
453: 	SSHFS_OPT("notruncate", truncate_workaround, 0),
454: 	SSHFS_OPT("buflimit",   buflimit_workaround, 1),
455: 	SSHFS_OPT("nobuflimit", buflimit_workaround, 0),
456: 	SSHFS_OPT("fstat",      fstat_workaround, 1),
457: 	SSHFS_OPT("nofstat",    fstat_workaround, 0),
458: 	SSHFS_OPT("createmode",   createmode_workaround, 1),
459: 	SSHFS_OPT("nocreatemode", createmode_workaround, 0),
464: 	do { if (sshfs.debug) fprintf(stderr, format, args); } while(0)
546: 	switch (sshfs.nomap) {
560: 			fprintf(stderr, "sshfs: memory allocation failed\n");
590: 		fprintf(stderr, "sshfs: memory allocation failed\n");
653: 	if (sshfs.base_path[0]) {
655: 			if (sshfs.base_path[strlen(sshfs.base_path)-1] != '/') {
657: 							   sshfs.base_path,
661: 							   sshfs.base_path,
665: 			realpath = g_strdup(sshfs.base_path);
790: 	if (sshfs.remote_uid_detected) {
791: 		if (uid == sshfs.remote_uid)
792: 			uid = sshfs.local_uid;
793: 		if (gid == sshfs.remote_gid)
794: 			gid = sshfs.local_gid;
796: 	if (sshfs.idmap == IDMAP_FILE && sshfs.uid_map)
797: 		if (translate_id(&uid, sshfs.uid_map) == -1)
799: 	if (sshfs.idmap == IDMAP_FILE && sshfs.gid_map)
800: 		if (translate_id(&gid, sshfs.gid_map) == -1)
807: 	if (sshfs.blksize) {
808: 		stbuf->st_blksize = sshfs.blksize;
809: 		stbuf->st_blocks = ((size + sshfs.blksize - 1) &
810: 			~((unsigned long long) sshfs.blksize - 1)) >> 9;
881: 				if (sshfs.follow_symlinks &&
915: 		fds[0].fd = sshfs.rfd;
917: 		fds[1].fd = sshfs.ptyfd;
938: 		res = read(sshfs.ptyfd, &c, 1);
951: 				write(sshfs.ptyfd, sshfs.password,
952: 				      strlen(sshfs.password));
959: 	if (!sshfs.reconnect) {
962: 		memset(sshfs.password, 0, size);
963: 		munmap(sshfs.password, size);
964: 		sshfs.password = NULL;
997: 		fprintf(stderr, "sshfs: memory allocation failed\n");
1008: 	if (sshfs.password_stdin) {
1010: 		sshfs.ptyfd = pty_master(&ptyname);
1011: 		if (sshfs.ptyfd == -1)
1014: 		sshfs.ptyslavefd = open(ptyname, O_RDWR | O_NOCTTY);
1015: 		if (sshfs.ptyslavefd == -1)
1023: 	sshfs.rfd = sockpair[0];
1024: 	sshfs.wfd = sockpair[0];
1040: 		if (!sshfs.foreground && devnull != -1)
1058: 		if (sshfs.password_stdin) {
1068: 			close(sshfs.ptyslavefd);
1069: 			close(sshfs.ptyfd);
1072: 		if (sshfs.debug) {
1094: 	sshfs.rfd = STDIN_FILENO;
1095: 	sshfs.wfd = STDOUT_FILENO;
1133: 	sshfs.rfd = sock;
1134: 	sshfs.wfd = sock;
1142: 		res = writev(sshfs.wfd, iov, count);
1206: 	pthread_mutex_lock(&sshfs.lock_write);
1208: 	pthread_mutex_unlock(&sshfs.lock_write);
1219: 		res = read(sshfs.rfd, p, size);
1287: 	pthread_mutex_lock(&sshfs.lock);
1289: 	pthread_mutex_unlock(&sshfs.lock);
1323: 	pthread_mutex_lock(&sshfs.lock);
1331: 		was_over = sshfs.outstanding_len > sshfs.max_outstanding_len;
1332: 		sshfs.outstanding_len -= req->len;
1334: 		    sshfs.outstanding_len <= sshfs.max_outstanding_len) {
1335: 			pthread_cond_broadcast(&sshfs.outstanding_cond);
1339: 	pthread_mutex_unlock(&sshfs.lock);
1341: 		if (sshfs.debug) {
1352: 			if (difftime < sshfs.min_rtt || !sshfs.num_received)
1353: 				sshfs.min_rtt = difftime;
1354: 			if (difftime > sshfs.max_rtt)
1355: 				sshfs.max_rtt = difftime;
1356: 			sshfs.total_rtt += difftime;
1357: 			sshfs.num_received++;
1358: 			sshfs.bytes_received += msgsize;
1367: 				pthread_mutex_lock(&sshfs.lock);
1369: 				pthread_mutex_unlock(&sshfs.lock);
1381: 	close(sshfs.rfd);
1382: 	if (sshfs.rfd != sshfs.wfd)
1383: 		close(sshfs.wfd);
1384: 	sshfs.rfd = -1;
1385: 	sshfs.wfd = -1;
1386: 	if (sshfs.ptyfd != -1) {
1387: 		close(sshfs.ptyfd);
1388: 		sshfs.ptyfd = -1;
1390: 	if (sshfs.ptyslavefd != -1) {
1391: 		close(sshfs.ptyslavefd);
1392: 		sshfs.ptyslavefd = -1;
1405: 	pthread_mutex_lock(&sshfs.lock);
1406: 	sshfs.processing_thread_started = 0;
1409: 	sshfs.connver ++;
1410: 	sshfs.outstanding_len = 0;
1411: 	pthread_cond_broadcast(&sshfs.outstanding_cond);
1412: 	pthread_mutex_unlock(&sshfs.lock);
1414: 	if (!sshfs.reconnect) {
1466: 				sshfs.ext_posix_rename = 1;
1467: 				sshfs.rename_workaround = 0;
1471: 				sshfs.ext_statvfs = 1;
1474: 				sshfs.ext_hardlink = 1;
1477: 				sshfs.ext_fsync = 1;
1519: 	if (sshfs.password_stdin && pty_expect_loop() == -1)
1525: 	sshfs.server_version = version;
1595: 	sshfs.remote_uid = stbuf.st_uid;
1596: 	sshfs.local_uid = getuid();
1597: 	sshfs.remote_gid = stbuf.st_gid;
1598: 	sshfs.local_gid = getgid();
1599: 	sshfs.remote_uid_detected = 1;
1600: 	DEBUG("remote_uid = %i\n", sshfs.remote_uid);
1603: 	if (!sshfs.remote_uid_detected)
1676: 	if (sshfs.slave)
1678: 	else if (sshfs.directport)
1688: 		sshfs.num_connect++;
1700: 	if (sshfs.processing_thread_started)
1703: 	if (sshfs.rfd == -1) {
1709: 	if (sshfs.detect_uid) {
1711: 		sshfs.detect_uid = 0;
1727: 	sshfs.processing_thread_started = 1;
1734: 	/* Readahead should be done by kernel or sshfs but not both */
1736: 		sshfs.sync_read = 1;
1739:         cfg->nullpath_ok = ~(sshfs.truncate_workaround || sshfs.fstat_workaround);
1744: 	if (!sshfs.delay_connect)
1811: 		pthread_mutex_lock(&sshfs.lock);
1813: 		pthread_mutex_unlock(&sshfs.lock);
1833: 	pthread_mutex_lock(&sshfs.lock);
1840: 		pthread_mutex_unlock(&sshfs.lock);
1844: 	sshfs.outstanding_len += req->len;
1845: 	while (sshfs.outstanding_len > sshfs.max_outstanding_len)
1846: 		pthread_cond_wait(&sshfs.outstanding_cond, &sshfs.lock);
1849: 	if (sshfs.debug) {
1851: 		sshfs.num_sent++;
1852: 		sshfs.bytes_sent += req->len;
1855: 	pthread_mutex_unlock(&sshfs.lock);
1861: 		pthread_mutex_lock(&sshfs.lock);
1863: 		pthread_mutex_unlock(&sshfs.lock);
1915: 		err = sshfs.op->getattr(path, &stbuf, NULL);
1953: 	const char *b = sshfs.base_path;
1974: 		fprintf(stderr, "sshfs: memory allocation failed\n");
1999: 	if (sshfs.server_version < 3)
2011: 			if (sshfs.transform_symlinks)
2083: 				pthread_mutex_lock(&sshfs.lock);
2084: 				if (sshfs_req_pending(req))
2087: 				pthread_mutex_unlock(&sshfs.lock);
2170: 	if (sshfs.sync_readdir)
2239: 	if (sshfs.server_version < 3)
2242: 	/* openssh sftp server doesn't follow standard: link target and
2303: 		*str++ = (char)('0' + rand_r(&sshfs.randseed) % 10);
2314: 	if (sshfs.ext_posix_rename)
2315: 		err = sshfs_ext_posix_rename(from, to);
2317: 		err = sshfs_do_rename(from, to);
2318: 	if (err == -EPERM && sshfs.rename_workaround) {
2325: 			tmperr = sshfs_do_rename(to, totmp);
2327: 				err = sshfs_do_rename(from, to);
2329: 					err = sshfs_unlink(totmp);
2331: 					sshfs_do_rename(totmp, to);
2335: 	if (err == -EPERM && sshfs.renamexdev_workaround)
2344: 	if (sshfs.ext_hardlink && !sshfs.disable_hardlink) {
2363: 	pthread_mutex_lock(&sshfs.lock);
2364: 	ret = (sf->connver == sshfs.connver);
2365: 	pthread_mutex_unlock(&sshfs.lock);
2372: 	return (struct sshfs_file *) (uintptr_t) fi->fh;
2381: 	struct sshfs_file *sf = NULL;
2384: 		sf = get_sshfs_file(fi);
2385: 		if (!sshfs_file_is_conn(sf))
2411: 	struct sshfs_file *sf = NULL;
2414: 		sf = get_sshfs_file(fi);
2415: 		if (!sshfs_file_is_conn(sf))
2419: 	if (sshfs.remote_uid_detected) {
2420: 		if (uid == sshfs.local_uid)
2421: 			uid = sshfs.remote_uid;
2422: 		if (gid == sshfs.local_gid)
2423: 			gid = sshfs.remote_gid;
2425: 	if (sshfs.idmap == IDMAP_FILE && sshfs.r_uid_map)
2426: 		if(translate_id(&uid, sshfs.r_uid_map) == -1)
2428: 	if (sshfs.idmap == IDMAP_FILE && sshfs.r_gid_map)
2429: 		if (translate_id(&gid, sshfs.r_gid_map) == -1)
2447: static int sshfs_truncate_workaround(const char *path, off_t size,
2452: 	pthread_mutex_lock(&sshfs.lock);
2453: 	sshfs.modifver++;
2454: 	pthread_mutex_unlock(&sshfs.lock);
2463: 	struct sshfs_file *sf = NULL;
2474: 		sf = get_sshfs_file(fi);
2475: 		if (!sshfs_file_is_conn(sf))
2502: 	struct sshfs_file *sf;
2509: 	if (sshfs.dir_cache)
2533: 	sf = g_new0(struct sshfs_file, 1);
2540: 	pthread_mutex_lock(&sshfs.lock);
2541: 	sf->modifver= sshfs.modifver;
2542: 	sf->connver = sshfs.connver;
2543: 	pthread_mutex_unlock(&sshfs.lock);
2570: 		if (sshfs.dir_cache)
2575: 		if (sshfs.dir_cache)
2585: 	return sshfs_open_common(path, 0, fi);
2591: 	struct sshfs_file *sf = get_sshfs_file(fi);
2595: 	if (!sshfs_file_is_conn(sf))
2598: 	if (sshfs.sync_write)
2602: 	pthread_mutex_lock(&sshfs.lock);
2609: 			pthread_cond_wait(&sf->write_finished, &sshfs.lock);
2613: 	pthread_mutex_unlock(&sshfs.lock);
2623:         err = sshfs_flush(path, fi);
2627: 	if (!sshfs.ext_fsync)
2631: 	struct sshfs_file *sf = get_sshfs_file(fi);
2654: 	struct sshfs_file *sf = get_sshfs_file(fi);
2656: 	if (sshfs_file_is_conn(sf)) {
2657: 		sshfs_flush(path, fi);
2662: 	sshfs_file_put(sf);
2728: 		size_t bsize = size < sshfs.max_read ? size : sshfs.max_read;
2742: 					sshfs_read_begin,
2743: 					sshfs_read_end,
2762: 	pthread_mutex_lock(&sshfs.lock);
2764: 	       pthread_cond_wait(&chunk->sio.finished, &sshfs.lock);
2765: 	pthread_mutex_unlock(&sshfs.lock);
2820: 	chunk = sshfs_send_read(sf, size, offset);
2824: static void submit_read(struct sshfs_file *sf, size_t size, off_t offset,
2829: 	chunk = sshfs_send_read(sf, size, offset);
2830: 	pthread_mutex_lock(&sshfs.lock);
2831: 	chunk->modifver = sshfs.modifver;
2835: 	pthread_mutex_unlock(&sshfs.lock);
2838: static struct read_chunk *search_read_chunk(struct sshfs_file *sf, off_t offset)
2841: 	if (ch && ch->offset == offset && ch->modifver == sshfs.modifver) {
2858: 	pthread_mutex_lock(&sshfs.lock);
2860: 	sf->is_seq = (sf->next_pos == offset && sf->modifver == sshfs.modifver);
2862: 	sf->modifver = sshfs.modifver;
2864: 	pthread_mutex_unlock(&sshfs.lock);
2901: 	struct sshfs_file *sf = get_sshfs_file(fi);
2904: 	if (!sshfs_file_is_conn(sf))
2907: 	if (sshfs.sync_read)
2908: 		return sshfs_sync_read(sf, rbuf, size, offset);
2910: 		return sshfs_async_read(sf, rbuf, size, offset);
2915: 	struct sshfs_file *sf = (struct sshfs_file *) req->data;
2917: 	sshfs_file_get(sf);
2924: 	struct sshfs_file *sf = (struct sshfs_file *) req->data;
2938: 	sshfs_file_put(sf);
2950: 		size_t bsize = size < sshfs.max_write ? size : sshfs.max_write;
2960: 					sshfs_write_begin, sshfs_write_end,
2973: 	struct sshfs_io *sio = (struct sshfs_io *) req->data;
2980: 	struct sshfs_io *sio = (struct sshfs_io *) req->data;
3003: 	struct sshfs_io sio = { .error = 0, .num_reqs = 0 };
3010: 		size_t bsize = size < sshfs.max_write ? size : sshfs.max_write;
3020: 					sshfs_sync_write_begin,
3021: 					sshfs_sync_write_end,
3029: 	pthread_mutex_lock(&sshfs.lock);
3031: 	       pthread_cond_wait(&sio.finished, &sshfs.lock);
3032: 	pthread_mutex_unlock(&sshfs.lock);
3044: 	struct sshfs_file *sf = get_sshfs_file(fi);
3048: 	if (!sshfs_file_is_conn(sf))
3051: 	sshfs_inc_modifver();
3053: 	if (!sshfs.sync_write && !sf->write_error)
3054: 		err = sshfs_async_write(sf, wbuf, size, offset);
3056: 		err = sshfs_sync_write(sf, wbuf, size, offset);
3083: 	if (sshfs.ext_statvfs)
3084: 		return sshfs_ext_statvfs(path, buf);
3087: 	buf->f_bsize = sshfs.blksize;
3102: 	if (sshfs.createmode_workaround)
3105: 	return sshfs_open_common(path, mode, fi);
3113: 	struct sshfs_file *sf = NULL;
3116: 		sf = get_sshfs_file(fi);
3117: 		if (!sshfs_file_is_conn(sf))
3121: 	sshfs_inc_modifver();
3122: 	if (sshfs.truncate_workaround)
3123: 		return sshfs_truncate_workaround(path, size, fi);
3147: 	struct sshfs_file *sf = NULL;
3149: 	if (fi != NULL && !sshfs.fstat_workaround) {
3150: 		sf = get_sshfs_file(fi);
3151: 		if (!sshfs_file_is_conn(sf))
3183: 	err = sshfs_open(path, &fi);
3185: 		sshfs_release(path, &fi);
3192: 	return offset + sshfs.max_read < size ? sshfs.max_read : size - offset;
3207: 	res = sshfs_open(path, &fi);
3213: 		res = sshfs_read(path, data + offset, bufsize, offset, &fi);
3217: 	sshfs_release(path, &fi);
3222: 	res = sshfs_open(path, &fi);
3228: 		res = sshfs_write(path, data + offset, bufsize, offset, &fi);
3233: 		res = sshfs_flush(path, &fi);
3234: 	sshfs_release(path, &fi);
3251: 		res = sshfs_open(path, openfi);
3255: 	res = sshfs_write(path, &c, 1, size - 1, openfi);
3257: 		res = sshfs_flush(path, openfi);
3259: 		sshfs_release(path, openfi);
3280: 		return sshfs_truncate_zero(path);
3284: 		err = sshfs_getattr(path, &stbuf, fi);
3290: 			return sshfs_truncate_shrink(path, size);
3292: 			return sshfs_truncate_extend(path, size, fi);
3300: 	pthread_mutex_init(&sshfs.lock, NULL);
3301: 	pthread_mutex_init(&sshfs.lock_write, NULL);
3302: 	pthread_cond_init(&sshfs.outstanding_cond, NULL);
3304: 	if (!sshfs.reqtab) {
3312: 		.init       = sshfs_init,
3313: 		.getattr    = sshfs_getattr,
3314: 		.access     = sshfs_access,
3315: 		.opendir    = sshfs_opendir,
3316: 		.readdir    = sshfs_readdir,
3317: 		.releasedir = sshfs_releasedir,
3318: 		.readlink   = sshfs_readlink,
3319: 		.mknod      = sshfs_mknod,
3320: 		.mkdir      = sshfs_mkdir,
3321: 		.symlink    = sshfs_symlink,
3322: 		.unlink     = sshfs_unlink,
3323: 		.rmdir      = sshfs_rmdir,
3324: 		.rename     = sshfs_rename,
3325: 		.link       = sshfs_link,
3326: 		.chmod      = sshfs_chmod,
3327: 		.chown      = sshfs_chown,
3328: 		.truncate   = sshfs_truncate,
3329: 		.utimens    = sshfs_utimens,
3330: 		.open       = sshfs_open,
3331: 		.flush      = sshfs_flush,
3332: 		.fsync      = sshfs_fsync,
3333: 		.release    = sshfs_release,
3334: 		.read       = sshfs_read,
3335: 		.write      = sshfs_write,
3336: 		.statfs     = sshfs_statfs,
3337: 		.create     = sshfs_create,
3356: "    -o sshfs_sync          synchronous writes\n"
3442: 		else if (!sshfs.mountpoint) {
3452: 				sshfs.mountpoint = strdup(arg);
3469: 					asprintf(&sshfs.mountpoint, "%s%s%s", dir, slash, base);
3483:                                 sshfs.mountpoint = arg;
3485:                                 sshfs.mountpoint = realpath(arg, NULL);
3488: 			if (!sshfs.mountpoint) {
3489: 				fprintf(stderr, "sshfs: bad mount point `%s': %s\n",
3495: 		fprintf(stderr, "sshfs: invalid argument `%s'\n", arg);
3536: 	char *argv[] = { argv0, argv1, sshfs.workarounds, NULL };
3538: 	char *s = sshfs.workarounds;
3545: 	res = fuse_opt_parse(&args, &sshfs, workaround_opts,
3558: 	sshfs.password = mmap(NULL, size, PROT_READ | PROT_WRITE,
3561: 	if (sshfs.password == MAP_FAILED) {
3565: 	if (mlock(sshfs.password, size) != 0) {
3566: 		memset(sshfs.password, 0, size);
3567: 		munmap(sshfs.password, size);
3568: 		sshfs.password = NULL;
3577: 		res = read(0, &sshfs.password[n], 1);
3583: 			sshfs.password[n] = '\n';
3586: 		if (sshfs.password[n] == '\n')
3593: 	sshfs.password[n+1] = '\0';
3670: 					fprintf(stderr,	"missing ']' in hostname\n");
3711: 	if (!sshfs.delay_connect) {
3715: 		if (!sshfs.no_check_root &&
3716: 		    sftp_check_root(sshfs.base_path) != 0)
3857: 		fprintf(stderr, "sshfs: memory allocation failed\n");
3881: 		fprintf(stderr, "sshfs: memory allocation failed\n");
3890: 	read_id_map(sshfs.uid_file, &username_to_uid, "uid", &sshfs.uid_map, &sshfs.r_uid_map);
3895: 	read_id_map(sshfs.gid_file, &groupname_to_gid, "gid", &sshfs.gid_map, &sshfs.r_gid_map);
3913: 	if (!realpath(*exec_path, sshfs_program_path)) {
3914: 		memset(sshfs_program_path, 0, PATH_MAX);
3918: 	sshfs.blksize = 4096;
3920: 	sshfs.max_read = 32768;
3921: 	sshfs.max_write = 32768;
3923: 	sshfs.rename_workaround = 1;
3925: 	sshfs.rename_workaround = 0;
3927: 	sshfs.renamexdev_workaround = 0;
3928: 	sshfs.truncate_workaround = 0;
3929: 	sshfs.buflimit_workaround = 1;
3930: 	sshfs.createmode_workaround = 0;
3932: 	sshfs.progname = argv[0];
3933: 	sshfs.rfd = -1;
3934: 	sshfs.wfd = -1;
3935: 	sshfs.ptyfd = -1;
3936: 	sshfs.dir_cache = 1;
3937: 	sshfs.show_help = 0;
3938: 	sshfs.show_version = 0;
3939: 	sshfs.singlethread = 0;
3940: 	sshfs.foreground = 0;
3941: 	sshfs.ptyslavefd = -1;
3942: 	sshfs.delay_connect = 0;
3943: 	sshfs.slave = 0;
3944: 	sshfs.detect_uid = 0;
3946: 		sshfs.idmap = IDMAP_NONE;
3948: 		sshfs.idmap = IDMAP_USER;
3950: 		fprintf(stderr, "bad idmap default value built into sshfs; "
3952: 		sshfs.idmap = IDMAP_NONE;
3954: 	sshfs.nomap = NOMAP_ERROR;
3960: 	if (fuse_opt_parse(&args, &sshfs, sshfs_opts, sshfs_opt_proc) == -1 ||
3964: 	if (sshfs.show_version) {
3965: 		printf("SSHFS version %s\n", PACKAGE_VERSION);
3973: 	if (sshfs.show_help) {
3981: 	} else if (!sshfs.mountpoint) {
3987: 	if (sshfs.idmap == IDMAP_USER)
3988: 		sshfs.detect_uid = 1;
3989: 	else if (sshfs.idmap == IDMAP_FILE) {
3990: 		sshfs.uid_map = NULL;
3991: 		sshfs.gid_map = NULL;
3992: 		sshfs.r_uid_map = NULL;
3993: 		sshfs.r_gid_map = NULL;
3994: 		if (!sshfs.uid_file && !sshfs.gid_file) {
3998: 		if (sshfs.uid_file)
4000: 		if (sshfs.gid_file)
4003: 	free(sshfs.uid_file);
4004: 	free(sshfs.gid_file);
4006: 	DEBUG("SSHFS version %s\n", PACKAGE_VERSION);
4008: 	/* Force sshfs to the foreground when using stdin+stdout */
4009: 	if (sshfs.slave)
4010: 		sshfs.foreground = 1;
4013: 	if (sshfs.slave && sshfs.password_stdin) {
4018: 	if (sshfs.password_stdin) {
4024: 	if (sshfs.debug)
4025: 		sshfs.foreground = 1;
4027: 	if (sshfs.buflimit_workaround)
4028: 		/* Work around buggy sftp-server in OpenSSH.  Without this on
4031: 		sshfs.max_outstanding_len = 8388608;
4033: 		sshfs.max_outstanding_len = ~0;
4036: 	sshfs.base_path = g_strdup(find_base_path());
4045: 	if (sshfs.sftp_server)
4046: 		sftp_server = sshfs.sftp_server;
4056: 	free(sshfs.sftp_server);
4062: 	sshfs.randseed = time(0);
4064: 	if (sshfs.max_read > 65536)
4065: 		sshfs.max_read = 65536;
4066: 	if (sshfs.max_write > 65536)
4067: 		sshfs.max_write = 65536;
4070: 	tmp = g_strdup_printf("-osubtype=sshfs,fsname=%s", fsname);
4075: 	if(sshfs.dir_cache)
4076: 		sshfs.op = cache_wrap(&sshfs_oper);
4078: 		sshfs.op = &sshfs_oper;
4079: 	fuse = fuse_new(&args, sshfs.op,
4090: 	res = fuse_mount(fuse, sshfs.mountpoint);
4113: 	res = fuse_daemonize(sshfs.foreground);
4120: 	if (sshfs.singlethread)
4134: 	if (sshfs.debug) {
4137: 		if (sshfs.num_sent)
4138: 			avg_rtt = sshfs.total_rtt / sshfs.num_sent;
4145: 		      (unsigned long long) sshfs.num_sent,
4146: 		      (unsigned long long) sshfs.bytes_sent,
4147: 		      (unsigned long long) sshfs.num_received,
4148: 		      (unsigned long long) sshfs.bytes_received,
4149: 		      sshfs.min_rtt, sshfs.max_rtt, avg_rtt,
4150: 		      sshfs.num_connect);
4155: 	free(sshfs.directport);
237: 	GHashTable *uid_map;
238: 	GHashTable *gid_map;
239: 	GHashTable *r_uid_map;
240: 	GHashTable *r_gid_map;
254: 	GHashTable *reqtab;
304: 	"CheckHostIP",
315: 	"GlobalKnownHostsFile",
346: 	"RevokedHostKeys",
347: 	"RhostsRSAAuthentication",
352: 	"StrictHostKeyChecking",
354: 	"UpdateHostKeys",
356: 	"UserKnownHostsFile",
357: 	"VerifyHostKeyDNS",
358: 	"VisualHostKey",
539: static inline int translate_id(uint32_t *id, GHashTable *map)
3775: 		const char *name_id, GHashTable **idmap, GHashTable **r_idmap)
github.com/osxfuse/sshfs:sshfs.c: [ master, ]
248: 	char *host;
65: #define SSH_FXP_INIT                1
66: #define SSH_FXP_VERSION             2
67: #define SSH_FXP_OPEN                3
68: #define SSH_FXP_CLOSE               4
69: #define SSH_FXP_READ                5
70: #define SSH_FXP_WRITE               6
71: #define SSH_FXP_LSTAT               7
72: #define SSH_FXP_FSTAT               8
73: #define SSH_FXP_SETSTAT             9
74: #define SSH_FXP_FSETSTAT           10
75: #define SSH_FXP_OPENDIR            11
76: #define SSH_FXP_READDIR            12
77: #define SSH_FXP_REMOVE             13
78: #define SSH_FXP_MKDIR              14
79: #define SSH_FXP_RMDIR              15
80: #define SSH_FXP_REALPATH           16
81: #define SSH_FXP_STAT               17
82: #define SSH_FXP_RENAME             18
83: #define SSH_FXP_READLINK           19
84: #define SSH_FXP_SYMLINK            20
85: #define SSH_FXP_STATUS            101
86: #define SSH_FXP_HANDLE            102
87: #define SSH_FXP_DATA              103
88: #define SSH_FXP_NAME              104
89: #define SSH_FXP_ATTRS             105
90: #define SSH_FXP_EXTENDED          200
91: #define SSH_FXP_EXTENDED_REPLY    201
93: #define SSH_FILEXFER_ATTR_SIZE          0x00000001
94: #define SSH_FILEXFER_ATTR_UIDGID        0x00000002
95: #define SSH_FILEXFER_ATTR_PERMISSIONS   0x00000004
96: #define SSH_FILEXFER_ATTR_ACMODTIME     0x00000008
97: #define SSH_FILEXFER_ATTR_EXTENDED      0x80000000
99: #define SSH_FX_OK                            0
100: #define SSH_FX_EOF                           1
101: #define SSH_FX_NO_SUCH_FILE                  2
102: #define SSH_FX_PERMISSION_DENIED             3
103: #define SSH_FX_FAILURE                       4
104: #define SSH_FX_BAD_MESSAGE                   5
105: #define SSH_FX_NO_CONNECTION                 6
106: #define SSH_FX_CONNECTION_LOST               7
107: #define SSH_FX_OP_UNSUPPORTED                8
109: #define SSH_FXF_READ            0x00000001
110: #define SSH_FXF_WRITE           0x00000002
111: #define SSH_FXF_APPEND          0x00000004
112: #define SSH_FXF_CREAT           0x00000008
113: #define SSH_FXF_TRUNC           0x00000010
114: #define SSH_FXF_EXCL            0x00000020
117: #define SSH2_FXE_STATVFS_ST_RDONLY	0x00000001
118: #define SSH2_FXE_STATVFS_ST_NOSUID	0x00000002
214: 	char *ssh_command;
216: 	struct fuse_args ssh_args;
239: 	unsigned ssh_ver;
296: static const char *ssh_opts[] = {
874: static void ssh_add_arg(const char *arg)
1060: static int start_ssh(void)
3748: static int ssh_connect(void)
135: #define SSHNODELAY_SO "sshnodelay.so"
144: static char sshfs_program_path[PATH_MAX] = { 0 };
176: struct sshfs_io {
199: struct sshfs_file {
212: struct sshfs {
294: static struct sshfs sshfs;
365: #define SSHFS_OPT(t, p, v) { t, offsetof(struct sshfs, p), v }
367: static struct fuse_opt sshfs_opts[] = {
1819: static void *sshfs_init(struct fuse_conn_info *conn)
1992: static int sshfs_getattr(const char *path, struct stat *stbuf)
2012: static int sshfs_access(const char *path, int mask)
2094: static int sshfs_readlink(const char *path, char *linkbuf, size_t size)
2136: static int sshfs_req_pending(struct request *req)
2234: static int sshfs_getdir(const char *path, fuse_cache_dirh_t h,
2261: static int sshfs_mkdir(const char *path, mode_t mode)
2274: static int sshfs_mknod(const char *path, mode_t mode, dev_t rdev)
2303: static int sshfs_symlink(const char *from, const char *to)
2321: static int sshfs_unlink(const char *path)
2332: static int sshfs_rmdir(const char *path)
2343: static int sshfs_do_rename(const char *from, const char *to)
2355: static int sshfs_ext_posix_rename(const char *from, const char *to)
2376: static int sshfs_rename(const char *from, const char *to)
2403: static int sshfs_link(const char *from, const char *to)
2422: static int sshfs_chmod(const char *path, mode_t mode)
2436: static int sshfs_chown(const char *path, uid_t uid, gid_t gid)
2472: static void sshfs_inc_modifver(void)
2479: static int sshfs_truncate(const char *path, off_t size)
2497: static int sshfs_utime(const char *path, struct utimbuf *ubuf)
2511: static inline int sshfs_file_is_conn(struct sshfs_file *sf)
2522: static int sshfs_open_common(const char *path, mode_t mode,
2603: static int sshfs_open(const char *path, struct fuse_file_info *fi)
2613: static int sshfs_flush(const char *path, struct fuse_file_info *fi)
2642: static int sshfs_fsync(const char *path, int isdatasync,
2666: static void sshfs_file_put(struct sshfs_file *sf)
2673: static void sshfs_file_get(struct sshfs_file *sf)
2678: static int sshfs_release(const char *path, struct fuse_file_info *fi)
2692: static void sshfs_read_end(struct request *req)
2731: static void sshfs_read_begin(struct request *req)
2737: static struct read_chunk *sshfs_send_read(struct sshfs_file *sf, size_t size,
2841: static int sshfs_sync_read(struct sshfs_file *sf, char *buf, size_t size,
2874: static int sshfs_async_read(struct sshfs_file *sf, char *rbuf, size_t size,
2924: static int sshfs_read(const char *path, char *rbuf, size_t size, off_t offset,
2939: static void sshfs_write_begin(struct request *req)
2947: static void sshfs_write_end(struct request *req)
2967: static int sshfs_async_write(struct sshfs_file *sf, const char *wbuf,
2997: static void sshfs_sync_write_begin(struct request *req)
3003: static void sshfs_sync_write_end(struct request *req)
3024: static int sshfs_sync_write(struct sshfs_file *sf, const char *wbuf,
3066: static int sshfs_write(const char *path, const char *wbuf, size_t size,
3087: static int sshfs_ext_statvfs(const char *path, struct statvfs *stbuf)
3108: static int sshfs_statfs(const char *path, struct statvfs *buf)
3126: static int sshfs_statfs(const char *path, struct statfs *buf)
3155: static int sshfs_create(const char *path, mode_t mode,
3161: static int sshfs_ftruncate(const char *path, off_t size,
3188: static int sshfs_fgetattr(const char *path, struct stat *stbuf,
3218: static int sshfs_truncate_zero(const char *path)
3236: static int sshfs_truncate_shrink(const char *path, off_t size)
3282: static int sshfs_truncate_extend(const char *path, off_t size,
3317: static int sshfs_truncate_workaround(const char *path, off_t size,
3355: static struct fuse_cache_operations sshfs_oper = {
3471: static int sshfs_fuse_main(struct fuse_args *args)
3481: static int sshfs_opt_proc(void *data, const char *arg, int key,
881: static int do_ssh_nodelay_workaround(void)
3456: static int is_ssh_opt(const char *arg)
3645: static void set_ssh_command(void)
2608: static inline struct sshfs_file *get_sshfs_file(struct fuse_file_info *fi)
2:   SSH file system
369: 	SSHFS_OPT("ssh_command=%s",    ssh_command, 0),
373: 	SSHFS_OPT("ssh_protocol=%u",   ssh_ver, 0),
374: 	SSHFS_OPT("-1",                ssh_ver, 1),
443: 	case SSH_FXP_INIT:           return "INIT";
444: 	case SSH_FXP_VERSION:        return "VERSION";
445: 	case SSH_FXP_OPEN:           return "OPEN";
446: 	case SSH_FXP_CLOSE:          return "CLOSE";
447: 	case SSH_FXP_READ:           return "READ";
448: 	case SSH_FXP_WRITE:          return "WRITE";
449: 	case SSH_FXP_LSTAT:          return "LSTAT";
450: 	case SSH_FXP_FSTAT:          return "FSTAT";
451: 	case SSH_FXP_SETSTAT:        return "SETSTAT";
452: 	case SSH_FXP_FSETSTAT:       return "FSETSTAT";
453: 	case SSH_FXP_OPENDIR:        return "OPENDIR";
454: 	case SSH_FXP_READDIR:        return "READDIR";
455: 	case SSH_FXP_REMOVE:         return "REMOVE";
456: 	case SSH_FXP_MKDIR:          return "MKDIR";
457: 	case SSH_FXP_RMDIR:          return "RMDIR";
458: 	case SSH_FXP_REALPATH:       return "REALPATH";
459: 	case SSH_FXP_STAT:           return "STAT";
460: 	case SSH_FXP_RENAME:         return "RENAME";
461: 	case SSH_FXP_READLINK:       return "READLINK";
462: 	case SSH_FXP_SYMLINK:        return "SYMLINK";
463: 	case SSH_FXP_STATUS:         return "STATUS";
464: 	case SSH_FXP_HANDLE:         return "HANDLE";
465: 	case SSH_FXP_DATA:           return "DATA";
466: 	case SSH_FXP_NAME:           return "NAME";
467: 	case SSH_FXP_ATTRS:          return "ATTRS";
468: 	case SSH_FXP_EXTENDED:       return "EXTENDED";
469: 	case SSH_FXP_EXTENDED_REPLY: return "EXTENDED_REPLY";
516: 	if (g_hash_table_lookup_extended(map, GUINT_TO_POINTER(*id), NULL, &id_p)) {
733: 	if ((flags & SSH_FILEXFER_ATTR_SIZE) &&
736: 	if ((flags & SSH_FILEXFER_ATTR_UIDGID) &&
740: 	if ((flags & SSH_FILEXFER_ATTR_PERMISSIONS) &&
743: 	if ((flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
748: 	if ((flags & SSH_FILEXFER_ATTR_EXTENDED)) {
876: 	if (fuse_opt_add_arg(&sshfs.ssh_args, arg) == -1)
880: #ifdef SSH_NODELAY_WORKAROUND
948: 		fprintf(stderr, "warning: failed set DYLD_INSERT_LIBRARIES for ssh nodelay workaround\n");
952: 			"for ssh nodelay workaround\n");
988: 			 * Something happened on stdout of ssh, this
1092: #ifdef SSH_NODELAY_WORKAROUND
1094: 		    do_ssh_nodelay_workaround() == -1) {
1096: 				"warning: ssh nodelay workaround disabled\n");
1106: 			for (i = 1; i < sshfs.ssh_args.argc; i++) {
1107: 				if (strcmp(sshfs.ssh_args.argv[i], "-x") == 0) {
1108: 					replace_arg(&sshfs.ssh_args.argv[i],
1157: 			for (i = 0; i < sshfs.ssh_args.argc; i++)
1159: 					sshfs.ssh_args.argv[i]);
1163: 		execvp(sshfs.ssh_args.argv[0], sshfs.ssh_args.argv);
1165: 			sshfs.ssh_args.argv[0], strerror(errno));
1180: static int connect_to(char *host, char *port)
1191: 	err = getaddrinfo(host, port, &hint, &ai);
1193: 		fprintf(stderr, "failed to resolve %s:%s: %s\n", host, port,
1305: 			fprintf(stderr, "remote host has disconnected\n");
1405: 		g_hash_table_lookup(sshfs.reqtab, GUINT_TO_POINTER(id));
1417: 		g_hash_table_remove(sshfs.reqtab, GUINT_TO_POINTER(id));
1488: 	g_hash_table_foreach_remove(sshfs.reqtab, (GHRFunc) clean_req, NULL);
1515: 	if (type != SSH_FXP_VERSION)
1596: 	if (sftp_send_iov(SSH_FXP_INIT, PROTO_VERSION, NULL, 0) == -1)
1621: 	case SSH_FX_OK:                return 0;
1622: 	case SSH_FX_NO_SUCH_FILE:      return ENOENT;
1623: 	case SSH_FX_PERMISSION_DENIED: return EACCES;
1624: 	case SSH_FX_FAILURE:           return EPERM;
1625: 	case SSH_FX_BAD_MESSAGE:       return EBADMSG;
1626: 	case SSH_FX_NO_CONNECTION:     return ENOTCONN;
1627: 	case SSH_FX_CONNECTION_LOST:   return ECONNABORTED;
1628: 	case SSH_FX_OP_UNSUPPORTED:    return EOPNOTSUPP;
1646: 	if (sftp_send_iov(SSH_FXP_STAT, id, iov, 1) == -1)
1651: 	if (type != SSH_FXP_ATTRS && type != SSH_FXP_STATUS) {
1661: 	if (type == SSH_FXP_STATUS) {
1672: 	if (!(flags & SSH_FILEXFER_ATTR_UIDGID))
1706: 	if (sftp_send_iov(SSH_FXP_LSTAT, id, iov, 1) == -1)
1711: 	if (type != SSH_FXP_ATTRS && type != SSH_FXP_STATUS) {
1721: 	if (type == SSH_FXP_STATUS) {
1726: 		fprintf(stderr, "%s:%s: %s\n", sshfs.host, remote_dir,
1738: 	if (!(flags & SSH_FILEXFER_ATTR_PERMISSIONS))
1742: 		fprintf(stderr, "%s:%s: Not a directory\n", sshfs.host,
1748: 			sshfs.host, remote_dir);
1766: 		err = connect_to(sshfs.host, sshfs.directport);
1768: 		err = start_ssh();
1852: 	    req->reply_type != SSH_FXP_STATUS) {
1856: 	if (req->reply_type == SSH_FXP_STATUS) {
1862: 		case SSH_FX_OK:
1863: 			if (expect_type == SSH_FXP_STATUS)
1869: 		case SSH_FX_EOF:
1870: 			if (type == SSH_FXP_READ || type == SSH_FXP_READDIR)
1876: 		case SSH_FX_FAILURE:
1877: 			if (type == SSH_FXP_RMDIR)
1931: 	g_hash_table_insert(sshfs.reqtab, GUINT_TO_POINTER(id), req);
1945: 		rmed = g_hash_table_remove(sshfs.reqtab, GUINT_TO_POINTER(id));
1999: 	err = sftp_request(sshfs.follow_symlinks ? SSH_FXP_STAT : SSH_FXP_LSTAT,
2000: 			   &buf, SSH_FXP_ATTRS, &outbuf);
2107: 	err = sftp_request(SSH_FXP_READLINK, &buf, SSH_FXP_NAME, &name);
2132: 	return sftp_request_send(SSH_FXP_READDIR, &iov, 1, NULL, NULL,
2133: 				 SSH_FXP_NAME, NULL, req);
2138: 	if (g_hash_table_lookup(sshfs.reqtab, GUINT_TO_POINTER(req->id)))
2189: 			tmperr = sftp_request_wait(req, SSH_FXP_READDIR,
2190: 						    SSH_FXP_NAME, &name);
2222: 		err = sftp_request(SSH_FXP_READDIR, handle, SSH_FXP_NAME, &name);
2242: 	err = sftp_request(SSH_FXP_OPENDIR, &buf, SSH_FXP_HANDLE, &handle);
2252: 		err2 = sftp_request(SSH_FXP_CLOSE, &handle, 0, NULL);
2267: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2269: 	err = sftp_request(SSH_FXP_MKDIR, &buf, SSH_FXP_STATUS, NULL);
2286: 	buf_add_uint32(&buf, SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_EXCL);
2287: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2289: 	err = sftp_request(SSH_FXP_OPEN, &buf, SSH_FXP_HANDLE, &handle);
2293: 		err2 = sftp_request(SSH_FXP_CLOSE, &handle, SSH_FXP_STATUS,
2316: 	err = sftp_request(SSH_FXP_SYMLINK, &buf, SSH_FXP_STATUS, NULL);
2327: 	err = sftp_request(SSH_FXP_REMOVE, &buf, SSH_FXP_STATUS, NULL);
2338: 	err = sftp_request(SSH_FXP_RMDIR, &buf, SSH_FXP_STATUS, NULL);
2350: 	err = sftp_request(SSH_FXP_RENAME, &buf, SSH_FXP_STATUS, NULL);
2363: 	err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_STATUS, NULL);
2414: 		err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_STATUS,
2428: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2431: 	err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL);
2461: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_UIDGID);
2464: 	err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL);
2490: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_SIZE);
2492: 	err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL);
2503: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_ACMODTIME);
2506: 	err = sftp_request(SSH_FXP_SETSTAT, &buf, SSH_FXP_STATUS, NULL);
2538: 		pflags = SSH_FXF_READ;
2540: 		pflags = SSH_FXF_WRITE;
2542: 		pflags = SSH_FXF_READ | SSH_FXF_WRITE;
2547: 		pflags |= SSH_FXF_CREAT;
2550: 		pflags |= SSH_FXF_EXCL;
2553: 		pflags |= SSH_FXF_TRUNC;
2569: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_PERMISSIONS);
2572: 	sftp_request_send(SSH_FXP_OPEN, &iov, 1, NULL, NULL, 1, NULL,
2576: 	type = sshfs.follow_symlinks ? SSH_FXP_STAT : SSH_FXP_LSTAT;
2577: 	err2 = sftp_request(type, &buf, SSH_FXP_ATTRS, &outbuf);
2582: 	err = sftp_request_wait(open_req, SSH_FXP_OPEN, SSH_FXP_HANDLE,
2586: 		sftp_request(SSH_FXP_CLOSE, &sf->handle, 0, NULL);
2660: 		err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_STATUS, NULL);
2684: 		sftp_request(SSH_FXP_CLOSE, handle, 0, NULL);
2700: 		if (req->reply_type == SSH_FXP_STATUS) {
2703: 				if (serr == SSH_FX_EOF)
2708: 		} else if (req->reply_type == SSH_FXP_DATA) {
2767: 		err = sftp_request_send(SSH_FXP_READ, iov, 1,
2955: 		if (req->reply_type != SSH_FXP_STATUS) {
2958: 			 serr != SSH_FX_OK) {
2985: 		err = sftp_request_send(SSH_FXP_WRITE, iov, 2,
3011: 		if (req->reply_type != SSH_FXP_STATUS) {
3014: 			 serr != SSH_FX_OK) {
3045: 		err = sftp_request_send(SSH_FXP_WRITE, iov, 2,
3095: 	err = sftp_request(SSH_FXP_EXTENDED, &buf, SSH_FXP_EXTENDED_REPLY,
3179: 	buf_add_uint32(&buf, SSH_FILEXFER_ATTR_SIZE);
3181: 	err = sftp_request(SSH_FXP_FSETSTAT, &buf, SSH_FXP_STATUS, NULL);
3206: 	err = sftp_request(SSH_FXP_FSTAT, &buf, SSH_FXP_ATTRS, &outbuf);
3307:  * SSH_FILEXFER_ATTR_SIZE in SETSTAT request.
3347: 	sshfs.reqtab = g_hash_table_new(NULL, NULL);
3349: 		fprintf(stderr, "failed to create hash table\n");
3395: "usage: %s [user@]host:[dir] mountpoint [options]\n"
3405: "    -F ssh_configfile      specifies alternative ssh configuration file\n"
3406: "    -1                     equivalent to '-o ssh_protocol=1'\n"
3427: #ifdef SSH_NODELAY_WORKAROUND
3428: "             [no]nodelay      set nodelay tcp flag in ssh (default: on)\n"
3442: "    -o ssh_command=CMD     execute CMD instead of 'ssh'\n"
3443: "    -o ssh_protocol=N      ssh protocol to use (default: 2)\n"
3445: "    -o directport=PORT     directly connect to PORT bypassing ssh\n"
3452: "    -o SSHOPT=VAL          ssh options (see man ssh_config)\n"
3461: 		for (o = ssh_opts; *o; o++) {
3489: 		if (is_ssh_opt(arg)) {
3491: 			ssh_add_arg(tmp);
3498: 		if (!sshfs.host && strchr(arg, ':')) {
3499: 			sshfs.host = strdup(arg);
3506: 		ssh_add_arg(tmp);
3511: 		ssh_add_arg("-oCompression=yes");
3516: 		ssh_add_arg(tmp);
3640: 	ssh_add_arg("-oNumberOfPasswordPrompts=1");
3652: 	d = sshfs.ssh_command;
3653: 	s = sshfs.ssh_command;
3661: 				replace_arg(&sshfs.ssh_args.argv[0],
3662: 					    sshfs.ssh_command);
3664: 				if (fuse_opt_insert_arg(&sshfs.ssh_args, i,
3665: 						sshfs.ssh_command) == -1)
3669: 			d = sshfs.ssh_command;
3684: 	char *s = sshfs.host;
3822: 	*idmap = g_hash_table_new(NULL, NULL);
3823: 	*r_idmap = g_hash_table_new(NULL, NULL);
3872: 		g_hash_table_insert(*idmap, GUINT_TO_POINTER(remote_id), GUINT_TO_POINTER(*local_id));
3873: 		g_hash_table_insert(*r_idmap, GUINT_TO_POINTER(*local_id), GUINT_TO_POINTER(remote_id));
3976: 	sshfs.ssh_ver = 2;
3995: 	ssh_add_arg("ssh");
3996: 	ssh_add_arg("-x");
3997: 	ssh_add_arg("-a");
3998: 	ssh_add_arg("-oClearAllForwardings=yes");
4057: 	if (!sshfs.host) {
4058: 		fprintf(stderr, "missing host\n");
4063: 	fsname = g_strdup(sshfs.host);
4066: 	if (sshfs.ssh_command)
4067: 		set_ssh_command();
4069: 	tmp = g_strdup_printf("-%i", sshfs.ssh_ver);
4070: 	ssh_add_arg(tmp);
4072: 	ssh_add_arg(sshfs.host);
4075: 	else if (sshfs.ssh_ver == 1)
4080: 	if (sshfs.ssh_ver != 1 && strchr(sftp_server, '/') == NULL)
4081: 		ssh_add_arg("-s");
4083: 	ssh_add_arg(sftp_server);
4171: 		res = ssh_connect();
4204: 	res = ssh_connect();
4231: 	fuse_opt_free_args(&sshfs.ssh_args);
116: /* statvfs@openssh.com f_flag flags */
120: #define SFTP_EXT_POSIX_RENAME "posix-rename@openssh.com"
121: #define SFTP_EXT_STATVFS "statvfs@openssh.com"
122: #define SFTP_EXT_HARDLINK "hardlink@openssh.com"
123: #define SFTP_EXT_FSYNC "fsync@openssh.com"
183: 	struct sshfs_io *sio;
196: 	struct sshfs_io sio;
313: 	"HostbasedAuthentication",
314: 	"HostKeyAlgorithms",
315: 	"HostKeyAlias",
316: 	"HostName",
324: 	"NoHostAuthenticationForLocalhost",
368: 	SSHFS_OPT("directport=%s",     directport, 0),
370: 	SSHFS_OPT("sftp_server=%s",    sftp_server, 0),
371: 	SSHFS_OPT("max_read=%u",       max_read, 0),
372: 	SSHFS_OPT("max_write=%u",      max_write, 0),
375: 	SSHFS_OPT("workaround=%s",     workarounds, 0),
376: 	SSHFS_OPT("idmap=none",        idmap, IDMAP_NONE),
377: 	SSHFS_OPT("idmap=user",        idmap, IDMAP_USER),
378: 	SSHFS_OPT("idmap=file",        idmap, IDMAP_FILE),
379: 	SSHFS_OPT("uidfile=%s",        uid_file, 0),
380: 	SSHFS_OPT("gidfile=%s",        gid_file, 0),
381: 	SSHFS_OPT("nomap=ignore",      nomap, NOMAP_IGNORE),
382: 	SSHFS_OPT("nomap=error",       nomap, NOMAP_ERROR),
383: 	SSHFS_OPT("sshfs_sync",        sync_write, 1),
384: 	SSHFS_OPT("no_readahead",      sync_read, 1),
385: 	SSHFS_OPT("sync_readdir",      sync_readdir, 1),
386: 	SSHFS_OPT("sshfs_debug",       debug, 1),
387: 	SSHFS_OPT("reconnect",         reconnect, 1),
388: 	SSHFS_OPT("transform_symlinks", transform_symlinks, 1),
389: 	SSHFS_OPT("follow_symlinks",   follow_symlinks, 1),
390: 	SSHFS_OPT("no_check_root",     no_check_root, 1),
391: 	SSHFS_OPT("password_stdin",    password_stdin, 1),
392: 	SSHFS_OPT("delay_connect",     delay_connect, 1),
393: 	SSHFS_OPT("slave",             slave, 1),
394: 	SSHFS_OPT("disable_hardlink",  disable_hardlink, 1),
410: 	SSHFS_OPT("none",       rename_workaround, 0),
411: 	SSHFS_OPT("none",       nodelay_workaround, 0),
412: 	SSHFS_OPT("none",       nodelaysrv_workaround, 0),
413: 	SSHFS_OPT("none",       truncate_workaround, 0),
414: 	SSHFS_OPT("none",       buflimit_workaround, 0),
415: 	SSHFS_OPT("none",       fstat_workaround, 0),
416: 	SSHFS_OPT("all",        rename_workaround, 1),
417: 	SSHFS_OPT("all",        nodelay_workaround, 1),
418: 	SSHFS_OPT("all",        nodelaysrv_workaround, 1),
419: 	SSHFS_OPT("all",        truncate_workaround, 1),
420: 	SSHFS_OPT("all",        buflimit_workaround, 1),
421: 	SSHFS_OPT("all",        fstat_workaround, 1),
422: 	SSHFS_OPT("rename",     rename_workaround, 1),
423: 	SSHFS_OPT("norename",   rename_workaround, 0),
424: 	SSHFS_OPT("nodelay",    nodelay_workaround, 1),
425: 	SSHFS_OPT("nonodelay",  nodelay_workaround, 0),
426: 	SSHFS_OPT("nodelaysrv", nodelaysrv_workaround, 1),
427: 	SSHFS_OPT("nonodelaysrv", nodelaysrv_workaround, 0),
428: 	SSHFS_OPT("truncate",   truncate_workaround, 1),
429: 	SSHFS_OPT("notruncate", truncate_workaround, 0),
430: 	SSHFS_OPT("buflimit",   buflimit_workaround, 1),
431: 	SSHFS_OPT("nobuflimit", buflimit_workaround, 0),
432: 	SSHFS_OPT("fstat",      fstat_workaround, 1),
433: 	SSHFS_OPT("nofstat",    fstat_workaround, 0),
438: 	do { if (sshfs.debug) fprintf(stderr, format, args); } while(0)
520: 	switch (sshfs.nomap) {
534: 			fprintf(stderr, "sshfs: memory allocation failed\n");
564: 		fprintf(stderr, "sshfs: memory allocation failed\n");
627: 	if (sshfs.base_path[0]) {
629: 			if (sshfs.base_path[strlen(sshfs.base_path)-1] != '/') {
631: 							   sshfs.base_path,
635: 							   sshfs.base_path,
639: 			realpath = g_strdup(sshfs.base_path);
765: 	if (sshfs.remote_uid_detected) {
766: 		if (uid == sshfs.remote_uid)
767: 			uid = sshfs.local_uid;
768: 		if (gid == sshfs.remote_gid)
769: 			gid = sshfs.local_gid;
772: 	if (sshfs.remote_uid_detected && uid == sshfs.remote_uid)
773: 		uid = sshfs.local_uid;
775: 	if (sshfs.idmap == IDMAP_FILE && sshfs.uid_map)
776: 		if (translate_id(&uid, sshfs.uid_map) == -1)
778: 	if (sshfs.idmap == IDMAP_FILE && sshfs.gid_map)
779: 		if (translate_id(&gid, sshfs.gid_map) == -1)
786: 	if (sshfs.blksize) {
787: 		stbuf->st_blksize = sshfs.blksize;
788: 		stbuf->st_blocks = ((size + sshfs.blksize - 1) &
789: 			~((unsigned long long) sshfs.blksize - 1)) >> 9;
860: 				if (sshfs.follow_symlinks &&
893: 	char *sshfs_program_path_base = NULL;
894: 	if (!sshfs_program_path[0]) {
897: 	sshfs_program_path_base = dirname(sshfs_program_path);
898: 	if (!sshfs_program_path_base) {
901: 	snprintf(sopath, sizeof(sopath), "%s/%s", sshfs_program_path_base,
902:              SSHNODELAY_SO);
912: 	snprintf(sopath, sizeof(sopath), "%s/%s", LIBDIR, SSHNODELAY_SO);
916: 		if (!realpath(sshfs.progname, sopath))
925: 		if (s + strlen(SSHNODELAY_SO) >= sopath + sizeof(sopath))
928: 		strcpy(s, SSHNODELAY_SO);
931: 			fprintf(stderr, "sshfs: cannot find %s\n",
932: 				SSHNODELAY_SO);
973: 		fds[0].fd = sshfs.rfd;
975: 		fds[1].fd = sshfs.ptyfd;
996: 		res = read(sshfs.ptyfd, &c, 1);
1009: 				write(sshfs.ptyfd, sshfs.password,
1010: 				      strlen(sshfs.password));
1017: 	if (!sshfs.reconnect) {
1020: 		memset(sshfs.password, 0, size);
1021: 		munmap(sshfs.password, size);
1022: 		sshfs.password = NULL;
1055: 		fprintf(stderr, "sshfs: memory allocation failed\n");
1066: 	if (sshfs.password_stdin) {
1068: 		sshfs.ptyfd = pty_master(&ptyname);
1069: 		if (sshfs.ptyfd == -1)
1072: 		sshfs.ptyslavefd = open(ptyname, O_RDWR | O_NOCTTY);
1073: 		if (sshfs.ptyslavefd == -1)
1081: 	sshfs.rfd = sockpair[0];
1082: 	sshfs.wfd = sockpair[0];
1093: 		if (sshfs.nodelay_workaround &&
1100: 		if (sshfs.nodelaysrv_workaround) {
1104: 			 * setting in sshd
1121: 		if (!sshfs.foreground && devnull != -1)
1139: 		if (sshfs.password_stdin) {
1149: 			close(sshfs.ptyslavefd);
1150: 			close(sshfs.ptyfd);
1153: 		if (sshfs.debug) {
1175: 	sshfs.rfd = STDIN_FILENO;
1176: 	sshfs.wfd = STDOUT_FILENO;
1214: 	sshfs.rfd = sock;
1215: 	sshfs.wfd = sock;
1223: 		res = writev(sshfs.wfd, iov, count);
1287: 	pthread_mutex_lock(&sshfs.lock_write);
1289: 	pthread_mutex_unlock(&sshfs.lock_write);
1300: 		res = read(sshfs.rfd, p, size);
1368: 	pthread_mutex_lock(&sshfs.lock);
1370: 	pthread_mutex_unlock(&sshfs.lock);
1403: 	pthread_mutex_lock(&sshfs.lock);
1411: 		was_over = sshfs.outstanding_len > sshfs.max_outstanding_len;
1412: 		sshfs.outstanding_len -= req->len;
1414: 		    sshfs.outstanding_len <= sshfs.max_outstanding_len) {
1415: 			pthread_cond_broadcast(&sshfs.outstanding_cond);
1419: 	pthread_mutex_unlock(&sshfs.lock);
1421: 		if (sshfs.debug) {
1432: 			if (difftime < sshfs.min_rtt || !sshfs.num_received)
1433: 				sshfs.min_rtt = difftime;
1434: 			if (difftime > sshfs.max_rtt)
1435: 				sshfs.max_rtt = difftime;
1436: 			sshfs.total_rtt += difftime;
1437: 			sshfs.num_received++;
1438: 			sshfs.bytes_received += msgsize;
1447: 				pthread_mutex_lock(&sshfs.lock);
1449: 				pthread_mutex_unlock(&sshfs.lock);
1461: 	close(sshfs.rfd);
1462: 	if (sshfs.rfd != sshfs.wfd)
1463: 		close(sshfs.wfd);
1464: 	sshfs.rfd = -1;
1465: 	sshfs.wfd = -1;
1466: 	if (sshfs.ptyfd != -1) {
1467: 		close(sshfs.ptyfd);
1468: 		sshfs.ptyfd = -1;
1470: 	if (sshfs.ptyslavefd != -1) {
1471: 		close(sshfs.ptyslavefd);
1472: 		sshfs.ptyslavefd = -1;
1485: 	pthread_mutex_lock(&sshfs.lock);
1486: 	sshfs.processing_thread_started = 0;
1489: 	sshfs.connver ++;
1490: 	sshfs.outstanding_len = 0;
1491: 	pthread_cond_broadcast(&sshfs.outstanding_cond);
1492: 	pthread_mutex_unlock(&sshfs.lock);
1494: 	if (!sshfs.reconnect) {
1546: 				sshfs.ext_posix_rename = 1;
1547: 				sshfs.rename_workaround = 0;
1551: 				sshfs.ext_statvfs = 1;
1554: 				sshfs.ext_hardlink = 1;
1557: 				sshfs.ext_fsync = 1;
1599: 	if (sshfs.password_stdin && pty_expect_loop() == -1)
1605: 	sshfs.server_version = version;
1675: 	sshfs.remote_uid = stbuf.st_uid;
1676: 	sshfs.local_uid = getuid();
1678: 	sshfs.remote_gid = stbuf.st_gid;
1679: 	sshfs.local_gid = getgid();
1681: 	sshfs.remote_uid_detected = 1;
1682: 	DEBUG("remote_uid = %i\n", sshfs.remote_uid);
1685: 	if (!sshfs.remote_uid_detected)
1741: 	if (S_ISDIR(sshfs.mnt_mode) && !S_ISDIR(stbuf.st_mode)) {
1746: 	if ((sshfs.mnt_mode ^ stbuf.st_mode) & S_IFMT) {
1763: 	if (sshfs.slave)
1765: 	else if (sshfs.directport)
1775: 		sshfs.num_connect++;
1787: 	if (sshfs.processing_thread_started)
1790: 	if (sshfs.rfd == -1) {
1796: 	if (sshfs.detect_uid) {
1798: 		sshfs.detect_uid = 0;
1814: 	sshfs.processing_thread_started = 1;
1821: static void *sshfs_init(void)
1825: 	/* Readahead should be done by kernel or sshfs but not both */
1827: 		sshfs.sync_read = 1;
1830: 	if (!sshfs.delay_connect)
1894: 		pthread_mutex_lock(&sshfs.lock);
1896: 		pthread_mutex_unlock(&sshfs.lock);
1916: 	pthread_mutex_lock(&sshfs.lock);
1923: 		pthread_mutex_unlock(&sshfs.lock);
1927: 	sshfs.outstanding_len += req->len;
1928: 	while (sshfs.outstanding_len > sshfs.max_outstanding_len)
1929: 		pthread_cond_wait(&sshfs.outstanding_cond, &sshfs.lock);
1932: 	if (sshfs.debug) {
1934: 		sshfs.num_sent++;
1935: 		sshfs.bytes_sent += req->len;
1938: 	pthread_mutex_unlock(&sshfs.lock);
1944: 		pthread_mutex_lock(&sshfs.lock);
1946: 		pthread_mutex_unlock(&sshfs.lock);
2018: 		err = sshfs.op->getattr(path, &stbuf);
2056: 	const char *b = sshfs.base_path;
2077: 		fprintf(stderr, "sshfs: memory allocation failed\n");
2102: 	if (sshfs.server_version < 3)
2114: 			if (sshfs.transform_symlinks)
2181: 				pthread_mutex_lock(&sshfs.lock);
2182: 				if (sshfs_req_pending(req))
2184: 				pthread_mutex_unlock(&sshfs.lock);
2247: 		if (sshfs.sync_readdir)
2308: 	if (sshfs.server_version < 3)
2311: 	/* openssh sftp server doesn't follow standard: link target and
2372: 		*str++ = (char)('0' + rand_r(&sshfs.randseed) % 10);
2379: 	if (sshfs.ext_posix_rename)
2380: 		err = sshfs_ext_posix_rename(from, to);
2382: 		err = sshfs_do_rename(from, to);
2383: 	if (err == -EPERM && sshfs.rename_workaround) {
2390: 			tmperr = sshfs_do_rename(to, totmp);
2392: 				err = sshfs_do_rename(from, to);
2394: 					err = sshfs_unlink(totmp);
2396: 					sshfs_do_rename(totmp, to);
2407: 	if (sshfs.ext_hardlink && !sshfs.disable_hardlink) {
2442: 	if (sshfs.remote_uid_detected) {
2443: 		if (uid == sshfs.local_uid)
2444: 			uid = sshfs.remote_uid;
2445: 		if (gid == sshfs.local_gid)
2446: 			gid = sshfs.remote_gid;
2449: 	if (sshfs.remote_uid_detected && uid == sshfs.local_uid)
2450: 		uid = sshfs.remote_uid;
2452: 	if (sshfs.idmap == IDMAP_FILE && sshfs.r_uid_map)
2453: 		if(translate_id(&uid, sshfs.r_uid_map) == -1)
2455: 	if (sshfs.idmap == IDMAP_FILE && sshfs.r_gid_map)
2456: 		if (translate_id(&gid, sshfs.r_gid_map) == -1)
2469: static int sshfs_truncate_workaround(const char *path, off_t size,
2474: 	pthread_mutex_lock(&sshfs.lock);
2475: 	sshfs.modifver++;
2476: 	pthread_mutex_unlock(&sshfs.lock);
2484: 	sshfs_inc_modifver();
2485: 	if (size == 0 || sshfs.truncate_workaround)
2486: 		return sshfs_truncate_workaround(path, size, NULL);
2515: 	pthread_mutex_lock(&sshfs.lock);
2516: 	ret = (sf->connver == sshfs.connver);
2517: 	pthread_mutex_unlock(&sshfs.lock);
2530: 	struct sshfs_file *sf;
2555: 	sf = g_new0(struct sshfs_file, 1);
2562: 	pthread_mutex_lock(&sshfs.lock);
2563: 	sf->modifver= sshfs.modifver;
2564: 	sf->connver = sshfs.connver;
2565: 	pthread_mutex_unlock(&sshfs.lock);
2605: 	return sshfs_open_common(path, 0, fi);
2610: 	return (struct sshfs_file *) (uintptr_t) fi->fh;
2616: 	struct sshfs_file *sf = get_sshfs_file(fi);
2620: 	if (!sshfs_file_is_conn(sf))
2623: 	if (sshfs.sync_write)
2627: 	pthread_mutex_lock(&sshfs.lock);
2634: 			pthread_cond_wait(&sf->write_finished, &sshfs.lock);
2638: 	pthread_mutex_unlock(&sshfs.lock);
2648: 	if (err = sshfs_flush(path, fi))
2651: 	if (!sshfs.ext_fsync)
2656: 		struct sshfs_file *sf = get_sshfs_file(fi);
2680: 	struct sshfs_file *sf = get_sshfs_file(fi);
2682: 	if (sshfs_file_is_conn(sf)) {
2683: 		sshfs_flush(path, fi);
2688: 	sshfs_file_put(sf);
2754: 		size_t bsize = size < sshfs.max_read ? size : sshfs.max_read;
2768: 					sshfs_read_begin,
2769: 					sshfs_read_end,
2788: 	pthread_mutex_lock(&sshfs.lock);
2790: 	       pthread_cond_wait(&chunk->sio.finished, &sshfs.lock);
2791: 	pthread_mutex_unlock(&sshfs.lock);
2846: 	chunk = sshfs_send_read(sf, size, offset);
2850: static void submit_read(struct sshfs_file *sf, size_t size, off_t offset,
2855: 	chunk = sshfs_send_read(sf, size, offset);
2856: 	pthread_mutex_lock(&sshfs.lock);
2857: 	chunk->modifver = sshfs.modifver;
2861: 	pthread_mutex_unlock(&sshfs.lock);
2864: static struct read_chunk *search_read_chunk(struct sshfs_file *sf, off_t offset)
2867: 	if (ch && ch->offset == offset && ch->modifver == sshfs.modifver) {
2884: 	pthread_mutex_lock(&sshfs.lock);
2886: 	sf->is_seq = (sf->next_pos == offset && sf->modifver == sshfs.modifver);
2888: 	sf->modifver = sshfs.modifver;
2890: 	pthread_mutex_unlock(&sshfs.lock);
2927: 	struct sshfs_file *sf = get_sshfs_file(fi);
2930: 	if (!sshfs_file_is_conn(sf))
2933: 	if (sshfs.sync_read)
2934: 		return sshfs_sync_read(sf, rbuf, size, offset);
2936: 		return sshfs_async_read(sf, rbuf, size, offset);
2941: 	struct sshfs_file *sf = (struct sshfs_file *) req->data;
2943: 	sshfs_file_get(sf);
2950: 	struct sshfs_file *sf = (struct sshfs_file *) req->data;
2964: 	sshfs_file_put(sf);
2976: 		size_t bsize = size < sshfs.max_write ? size : sshfs.max_write;
2986: 					sshfs_write_begin, sshfs_write_end,
2999: 	struct sshfs_io *sio = (struct sshfs_io *) req->data;
3006: 	struct sshfs_io *sio = (struct sshfs_io *) req->data;
3029: 	struct sshfs_io sio = { .error = 0, .num_reqs = 0 };
3036: 		size_t bsize = size < sshfs.max_write ? size : sshfs.max_write;
3046: 					sshfs_sync_write_begin,
3047: 					sshfs_sync_write_end,
3055: 	pthread_mutex_lock(&sshfs.lock);
3057: 	       pthread_cond_wait(&sio.finished, &sshfs.lock);
3058: 	pthread_mutex_unlock(&sshfs.lock);
3070: 	struct sshfs_file *sf = get_sshfs_file(fi);
3074: 	if (!sshfs_file_is_conn(sf))
3077: 	sshfs_inc_modifver();
3079: 	if (!sshfs.sync_write && !sf->write_error)
3080: 		err = sshfs_async_write(sf, wbuf, size, offset);
3082: 		err = sshfs_sync_write(sf, wbuf, size, offset);
3110: 	if (sshfs.ext_statvfs)
3111: 		return sshfs_ext_statvfs(path, buf);
3114: 	buf->f_bsize = sshfs.blksize;
3128: 	if (sshfs.ext_statvfs) {
3132: 		err = sshfs_ext_statvfs(path, &vbuf);
3146: 	buf->f_bsize = sshfs.blksize;
3158: 	return sshfs_open_common(path, mode, fi);
3166: 	struct sshfs_file *sf = get_sshfs_file(fi);
3170: 	if (!sshfs_file_is_conn(sf))
3173: 	sshfs_inc_modifver();
3174: 	if (sshfs.truncate_workaround)
3175: 		return sshfs_truncate_workaround(path, size, fi);
3194: 	struct sshfs_file *sf = get_sshfs_file(fi);
3198: 	if (!sshfs_file_is_conn(sf))
3201: 	if (sshfs.fstat_workaround)
3202: 		return sshfs_getattr(path, stbuf);
3224: 	err = sshfs_open(path, &fi);
3226: 		sshfs_release(path, &fi);
3233: 	return offset + sshfs.max_read < size ? sshfs.max_read : size - offset;
3248: 	res = sshfs_open(path, &fi);
3254: 		res = sshfs_read(path, data + offset, bufsize, offset, &fi);
3258: 	sshfs_release(path, &fi);
3263: 	res = sshfs_open(path, &fi);
3269: 		res = sshfs_write(path, data + offset, bufsize, offset, &fi);
3274: 		res = sshfs_flush(path, &fi);
3275: 	sshfs_release(path, &fi);
3292: 		res = sshfs_open(path, openfi);
3296: 	res = sshfs_write(path, &c, 1, size - 1, openfi);
3298: 		res = sshfs_flush(path, openfi);
3300: 		sshfs_release(path, openfi);
3321: 		return sshfs_truncate_zero(path);
3326: 			err = sshfs_fgetattr(path, &stbuf, fi);
3328: 			err = sshfs_getattr(path, &stbuf);
3334: 			return sshfs_truncate_shrink(path, size);
3336: 			return sshfs_truncate_extend(path, size, fi);
3344: 	pthread_mutex_init(&sshfs.lock, NULL);
3345: 	pthread_mutex_init(&sshfs.lock_write, NULL);
3346: 	pthread_cond_init(&sshfs.outstanding_cond, NULL);
3348: 	if (!sshfs.reqtab) {
3357: 		.init       = sshfs_init,
3358: 		.getattr    = sshfs_getattr,
3359: 		.access     = sshfs_access,
3360: 		.readlink   = sshfs_readlink,
3361: 		.mknod      = sshfs_mknod,
3362: 		.mkdir      = sshfs_mkdir,
3363: 		.symlink    = sshfs_symlink,
3364: 		.unlink     = sshfs_unlink,
3365: 		.rmdir      = sshfs_rmdir,
3366: 		.rename     = sshfs_rename,
3367: 		.link       = sshfs_link,
3368: 		.chmod      = sshfs_chmod,
3369: 		.chown      = sshfs_chown,
3370: 		.truncate   = sshfs_truncate,
3371: 		.utime      = sshfs_utime,
3372: 		.open       = sshfs_open,
3373: 		.flush      = sshfs_flush,
3374: 		.fsync      = sshfs_fsync,
3375: 		.release    = sshfs_release,
3376: 		.read       = sshfs_read,
3377: 		.write      = sshfs_write,
3378: 		.statfs     = sshfs_statfs,
3380: 		.create     = sshfs_create,
3381: 		.ftruncate  = sshfs_ftruncate,
3382: 		.fgetattr   = sshfs_fgetattr,
3389: 	.cache_getdir = sshfs_getdir,
3402: "SSHFS options:\n"
3409: "    -o sshfs_sync          synchronous writes\n"
3412: "    -o sshfs_debug         print some debugging information\n"
3430: "             [no]nodelaysrv   set nodelay tcp flag in sshd (default: off)\n"
3473: 	sshfs.op = cache_init(&sshfs_oper);
3475: 	return fuse_main(args->argc, args->argv, sshfs.op, NULL);
3477: 	return fuse_main(args->argc, args->argv, sshfs.op);
3523: 		sshfs_fuse_main(outargs);
3527: 		printf("SSHFS version %s\n", PACKAGE_VERSION);
3530: 		sshfs_fuse_main(outargs);
3535: 		sshfs.foreground = 1;
3555: 	char *argv[] = { "", "-o", sshfs.workarounds, NULL };
3557: 	char *s = sshfs.workarounds;
3564: 	res = fuse_opt_parse(&args, &sshfs, workaround_opts,
3604: 	sshfs.password = mmap(NULL, size, PROT_READ | PROT_WRITE,
3607: 	if (sshfs.password == MAP_FAILED) {
3611: 	if (mlock(sshfs.password, size) != 0) {
3612: 		memset(sshfs.password, 0, size);
3613: 		munmap(sshfs.password, size);
3614: 		sshfs.password = NULL;
3623: 		res = read(0, &sshfs.password[n], 1);
3629: 			sshfs.password[n] = '\n';
3632: 		if (sshfs.password[n] == '\n')
3639: 	sshfs.password[n+1] = '\0';
3696: 					fprintf(stderr,	"missing ']' in hostname\n");
3756: 	if (!sshfs.delay_connect) {
3760: 		if (!sshfs.no_check_root &&
3761: 		    sftp_check_root(sshfs.base_path) != 0)
3902: 		fprintf(stderr, "sshfs: memory allocation failed\n");
3926: 		fprintf(stderr, "sshfs: memory allocation failed\n");
3935: 	read_id_map(sshfs.uid_file, &username_to_uid, "uid", &sshfs.uid_map, &sshfs.r_uid_map);
3940: 	read_id_map(sshfs.gid_file, &groupname_to_gid, "gid", &sshfs.gid_map, &sshfs.r_gid_map);
3957: 	if (!realpath(*exec_path, sshfs_program_path)) {
3958: 		memset(sshfs_program_path, 0, PATH_MAX);
3963: 	sshfs.blksize = 4096;
3965: 	sshfs.max_read = 32768;
3966: 	sshfs.max_write = 32768;
3967: 	sshfs.nodelay_workaround = 1;
3968: 	sshfs.nodelaysrv_workaround = 0;
3970: 	sshfs.rename_workaround = 1;
3972: 	sshfs.rename_workaround = 0;
3974: 	sshfs.truncate_workaround = 0;
3975: 	sshfs.buflimit_workaround = 1;
3977: 	sshfs.progname = argv[0];
3978: 	sshfs.rfd = -1;
3979: 	sshfs.wfd = -1;
3980: 	sshfs.ptyfd = -1;
3981: 	sshfs.ptyslavefd = -1;
3982: 	sshfs.delay_connect = 0;
3983: 	sshfs.slave = 0;
3984: 	sshfs.detect_uid = 0;
3986: 		sshfs.idmap = IDMAP_NONE;
3988: 		sshfs.idmap = IDMAP_USER;
3990: 		fprintf(stderr, "bad idmap default value built into sshfs; "
3992: 		sshfs.idmap = IDMAP_NONE;
3994: 	sshfs.nomap = NOMAP_ERROR;
4000: 	if (fuse_opt_parse(&args, &sshfs, sshfs_opts, sshfs_opt_proc) == -1 ||
4006: 	if (sshfs.truncate_workaround || sshfs.fstat_workaround) {
4007: 		sshfs_oper.oper.flag_nullpath_ok = 0;
4008: 		sshfs_oper.oper.flag_nopath = 0;
4012: 	if (sshfs.idmap == IDMAP_USER)
4013: 		sshfs.detect_uid = 1;
4014: 	else if (sshfs.idmap == IDMAP_FILE) {
4015: 		sshfs.uid_map = NULL;
4016: 		sshfs.gid_map = NULL;
4017: 		sshfs.r_uid_map = NULL;
4018: 		sshfs.r_gid_map = NULL;
4019: 		if (!sshfs.uid_file && !sshfs.gid_file) {
4023: 		if (sshfs.uid_file)
4025: 		if (sshfs.gid_file)
4028: 	free(sshfs.uid_file);
4029: 	free(sshfs.gid_file);
4031: 	DEBUG("SSHFS version %s\n", PACKAGE_VERSION);
4033: 	if (sshfs.slave) {
4034: 		/* Force sshfs to the foreground when using stdin+stdout */
4035: 		sshfs.foreground = 1;
4038: 	if (sshfs.slave && sshfs.password_stdin) {
4043: 	if (sshfs.password_stdin) {
4049: 	if (sshfs.buflimit_workaround)
4050: 		/* Work around buggy sftp-server in OpenSSH.  Without this on
4053: 		sshfs.max_outstanding_len = 8388608;
4055: 		sshfs.max_outstanding_len = ~0;
4064: 	sshfs.base_path = g_strdup(find_base_path());
4073: 	if (sshfs.sftp_server)
4074: 		sftp_server = sshfs.sftp_server;
4084: 	free(sshfs.sftp_server);
4091: 	sshfs.randseed = time(0);
4093: 	if (sshfs.max_read > 65536)
4094: 		sshfs.max_read = 65536;
4095: 	if (sshfs.max_write > 65536)
4096: 		sshfs.max_write = 65536;
4107: 	tmp = g_strdup_printf("-osubtype=sshfs,fsname=%s", fsname);
4110: 	tmp = g_strdup_printf("-ofsname=sshfs#%s", fsname);
4133: 		if (sshfs.slave) {
4134: 			/* Force sshfs to the foreground when using stdin+stdout */
4144: 		sshfs.mnt_mode = st.st_mode;
4146: 		sshfs.mnt_mode = S_IFDIR | 0755;
4159: 		sshfs.op = cache_init(&sshfs_oper);
4160: 		fuse = fuse_new(ch, &args, sshfs.op,
4208: 	res = sshfs_fuse_main(&args);
4211: 	if (sshfs.debug) {
4214: 		if (sshfs.num_sent)
4215: 			avg_rtt = sshfs.total_rtt / sshfs.num_sent;
4222: 		      (unsigned long long) sshfs.num_sent,
4223: 		      (unsigned long long) sshfs.bytes_sent,
4224: 		      (unsigned long long) sshfs.num_received,
4225: 		      (unsigned long long) sshfs.bytes_received,
4226: 		      sshfs.min_rtt, sshfs.max_rtt, avg_rtt,
4227: 		      sshfs.num_connect);
4232: 	free(sshfs.directport);
233: 	GHashTable *uid_map;
234: 	GHashTable *gid_map;
235: 	GHashTable *r_uid_map;
236: 	GHashTable *r_gid_map;
250: 	GHashTable *reqtab;
301: 	"CheckHostIP",
310: 	"GlobalKnownHostsFile",
332: 	"RhostsRSAAuthentication",
337: 	"StrictHostKeyChecking",
340: 	"UserKnownHostsFile",
341: 	"VerifyHostKeyDNS",
513: static inline int translate_id(uint32_t *id, GHashTable *map)
3820: 		const char *name_id, GHashTable **idmap, GHashTable **r_idmap)
android.googlesource.com/platform/tools/idea:platform/util/src/com/intellij/util/containers/ConcurrentHashMap.java: [ master, ]
565:     final int hash;
3868:   private int hash(K key) {
538:   static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash
589:     public final int hashCode() {
1343:   public int hashCode() {
3123:     public int hashCode() {
3466:     public int hashCode() {
3601:     public final int hashCode() {
232: public class ConcurrentHashMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V>, Serializable, TObjectHashingStrategy<K> {
234:   @NotNull private final TObjectHashingStrategy<K> myHashingStrategy;
569:     protected final TObjectHashingStrategy<K> myHashingStrategy;
802:   public ConcurrentHashMap() {
806:   public ConcurrentHashMap(@NotNull TObjectHashingStrategy<K> hashingStrategy) {
820:   public ConcurrentHashMap(int initialCapacity) {
836:   public ConcurrentHashMap(Map<? extends K, ? extends V> m) {
856:   public ConcurrentHashMap(int initialCapacity, float loadFactor) {
878:   public ConcurrentHashMap(int initialCapacity,
893:   public ConcurrentHashMap(int initialCapacity,
3656:   static final class CounterHashCode {
3663:   static final AtomicInteger counterHashCodeGenerator = new AtomicInteger();
3674:   static final ThreadLocal<CounterHashCode> threadCounterHashCode =
3852:   public int computeHashCode(final K object) {
37:  * A hash table supporting full concurrency of retrievals and
58:  * the hash table at some point at or since the creation of the
70:  * collisions (i.e., keys that have distinct hash codes but fall into
76:  * hash tables.  However, resizing this or any other kind of hash
88:  * hash table. To ameliorate impact, when keys are {@link Comparable},
239:    * The primary design goal of this hash table is to maintain
246:    * This map usually acts as a binned (bucketed) hash table.  Each
248:    * of the basic Node class with hash, key, value, and next
257:    * because they have negative hash fields and null key and value
270:    * We use the top (sign) bit of Node hash fields for control
272:    * constraints.  Nodes with negative hash fields are specially
278:    * key/hash distributions.  Other update operations (insert,
296:    * random hash codes, this is not a common problem.  Ideally, the
319:    * Actual hash code distributions encountered in practice
323:    * designed to have identical hash codes or ones that differs only
358:    * only a special forwarding node (with hash field "MOVED") that
398:    * bin already holding two or more nodes. Under uniform hash
409:    * this, the tree is ordered primarily by hash value, then by
413:    * hash values. (This corresponds to the full list search that
466:    * because the top two bits of 32bit hash fields are used for
533:    * Encodings for Node hash fields. See above for explanation.
535:   static final int MOVED = -1; // hash for forwarding nodes
536:   static final int TREEBIN = -2; // hash for roots of trees
537:   static final int RESERVED = -3; // hash for transient reservations
560:    * in bulk tasks.  Subclasses of Node with a negative hash field
571:     Node(int hash, K key, V val, Node<K, V> next, @NotNull TObjectHashingStrategy<K> hashingStrategy) {
572:       this.hash = hash;
622:           if (e.hash == h &&
636:    * Spreads (XORs) higher bits of hash to lower and also forces top
652:     return (h ^ h >>> 16) & HASH_BITS;
717:    * the form of a hash value anded with (length - 1) is a valid
946:     int h = hash((K)key);
951:       if ((eh = e.hash) == h) {
961:         if (e.hash == h &&
1034:     int hash = hash(key);
1044:       else if ((f = tabAt(tab, i = n - 1 & hash)) == null) {
1046:                      new Node<K, V>(hash, key, value, null,myHashingStrategy))) {
1050:       else if ((fh = f.hash) == MOVED) {
1061:                 if (e.hash == hash &&
1072:                   pred.next = new Node<K, V>(hash, key,
1081:               if ((p = ((TreeBin<K, V>)f).putTreeVal(hash, key,
1141:     int hash = hash((K)key);
1148:           (f = tabAt(tab, i = n - 1 & hash)) == null) {
1151:       else if ((fh = f.hash) == MOVED) {
1163:                 if (e.hash == hash &&
1194:                   (p = r.findTreeNode(hash, key, null)) != null) {
1238:       else if ((fh = f.hash) == MOVED) {
1337:    * Returns the hash code value for this {@link Map}, i.e.,
1341:    * @return the hash code value for this map
1349:         h += hash(p.key) ^ p.val.hashCode();
1512:         p = new Node<K, V>(hash(k), k, v, p,myHashingStrategy);
1539:         int h = p.hash;
1546:           if (first.hash < 0) {
1559:               if (q.hash == h &&
1575:                   (q.hash, q.key, q.val, null, null, myHashingStrategy);
1801:           if ((eh = e.hash) == h &&
2052:       else if ((fh = f.hash) == MOVED) {
2064:                 int b = p.hash & n;
2079:                 int ph = p.hash;
2103:                 int h = e.hash;
2158:       else if ((b = tabAt(tab, index)) != null && b.hash >= 0) {
2165:                 new TreeNode<K, V>(e.hash, e.key, e.val,
2189:       Node<K, V> p = new Node<K, V>(q.hash, q.key, q.val, null,q.myHashingStrategy);
2213:     TreeNode(int hash, K key, V val, Node<K, V> next,
2215:       super(hash, key, val, next, hashingStrategy);
2238:           if ((ph = p.hash) > h) {
2325:           int h = x.hash;
2331:             if ((ph = p.hash) > h) {
2415:             if (e.hash == h &&
2463:         else if ((ph = p.hash) > h) {
2883:       if (tl != null && (tl.parent != t || tl.hash > t.hash)) {
2886:       if (tr != null && (tr.parent != t || tr.hash < t.hash)) {
2975:         if ((e = tabAt(t, index)) != null && e.hash < 0) {
3652:    * Holder for the thread-local hash code determining which
3672:    * Per-thread counter hash codes. Shared across all instances.
39:  * same functional specification as {@link java.util.Hashtable}, and
41:  * {@code Hashtable}. However, even though all operations are
45:  * interoperable with {@code Hashtable} in programs that rely on its
87:  * {@code hashCode()} is a sure way to slow down performance of any
101:  * <p>Like {@link Hashtable} but unlike {@link java.util.HashMap}, this class
228: // added hashing strategy argument
243:    * the same or better than java.util.HashMap, and to support high
256:    * hashes, and are readily distinguishable during search etc
317:    * elements is roughly 1 / (8 * #elements) under random hashes.
322:    * Similarly for dumb or hostile usages in which multiple keys are
415:    * tied hashes.) On insertion, to keep a total ordering (or as
576:       myHashingStrategy = hashingStrategy;
590:       return key.hashCode() ^ val.hashCode();
638:    * hashes that vary only in bits above the current mask will
643:    * quality of bit-spreading. Because many common sets of hashes
807:     myHashingStrategy = hashingStrategy;
894:                              float loadFactor, int concurrencyLevel, @NotNull TObjectHashingStrategy<K> hashingStrategy) {
895:     myHashingStrategy = hashingStrategy == THIS ? this : hashingStrategy;
1339:    * {@code key.hashCode() ^ value.hashCode()}.
1457:     int sshift = 0;
1460:       ++sshift;
1463:     int segmentShift = 32 - sshift;
1667:   // Hashtable legacy methods
1673:    * full compatibility with class {@link java.util.Hashtable},
1782:     ForwardingNode(Node<K, V>[] tab, TObjectHashingStrategy<K> hashingStrategy) {
1783:       super(MOVED, null, null, null, hashingStrategy);
2214:              TreeNode<K, V> parent, TObjectHashingStrategy<K> hashingStrategy) {
2292:      * hashCodes and non-comparable. We don't require a total
2311:     TreeBin(TreeNode<K, V> b, TObjectHashingStrategy<K> hashingStrategy) {
2312:       super(TREEBIN, null, null, null, hashingStrategy);
3124:       return key.hashCode() ^ val.hashCode();
3469:         h += e.hashCode();
3607:           h += p.hashCode();
3741:           wasUncontended = true;      // Continue after rehash
3769:         h ^= h << 13;                   // Rehash
3853:     return object == null ? 0 : object.hashCode();
21: import gnu.trove.TObjectHashingStrategy;
91:  * <p>A {@link Set} projection of a ConcurrentHashMapV8 may be created
104:  * <p>ConcurrentHashMapV8s support a set of sequential and parallel bulk
111:  * and/or return values. Because the elements of a ConcurrentHashMapV8
161:  * from those of ConcurrentHashMapV8: Any non-null result returned
227: // copied from JDK1.8 ConcurrentHashMap except:
417:    * classes and identityHashCodes as tie-breakers. The red-black
610:              (k == key || myHashingStrategy.equals((K)k, key)) &&
623:               ((ek = e.key) == k || ek != null && myHashingStrategy.equals((K)k,ek))) {
803:     myHashingStrategy = this;
828:     myHashingStrategy = this;
838:     myHashingStrategy = this;
882:   private static final TObjectHashingStrategy THIS = new TObjectHashingStrategy() {
884:     public int computeHashCode(Object object) {
952:         if ((ek = e.key) == key || ek != null && myHashingStrategy.equals((K)key,ek)) {
962:             ((ek = e.key) == key || ek != null && myHashingStrategy.equals((K)key,ek))) {
1063:                      ek != null && myHashingStrategy.equals(key,ek))) {
1073:                                              value, null,myHashingStrategy);
1165:                      ek != null && myHashingStrategy.equals((K)key,ek))) {
1444:    * Saves the state of the {@code ConcurrentHashMapV8} instance to a
1561:                    qk != null && myHashingStrategy.equals(k,qk))) {
1584:               setTabAt(tab, j, new TreeBin<K, V>(hd, myHashingStrategy));
1713:   // ConcurrentHashMapV8-only methods
1717:    * instead of {@link #size} because a ConcurrentHashMapV8 may
1731:    * Creates a new {@link Set} backed by a ConcurrentHashMapV8
1739:       (new ConcurrentHashMap<K, Boolean>(), Boolean.TRUE);
1743:    * Creates a new {@link Set} backed by a ConcurrentHashMapV8
1755:       (new ConcurrentHashMap<K, Boolean>(initialCapacity), Boolean.TRUE);
1802:               ((ek = e.key) == k || ek != null && myHashingStrategy.equals((K)k, ek))) {
1869:       CounterHashCode hc;
1874:       if ((hc = threadCounterHashCode.get()) == null ||
1989:       ForwardingNode<K, V> rev = new ForwardingNode<K, V>(tab, myHashingStrategy);
2002:     ForwardingNode<K, V> fwd = new ForwardingNode<K, V>(nextTab, myHashingStrategy);
2083:                   ln = new Node<K, V>(ph, pk, pv, ln,myHashingStrategy);
2086:                   hn = new Node<K, V>(ph, pk, pv, hn,myHashingStrategy);
2105:                   (h, e.key, e.val, null, null, myHashingStrategy);
2128:                    hc != 0 ? new TreeBin<K, V>(lo, myHashingStrategy) : t;
2130:                    lc != 0 ? new TreeBin<K, V>(hi, myHashingStrategy) : t;
2166:                                    null, null, myHashingStrategy);
2175:             setTabAt(tab, index, new TreeBin<K, V>(hd, myHashingStrategy));
2244:           else if ((pk = p.key) == k || pk != null && myHashingStrategy.equals((K)k,pk)) {
2302:         d = System.identityHashCode(a) <= System.identityHashCode(b) ?
2416:                 ((ek = e.key) == k || ek != null && myHashingStrategy.equals((K)k,ek))) {
2460:           first = root = new TreeNode<K, V>(h, k, v, null, null, myHashingStrategy);
2469:         else if ((pk = p.key) == k || pk != null && myHashingStrategy.equals(k,pk)) {
2493:           first = x = new TreeNode<K, V>(h, k, v, f, xp, myHashingStrategy);
3000:     final ConcurrentHashMap<K, V> map;
3004:                  ConcurrentHashMap<K, V> map) {
3031:                 ConcurrentHashMap<K, V> map) {
3056:                   ConcurrentHashMap<K, V> map) {
3081:                   ConcurrentHashMap<K, V> map) {
3105:     final ConcurrentHashMap<K, V> map;
3107:     MapEntry(K key, V val, ConcurrentHashMap<K, V> map) {
3138:              (k == key || map.myHashingStrategy.equals((K)k,key)) &&
3167:     final ConcurrentHashMap<K, V> map;
3169:     CollectionView(@NotNull ConcurrentHashMap<K, V> map) {
3178:     public ConcurrentHashMap<K, V> getMap() {
3354:    * A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in
3369:     KeySetView(ConcurrentHashMap<K, V> map, V value) {  // non-public
3416:       ConcurrentHashMap<K, V> m = map;
3484:    * A view of a ConcurrentHashMapV8 as a {@link Collection} of
3492:     ValuesView(ConcurrentHashMap<K, V> map) {
3517:       ConcurrentHashMap<K, V> m = map;
3537:    * A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value)
3545:     EntrySetView(ConcurrentHashMap<K, V> map) {
3579:       ConcurrentHashMap<K, V> m = map;
3654:    * counterHashCodeGenerator, but may be moved upon collisions.
3661:    * Generates initial value for per-thread CounterHashCodes.
3666:    * Increment for counterHashCodeGenerator. See class ThreadLocal
3675:     new ThreadLocal<CounterHashCode>();
3692:   private void fullAddCount(long x, CounterHashCode hc,
3696:       hc = new CounterHashCode();
3697:       int s = counterHashCodeGenerator.addAndGet(SEED_INCREMENT);
3699:       threadCounterHashCode.set(hc);
3812:       Class<?> k = ConcurrentHashMap.class;
3869:     return spread(myHashingStrategy.computeHashCode(key));
android.googlesource.com/platform/superproject:tools/idea/platform/util/src/com/intellij/util/containers/ConcurrentHashMap.java: [ master, ] Duplicate result
chromium.googlesource.com/arc/arc:third_party/android/libcore/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java: [ master, ]
425:         final int hash;
402:     static final int HASH_BITS = 0x7fffffff; // usable bits of normal node hash
439:         public final int hashCode()   { return key.hashCode() ^ val.hashCode(); }
1097:     public int hashCode() {
2609:         public int hashCode()    { return key.hashCode() ^ val.hashCode(); }
2892:         public int hashCode() {
2999:         public final int hashCode() {
102: public class ConcurrentHashMap<K,V> extends java.util.AbstractMap<K,V>
633:     public ConcurrentHashMap() {
646:     public ConcurrentHashMap(int initialCapacity) {
660:     public ConcurrentHashMap(Map<? extends K, ? extends V> m) {
680:     public ConcurrentHashMap(int initialCapacity, float loadFactor) {
702:     public ConcurrentHashMap(int initialCapacity,
3039:     static final class CounterHashCode {
3046:     static final AtomicInteger counterHashCodeGenerator = new AtomicInteger();
3057:     static final ThreadLocal<CounterHashCode> threadCounterHashCode =
36:  * A hash table supporting full concurrency of retrievals and
57:  * the hash table at some point at or since the creation of the
69:  * collisions (i.e., keys that have distinct hash codes but fall into
75:  * hash tables.  However, resizing this or any other kind of hash
87:  * hash table. To ameliorate impact, when keys are {@link Comparable},
109:      * The primary design goal of this hash table is to maintain
116:      * This map usually acts as a binned (bucketed) hash table.  Each
118:      * of the basic Node class with hash, key, value, and next
127:      * because they have negative hash fields and null key and value
140:      * We use the top (sign) bit of Node hash fields for control
142:      * constraints.  Nodes with negative hash fields are specially
148:      * key/hash distributions.  Other update operations (insert,
166:      * random hash codes, this is not a common problem.  Ideally, the
189:      * Actual hash code distributions encountered in practice
193:      * designed to have identical hash codes or ones that differs only
228:      * only a special forwarding node (with hash field "MOVED") that
268:      * bin already holding two or more nodes. Under uniform hash
279:      * handle this, the tree is ordered primarily by hash value, then
283:      * tied hash values. (This corresponds to the full list search
330:      * because the top two bits of 32bit hash fields are used for
397:      * Encodings for Node hash fields. See above for explanation.
399:     static final int MOVED     = 0x8fffffff; // (-1) hash for forwarding nodes
400:     static final int TREEBIN   = 0x80000000; // hash for roots of trees
401:     static final int RESERVED  = 0x80000001; // hash for transient reservations
420:      * in bulk tasks.  Subclasses of Node with a negative hash field
430:         Node(int hash, K key, V val, Node<K,V> next) {
431:             this.hash = hash;
462:                     if (e.hash == h &&
474:      * Spreads (XORs) higher bits of hash to lower and also forces top
490:         return (h ^ (h >>> 16)) & HASH_BITS;
549:      * the form of a hash value anded with (length - 1) is a valid
749:             if ((eh = e.hash) == h) {
756:                 if (e.hash == h &&
822:         int hash = spread(key.hashCode());
828:             else if ((f = tabAt(tab, i = (n - 1) & hash)) == null) {
830:                              new Node<K,V>(hash, key, value, null)))
833:             else if ((fh = f.hash) == MOVED)
843:                                 if (e.hash == hash &&
853:                                     pred.next = new Node<K,V>(hash, key,
862:                             if ((p = ((TreeBin<K,V>)f).putTreeVal(hash, key,
916:         int hash = spread(key.hashCode());
920:                 (f = tabAt(tab, i = (n - 1) & hash)) == null)
922:             else if ((fh = f.hash) == MOVED)
933:                                 if (e.hash == hash &&
959:                                 (p = r.findTreeNode(hash, key, null)) != null) {
998:             else if ((fh = f.hash) == MOVED) {
1091:      * Returns the hash code value for this {@link Map}, i.e.,
1095:      * @return the hash code value for this map
1274:                 int h = p.hash, j = h & mask;
1279:                     if (first.hash < 0) {
1290:                             if (q.hash == h &&
1305:                                     (q.hash, q.key, q.val, null, null);
1511:                     if ((eh = e.hash) == h &&
1729:             else if ((fh = f.hash) == MOVED)
1739:                                 int b = p.hash & n;
1754:                                 int ph = p.hash; K pk = p.key; V pv = p.val;
1767:                                 int h = e.hash;
1824:                                 new TreeNode<K,V>(e.hash, e.key, e.val,
1845:             Node<K,V> p = new Node<K,V>(q.hash, q.key, q.val, null);
1867:         TreeNode(int hash, K key, V val, Node<K,V> next,
1869:             super(hash, key, val, next);
1887:                     if ((ph = p.hash) > h)
1948:                     int hash = x.hash;
1952:                         if ((ph = p.hash) > hash)
1954:                         else if (ph < hash)
2026:                         if (e.hash == h &&
2065:                 else if ((ph = p.hash) > h)
2413:             if (tl != null && (tl.parent != t || tl.hash > t.hash))
2415:             if (tr != null && (tr.parent != t || tr.hash < t.hash))
2493:                 if ((e = tabAt(t, index)) != null && e.hash < 0) {
3035:      * Holder for the thread-local hash code determining which
3055:      * Per-thread counter hash codes. Shared across all instances.
18: import java.util.HashMap;
19: import java.util.Hashtable;
38:  * same functional specification as {@link java.util.Hashtable}, and
40:  * {@code Hashtable}. However, even though all operations are
44:  * interoperable with {@code Hashtable} in programs that rely on its
86:  * {@code hashCode()} is a sure way to slow down performance of any
94:  * <p>Like {@link Hashtable} but unlike {@link HashMap}, this class
113:      * the same or better than java.util.HashMap, and to support high
126:      * hashes, and are readily distinguishable during search etc
187:      * elements is roughly 1 / (8 * #elements) under random hashes.
192:      * Similarly for dumb or hostile usages in which multiple keys are
285:      * had tied hashes.)  The red-black balancing code is updated from
476:      * hashes that vary only in bits above the current mask will
481:      * quality of bit-spreading. Because many common sets of hashes
746:         int h = spread(key.hashCode());
1093:      * {@code key.hashCode() ^ value.hashCode()}.
1103:                 h += p.key.hashCode() ^ p.val.hashCode();
1200:         int sshift = 0;
1203:             ++sshift;
1206:         int segmentShift = 32 - sshift;
1251:                 p = new Node<K,V>(spread(k.hashCode()), k, v, p);
1376:     // Hashtable legacy methods
1382:      * full compatibility with class {@link java.util.Hashtable}.
2895:                 h += e.hashCode();
3005:                     h += p.hashCode();
3113:                     wasUncontended = true;      // Continue after rehash
3135:                 h ^= h << 13;                   // Rehash
1188:      * Saves the state of the {@code ConcurrentHashMap} instance to a
1422:     // ConcurrentHashMap-only methods
1426:      * instead of {@link #size} because a ConcurrentHashMap may
1442:      * Creates a new {@link Set} backed by a ConcurrentHashMap
1452:             (new ConcurrentHashMap<K,Boolean>(), Boolean.TRUE);
1456:      * Creates a new {@link Set} backed by a ConcurrentHashMap
1470:             (new ConcurrentHashMap<K,Boolean>(initialCapacity), Boolean.TRUE);
1577:             CounterHashCode hc; CounterCell a; long v; int m;
1579:             if ((hc = threadCounterHashCode.get()) == null ||
2515:         final ConcurrentHashMap<K,V> map;
2518:                     ConcurrentHashMap<K,V> map) {
2539:                     ConcurrentHashMap<K,V> map) {
2559:                       ConcurrentHashMap<K,V> map) {
2579:                       ConcurrentHashMap<K,V> map) {
2601:         final ConcurrentHashMap<K,V> map;
2602:         MapEntry(K key, V val, ConcurrentHashMap<K,V> map) {
2647:         final ConcurrentHashMap<K,V> map;
2648:         CollectionView(ConcurrentHashMap<K,V> map)  { this.map = map; }
2655:         public ConcurrentHashMap<K,V> getMap() { return map; }
2795:      * A view of a ConcurrentHashMap as a {@link Set} of keys, in
2811:         KeySetView(ConcurrentHashMap<K,V> map, V value) {  // non-public
2847:             ConcurrentHashMap<K,V> m = map;
2909:      * A view of a ConcurrentHashMap as a {@link Collection} of
2916:         ValuesView(ConcurrentHashMap<K,V> map) { super(map); }
2934:             ConcurrentHashMap<K,V> m = map;
2950:      * A view of a ConcurrentHashMap as a {@link Set} of (key, value)
2957:         EntrySetView(ConcurrentHashMap<K,V> map) { super(map); }
2980:             ConcurrentHashMap<K,V> m = map;
3037:      * counterHashCodeGenerator, but may be moved upon collisions.
3044:      * Generates initial value for per-thread CounterHashCodes.
3049:      * Increment for counterHashCodeGenerator. See class ThreadLocal
3058:         new ThreadLocal<CounterHashCode>();
3073:     private final void fullAddCount(long x, CounterHashCode hc,
3077:             hc = new CounterHashCode();
3078:             int s = counterHashCodeGenerator.addAndGet(SEED_INCREMENT);
3080:             threadCounterHashCode.set(hc);
3175:             Class<?> k = ConcurrentHashMap.class;
github.com/apache/ant-ivy:src/java/org/apache/ivy/plugins/repository/ssh/SshCache.java: [ master, ]
69:         private String host = null;
397:         private final String host;
18: package org.apache.ivy.plugins.repository.ssh;
53:     private static final int SSH_DEFAULT_PORT = 22;
51: public final class SshCache {
55:     private SshCache() {
78:         public String getHost() {
47:  * a class to cache SSH Connections and Channel for the SSH Repository each session is defined by
48:  * connecting user / host / port two maps are used to find cache entries one map is using the above
73:         private int port = SSH_DEFAULT_PORT;
76:          * @return the host
79:             return host;
98:             host = newHost;
142:                     Message.verbose(":: SFTP :: closing sftp connection from " + host + "...");
145:                     Message.verbose(":: SFTP :: sftp connection closed from " + host);
152:      * key is username / host / port
168:      * @param host
174:     private Entry getCacheEntry(String user, String host, int port) {
175:         return uriCacheMap.get(createCacheKey(user, host, port));
183:      * @param host
189:     private static String createCacheKey(String user, String host, int port) {
191:         if (port != -1 && port != SSH_DEFAULT_PORT) {
194:         return user.trim().toLowerCase(Locale.US) + "@" + host.trim().toLowerCase(Locale.US) + ":"
215:      * @param host
222:     private void setSession(String user, String host, int port, Session newSession) {
223:         Entry entry = uriCacheMap.get(createCacheKey(user, host, port));
231:             Message.verbose(":: SSH :: closing ssh connection from " + oldhost + "...");
233:             Message.verbose(":: SSH :: ssh connection closed from " + oldhost);
236:             uriCacheMap.remove(createCacheKey(user, host, port));
241:             Entry newEntry = new Entry(newSession, user, host, port);
242:             uriCacheMap.put(createCacheKey(user, host, port), newEntry);
298:      * Attempts to connect to a local SSH agent (using either UNIX sockets or PuTTY's Pageant)
310:             Message.verbose(":: SSH :: Failure connecting to agent :: " + e.toString());
318:      * @param host
337:     public Session getSession(String host, int port, String username, String userPassword,
340:         Checks.checkNotNull(host, "host");
342:         Entry entry = getCacheEntry(username, host, port);
348:             Message.verbose(":: SSH :: connecting to " + host + "...");
352:                     session = jsch.getSession(username, host, port);
354:                     session = jsch.getSession(username, host);
362:                 session.setUserInfo(new CfUserInfo(host, username, userPassword, pemFile,
372:                 Message.verbose(":: SSH :: connected to " + host + "!");
373:                 setSession(username, host, port, session);
401:         public CfUserInfo(String host, String userName, String userPassword, File pemFile,
405:             this.host = host;
429:                 Credentials c = CredentialsUtil.promptCredentials(new Credentials(null, host,
22: import java.util.HashMap;
58:     private static SshCache instance = new SshCache();
60:     public static SshCache getInstance() {
96:         public Entry(Session newSession, String newUser, String newHost, int newPort) {
156:     private final Map<String, Entry> uriCacheMap = new HashMap<>();
161:     private final Map<Session, Entry> sessionCacheMap = new HashMap<>();
164:      * retrieves a session entry for a given hostname from the cache
230:             String oldhost = oldSession.getHost();
256:             setSession(entry.getUser(), entry.getHost(), entry.getPort(), null);
github.com/apache/ant-ivy:src/java/org/apache/ivy/plugins/repository/ssh/AbstractSshBasedRepository.java: [ master, ]
51:     private String host = null;
18: package org.apache.ivy.plugins.repository.ssh;
57:     private String sshConfig = null;
288:     public String getHost() {
296:     public void setHost(String host) {
39: public abstract class AbstractSshBasedRepository extends AbstractRepository {
59:     public AbstractSshBasedRepository() {
63:     public AbstractSshBasedRepository(final TimeoutConstraint timeoutConstraint) {
348:     public String getSshConfig() {
356:     public void setSshConfig(String sshConfig) {
79:      *            might be just a path or a full ssh or sftp uri
85:         String host = getHost();
93:                 host = uri.getHost();
111:             Config config = configRepository.getConfig(host);
112:             host = config.getHostname();
122:         if (host == null) {
124:                     "missing host information. host should be provided either "
129:             Credentials c = requestCredentials(host);
137:         return SshCache.getInstance().getSession(host, port, user, userPassword, keyFile,
158:                 throw new URISyntaxException(source, "Missing host in URI or in resolver");
177:      * Called, when user was not found in URL. Maintain static hash of credentials and retrieve or
178:      * ask credentials for host.
180:      * @param host
181:      *            host for which we want to get credentials.
182:      * @return credentials for given host
184:     private Credentials requestCredentials(String host) {
185:         Credentials c = credentialsCache.get(host);
187:             c = CredentialsUtil.promptCredentials(new Credentials(null, host, user,
193:                 credentialsCache.put(host, c);
286:      * @return the host
289:         return host;
293:      * @param host
294:      *            the host to set
297:         this.host = host;
331:      * @return allowedAgentUse Whether use of a local SSH agent for authentication is allowed
339:      *            Whether use of a local SSH agent for authentication is allowed
346:      * @return sshConfig Path to a local ssh config file
354:      *            Path to a local ssh config file
24: import java.util.HashMap;
68:      * hashmap of user/hosts with credentials. key is hostname, value is Credentials
70:     private static final Map<String, Credentials> credentialsCache = new HashMap<>();
89:         String sshConfig = getSshConfig();
92:             if (uri.getHost() != null) {
109:         if (sshConfig != null) {
110:             ConfigRepository configRepository = OpenSSHConfig.parseFile(sshConfig);
126:                             + ", or in the openssh config file specified by sshConfig");
157:             if (uri.getHost() == null && getHost() == null) {
171:                     + "://user:pass@hostname/path/to/repository");
209:         SshCache.getInstance().clearSession(session);
349:         return sshConfig;
353:      * @param sshConfig
357:         this.sshConfig = sshConfig;
36: import com.jcraft.jsch.OpenSSHConfig;
go.googlesource.com/crypto:ssh/keys.go: [ master, ]
5: package ssh
595: func ecHash(curve elliptic.Curve) crypto.Hash {
114: func ParseKnownHosts(in []byte) (marker string, hosts []string, pubKey PublicKey, comment string, rest []byte, err error) {
970: func parseOpenSSHPrivateKey(key []byte) (crypto.PrivateKey, error) {
33: 	KeyAlgoRSA      = "ssh-rsa"
34: 	KeyAlgoDSA      = "ssh-dss"
38: 	KeyAlgoED25519  = "ssh-ed25519"
46: 	SigAlgoRSA        = "ssh-rsa"