"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "sshfs.c" between
sshfs-3.7.0.tar.xz and sshfs-3.7.1.tar.xz

About: SSH Filesystem is based on the FUSE (Filesystem in Userspace) kernel module and uses the SSH File Transfer Protocol (SFTP) without requiring root privileges for mounting a remote filesystem.

sshfs.c  (sshfs-3.7.0.tar.xz):sshfs.c  (sshfs-3.7.1.tar.xz)
skipping to change at line 342 skipping to change at line 342
unsigned ssh_ver; unsigned ssh_ver;
int sync_write; int sync_write;
int sync_read; int sync_read;
int sync_readdir; int sync_readdir;
int direct_io; int direct_io;
int debug; int debug;
int verbose; int verbose;
int foreground; int foreground;
int reconnect; int reconnect;
int delay_connect; int delay_connect;
int slave; int passive;
char *host; char *host;
char *base_path; char *base_path;
GHashTable *reqtab; GHashTable *reqtab;
GHashTable *conntab; GHashTable *conntab;
pthread_mutex_t lock; pthread_mutex_t lock;
unsigned int randseed; unsigned int randseed;
int max_conns; int max_conns;
struct conn *conns; struct conn *conns;
int ptyfd; int ptyfd;
int ptyslavefd; int ptypassivefd;
int connvers; int connvers;
int server_version; int server_version;
unsigned remote_uid; unsigned remote_uid;
unsigned local_uid; unsigned local_uid;
unsigned remote_gid; unsigned remote_gid;
unsigned local_gid; unsigned local_gid;
int remote_uid_detected; int remote_uid_detected;
unsigned blksize; unsigned blksize;
char *progname; char *progname;
long modifver; long modifver;
skipping to change at line 498 skipping to change at line 498
SSHFS_OPT("no_readahead", sync_read, 1), SSHFS_OPT("no_readahead", sync_read, 1),
SSHFS_OPT("sync_readdir", sync_readdir, 1), SSHFS_OPT("sync_readdir", sync_readdir, 1),
SSHFS_OPT("sshfs_debug", debug, 1), SSHFS_OPT("sshfs_debug", debug, 1),
SSHFS_OPT("sshfs_verbose", verbose, 1), SSHFS_OPT("sshfs_verbose", verbose, 1),
SSHFS_OPT("reconnect", reconnect, 1), SSHFS_OPT("reconnect", reconnect, 1),
SSHFS_OPT("transform_symlinks", transform_symlinks, 1), SSHFS_OPT("transform_symlinks", transform_symlinks, 1),
SSHFS_OPT("follow_symlinks", follow_symlinks, 1), SSHFS_OPT("follow_symlinks", follow_symlinks, 1),
SSHFS_OPT("no_check_root", no_check_root, 1), SSHFS_OPT("no_check_root", no_check_root, 1),
SSHFS_OPT("password_stdin", password_stdin, 1), SSHFS_OPT("password_stdin", password_stdin, 1),
SSHFS_OPT("delay_connect", delay_connect, 1), SSHFS_OPT("delay_connect", delay_connect, 1),
SSHFS_OPT("slave", slave, 1), SSHFS_OPT("slave", passive, 1),
SSHFS_OPT("passive", passive, 1),
SSHFS_OPT("disable_hardlink", disable_hardlink, 1), SSHFS_OPT("disable_hardlink", disable_hardlink, 1),
SSHFS_OPT("dir_cache=yes", dir_cache, 1), SSHFS_OPT("dir_cache=yes", dir_cache, 1),
SSHFS_OPT("dir_cache=no", dir_cache, 0), SSHFS_OPT("dir_cache=no", dir_cache, 0),
SSHFS_OPT("direct_io", direct_io, 1), SSHFS_OPT("direct_io", direct_io, 1),
SSHFS_OPT("max_conns=%u", max_conns, 1), SSHFS_OPT("max_conns=%u", max_conns, 1),
SSHFS_OPT("-h", show_help, 1), SSHFS_OPT("-h", show_help, 1),
SSHFS_OPT("--help", show_help, 1), SSHFS_OPT("--help", show_help, 1),
SSHFS_OPT("-V", show_version, 1), SSHFS_OPT("-V", show_version, 1),
SSHFS_OPT("--version", show_version, 1), SSHFS_OPT("--version", show_version, 1),
skipping to change at line 1067 skipping to change at line 1068
sshfs.password = NULL; sshfs.password = NULL;
} }
return 0; return 0;
} }
static struct conn* get_conn(const struct sshfs_file *sf, static struct conn* get_conn(const struct sshfs_file *sf,
const char *path) const char *path)
{ {
struct conntab_entry *ce; struct conntab_entry *ce;
int i;
if (sshfs.max_conns == 1) if (sshfs.max_conns == 1)
return &sshfs.conns[0]; return &sshfs.conns[0];
if (sf != NULL) if (sf != NULL)
return sf->conn; return sf->conn;
if (path != NULL) { if (path != NULL) {
pthread_mutex_lock(&sshfs.lock); pthread_mutex_lock(&sshfs.lock);
ce = g_hash_table_lookup(sshfs.conntab, path); ce = g_hash_table_lookup(sshfs.conntab, path);
skipping to change at line 1088 skipping to change at line 1090
if (ce != NULL) { if (ce != NULL) {
struct conn *conn = ce->conn; struct conn *conn = ce->conn;
pthread_mutex_unlock(&sshfs.lock); pthread_mutex_unlock(&sshfs.lock);
return conn; return conn;
} }
pthread_mutex_unlock(&sshfs.lock); pthread_mutex_unlock(&sshfs.lock);
} }
int best_index = 0; int best_index = 0;
uint64_t best_score = ~0ULL; /* smaller is better */ uint64_t best_score = ~0ULL; /* smaller is better */
for (int i = 0; i < sshfs.max_conns; i++) { for (i = 0; i < sshfs.max_conns; i++) {
uint64_t score = ((uint64_t) sshfs.conns[i].req_count << 43) + uint64_t score = ((uint64_t) sshfs.conns[i].req_count << 43) +
((uint64_t) sshfs.conns[i].dir_count << 22) + ((uint64_t) sshfs.conns[i].dir_count << 22) +
((uint64_t) sshfs.conns[i].file_count << 1) + ((uint64_t) sshfs.conns[i].file_count << 1) +
(uint64_t) (sshfs.conns[i].rfd >= 0 ? 0 : 1); (uint64_t) (sshfs.conns[i].rfd >= 0 ? 0 : 1);
if (score < best_score) { if (score < best_score) {
best_index = i; best_index = i;
best_score = score; best_score = score;
} }
} }
return &sshfs.conns[best_index]; return &sshfs.conns[best_index];
skipping to change at line 1145 skipping to change at line 1147
char *ptyname = NULL; char *ptyname = NULL;
int sockpair[2]; int sockpair[2];
int pid; int pid;
if (sshfs.password_stdin) { if (sshfs.password_stdin) {
sshfs.ptyfd = pty_master(&ptyname); sshfs.ptyfd = pty_master(&ptyname);
if (sshfs.ptyfd == -1) if (sshfs.ptyfd == -1)
return -1; return -1;
sshfs.ptyslavefd = open(ptyname, O_RDWR | O_NOCTTY); sshfs.ptypassivefd = open(ptyname, O_RDWR | O_NOCTTY);
if (sshfs.ptyslavefd == -1) if (sshfs.ptypassivefd == -1)
return -1; return -1;
} }
if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair) == -1) { if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockpair) == -1) {
perror("failed to create socket pair"); perror("failed to create socket pair");
return -1; return -1;
} }
conn->rfd = sockpair[0]; conn->rfd = sockpair[0];
conn->wfd = sockpair[0]; conn->wfd = sockpair[0];
skipping to change at line 1188 skipping to change at line 1190
switch (fork()) { switch (fork()) {
case -1: case -1:
perror("failed to fork"); perror("failed to fork");
_exit(1); _exit(1);
case 0: case 0:
break; break;
default: default:
_exit(0); _exit(0);
} }
chdir("/"); chdir("/");
/*
* Avoid processes hanging trying to stat() OLDPWD if it is in
* the mount point. This can be removed if sshfs opens the
* mount point after establishing the ssh connection.
*/
unsetenv("OLDPWD");
if (sshfs.password_stdin) { if (sshfs.password_stdin) {
int sfd; int sfd;
setsid(); setsid();
sfd = open(ptyname, O_RDWR); sfd = open(ptyname, O_RDWR);
if (sfd == -1) { if (sfd == -1) {
perror(ptyname); perror(ptyname);
_exit(1); _exit(1);
} }
close(sfd); close(sfd);
close(sshfs.ptyslavefd); close(sshfs.ptypassivefd);
close(sshfs.ptyfd); close(sshfs.ptyfd);
} }
if (sshfs.debug) { if (sshfs.debug) {
int i; int i;
fprintf(stderr, "executing"); fprintf(stderr, "executing");
for (i = 0; i < sshfs.ssh_args.argc; i++) for (i = 0; i < sshfs.ssh_args.argc; i++)
fprintf(stderr, " <%s>", fprintf(stderr, " <%s>",
sshfs.ssh_args.argv[i]); sshfs.ssh_args.argv[i]);
skipping to change at line 1223 skipping to change at line 1231
execvp(sshfs.ssh_args.argv[0], sshfs.ssh_args.argv); execvp(sshfs.ssh_args.argv[0], sshfs.ssh_args.argv);
fprintf(stderr, "failed to execute '%s': %s\n", fprintf(stderr, "failed to execute '%s': %s\n",
sshfs.ssh_args.argv[0], strerror(errno)); sshfs.ssh_args.argv[0], strerror(errno));
_exit(1); _exit(1);
} }
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
close(sockpair[1]); close(sockpair[1]);
return 0; return 0;
} }
static int connect_slave(struct conn *conn) static int connect_passive(struct conn *conn)
{ {
conn->rfd = STDIN_FILENO; conn->rfd = STDIN_FILENO;
conn->wfd = STDOUT_FILENO; conn->wfd = STDOUT_FILENO;
return 0; return 0;
} }
static int connect_to(struct conn *conn, char *host, char *port) static int connect_to(struct conn *conn, char *host, char *port)
{ {
int err; int err;
int sock; int sock;
skipping to change at line 1530 skipping to change at line 1538
{ {
close(conn->rfd); close(conn->rfd);
if (conn->rfd != conn->wfd) if (conn->rfd != conn->wfd)
close(conn->wfd); close(conn->wfd);
conn->rfd = -1; conn->rfd = -1;
conn->wfd = -1; conn->wfd = -1;
if (sshfs.ptyfd != -1) { if (sshfs.ptyfd != -1) {
close(sshfs.ptyfd); close(sshfs.ptyfd);
sshfs.ptyfd = -1; sshfs.ptyfd = -1;
} }
if (sshfs.ptyslavefd != -1) { if (sshfs.ptypassivefd != -1) {
close(sshfs.ptyslavefd); close(sshfs.ptypassivefd);
sshfs.ptyslavefd = -1; sshfs.ptypassivefd = -1;
} }
} }
static void *process_requests(void *data_) static void *process_requests(void *data_)
{ {
(void) data_; (void) data_;
struct conn *conn = data_; struct conn *conn = data_;
while (1) { while (1) {
if (process_one_request(conn) == -1) if (process_one_request(conn) == -1)
skipping to change at line 1823 skipping to change at line 1831
out: out:
buf_free(&buf); buf_free(&buf);
return err; return err;
} }
static int connect_remote(struct conn *conn) static int connect_remote(struct conn *conn)
{ {
int err; int err;
if (sshfs.slave) if (sshfs.passive)
err = connect_slave(conn); err = connect_passive(conn);
else if (sshfs.directport) else if (sshfs.directport)
err = connect_to(conn, sshfs.host, sshfs.directport); err = connect_to(conn, sshfs.host, sshfs.directport);
else else
err = start_ssh(conn); err = start_ssh(conn);
if (!err) if (!err)
err = sftp_init(conn); err = sftp_init(conn);
if (err) if (err)
close_conn(conn); close_conn(conn);
else else
skipping to change at line 3624 skipping to change at line 3632
" file translate UIDs/GIDs contained in uidfile/gidfile\ n" " file translate UIDs/GIDs contained in uidfile/gidfile\ n"
" -o uidfile=FILE file containing username:remote_uid mappings\n" " -o uidfile=FILE file containing username:remote_uid mappings\n"
" -o gidfile=FILE file containing groupname:remote_gid mappings\n" " -o gidfile=FILE file containing groupname:remote_gid mappings\n"
" -o nomap=TYPE with idmap=file, how to handle missing mappings\n" " -o nomap=TYPE with idmap=file, how to handle missing mappings\n"
" ignore don't do any re-mapping\n" " ignore don't do any re-mapping\n"
" error return an error (default)\n" " error return an error (default)\n"
" -o ssh_command=CMD execute CMD instead of 'ssh'\n" " -o ssh_command=CMD execute CMD instead of 'ssh'\n"
" -o ssh_protocol=N ssh protocol to use (default: 2)\n" " -o ssh_protocol=N ssh protocol to use (default: 2)\n"
" -o sftp_server=SERV path to sftp server or subsystem (default: sftp)\n" " -o sftp_server=SERV path to sftp server or subsystem (default: sftp)\n"
" -o directport=PORT directly connect to PORT bypassing ssh\n" " -o directport=PORT directly connect to PORT bypassing ssh\n"
" -o slave communicate over stdin and stdout bypassing network\ n" " -o passive communicate over stdin and stdout bypassing network\ n"
" -o disable_hardlink link(2) will return with errno set to ENOSYS\n" " -o disable_hardlink link(2) will return with errno set to ENOSYS\n"
" -o transform_symlinks transform absolute symlinks to relative\n" " -o transform_symlinks transform absolute symlinks to relative\n"
" -o follow_symlinks follow symlinks on the server\n" " -o follow_symlinks follow symlinks on the server\n"
" -o no_check_root don't check for existence of 'dir' on server\n" " -o no_check_root don't check for existence of 'dir' on server\n"
" -o password_stdin read password from stdin (only for pam_mount!)\n" " -o password_stdin read password from stdin (only for pam_mount!)\n"
" -o max_conns=N open parallel SSH connections\n" " -o max_conns=N open parallel SSH connections\n"
" -o SSHOPT=VAL ssh options (see man ssh_config)\n" " -o SSHOPT=VAL ssh options (see man ssh_config)\n"
"\n" "\n"
"FUSE Options:\n", "FUSE Options:\n",
progname); progname);
skipping to change at line 4176 skipping to change at line 4184
sshfs.createmode_workaround = 0; sshfs.createmode_workaround = 0;
sshfs.ssh_ver = 2; sshfs.ssh_ver = 2;
sshfs.progname = argv[0]; sshfs.progname = argv[0];
sshfs.max_conns = 1; sshfs.max_conns = 1;
sshfs.ptyfd = -1; sshfs.ptyfd = -1;
sshfs.dir_cache = 1; sshfs.dir_cache = 1;
sshfs.show_help = 0; sshfs.show_help = 0;
sshfs.show_version = 0; sshfs.show_version = 0;
sshfs.singlethread = 0; sshfs.singlethread = 0;
sshfs.foreground = 0; sshfs.foreground = 0;
sshfs.ptyslavefd = -1; sshfs.ptypassivefd = -1;
sshfs.delay_connect = 0; sshfs.delay_connect = 0;
sshfs.slave = 0; sshfs.passive = 0;
sshfs.detect_uid = 0; sshfs.detect_uid = 0;
if (strcmp(IDMAP_DEFAULT, "none") == 0) { if (strcmp(IDMAP_DEFAULT, "none") == 0) {
sshfs.idmap = IDMAP_NONE; sshfs.idmap = IDMAP_NONE;
} else if (strcmp(IDMAP_DEFAULT, "user") == 0) { } else if (strcmp(IDMAP_DEFAULT, "user") == 0) {
sshfs.idmap = IDMAP_USER; sshfs.idmap = IDMAP_USER;
} else { } else {
fprintf(stderr, "bad idmap default value built into sshfs; " fprintf(stderr, "bad idmap default value built into sshfs; "
"assuming none (bad logic in configure script?)\n"); "assuming none (bad logic in configure script?)\n");
sshfs.idmap = IDMAP_NONE; sshfs.idmap = IDMAP_NONE;
} }
skipping to change at line 4244 skipping to change at line 4252
load_uid_map(); load_uid_map();
if (sshfs.gid_file) if (sshfs.gid_file)
load_gid_map(); load_gid_map();
} }
free(sshfs.uid_file); free(sshfs.uid_file);
free(sshfs.gid_file); free(sshfs.gid_file);
DEBUG("SSHFS version %s\n", PACKAGE_VERSION); DEBUG("SSHFS version %s\n", PACKAGE_VERSION);
/* Force sshfs to the foreground when using stdin+stdout */ /* Force sshfs to the foreground when using stdin+stdout */
if (sshfs.slave) if (sshfs.passive)
sshfs.foreground = 1; sshfs.foreground = 1;
if (sshfs.slave && sshfs.password_stdin) { if (sshfs.passive && sshfs.password_stdin) {
fprintf(stderr, "the password_stdin and slave options cannot both fprintf(stderr, "the password_stdin and passive options cannot bo
be specified\n"); th be specified\n");
exit(1); exit(1);
} }
if (sshfs.password_stdin) { if (sshfs.password_stdin) {
res = read_password(); res = read_password();
if (res == -1) if (res == -1)
exit(1); exit(1);
} }
if (sshfs.debug) if (sshfs.debug)
skipping to change at line 4280 skipping to change at line 4288
if (sshfs.buflimit_workaround) { if (sshfs.buflimit_workaround) {
fprintf(stderr, "buflimit workaround is not supported wit h parallel connections\n"); fprintf(stderr, "buflimit workaround is not supported wit h parallel connections\n");
exit(1); exit(1);
} }
if (sshfs.password_stdin) { if (sshfs.password_stdin) {
fprintf(stderr, "password_stdin option cannot be specifie d with parallel connections\n"); fprintf(stderr, "password_stdin option cannot be specifie d with parallel connections\n");
exit(1); exit(1);
} }
if (sshfs.slave) { if (sshfs.passive) {
fprintf(stderr, "slave option cannot be specified with pa fprintf(stderr, "passive option cannot be specified with
rallel connections\n"); parallel connections\n");
exit(1); exit(1);
} }
} else if (sshfs.max_conns <= 0) { } else if (sshfs.max_conns <= 0) {
fprintf(stderr, "value of max_conns option must be at least 1\n") ; fprintf(stderr, "value of max_conns option must be at least 1\n") ;
exit(1); exit(1);
} }
sshfs.conns = g_new0(struct conn, sshfs.max_conns); sshfs.conns = g_new0(struct conn, sshfs.max_conns);
for (i = 0; i < sshfs.max_conns; i++) { for (i = 0; i < sshfs.max_conns; i++) {
sshfs.conns[i].rfd = -1; sshfs.conns[i].rfd = -1;
 End of changes. 17 change blocks. 
23 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)