summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/sftp-server.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-03-18 09:55:03 +0000
committerdes <des@FreeBSD.org>2002-03-18 09:55:03 +0000
commit2fc4a488978a03338ecc65403597582c77dabeea (patch)
tree068818e7abaca45008ac24af9fb4de22815cc0eb /crypto/openssh/sftp-server.c
parent8acd87ac472a182ef2d717212f2c0faba81143a5 (diff)
downloadFreeBSD-src-2fc4a488978a03338ecc65403597582c77dabeea.zip
FreeBSD-src-2fc4a488978a03338ecc65403597582c77dabeea.tar.gz
Vendor import of OpenSSH 3.1
Diffstat (limited to 'crypto/openssh/sftp-server.c')
-rw-r--r--crypto/openssh/sftp-server.c130
1 files changed, 72 insertions, 58 deletions
diff --git a/crypto/openssh/sftp-server.c b/crypto/openssh/sftp-server.c
index b49f861..b98c5ff 100644
--- a/crypto/openssh/sftp-server.c
+++ b/crypto/openssh/sftp-server.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000 Markus Friedl. All rights reserved.
+ * Copyright (c) 2000, 2001, 2002 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -22,7 +22,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "includes.h"
-RCSID("$OpenBSD: sftp-server.c,v 1.25 2001/04/05 10:42:53 markus Exp $");
+RCSID("$OpenBSD: sftp-server.c,v 1.33 2002/02/13 00:28:13 markus Exp $");
#include "buffer.h"
#include "bufaux.h"
@@ -56,7 +56,7 @@ struct Stat {
Attrib attrib;
};
-int
+static int
errno_to_portable(int unixerrno)
{
int ret = 0;
@@ -87,7 +87,7 @@ errno_to_portable(int unixerrno)
return ret;
}
-int
+static int
flags_from_portable(int pflags)
{
int flags = 0;
@@ -109,7 +109,7 @@ flags_from_portable(int pflags)
return flags;
}
-Attrib *
+static Attrib *
get_attrib(void)
{
return decode_attrib(&iqueue);
@@ -133,21 +133,21 @@ enum {
Handle handles[100];
-void
+static void
handle_init(void)
{
int i;
- for(i = 0; i < sizeof(handles)/sizeof(Handle); i++)
+ for (i = 0; i < sizeof(handles)/sizeof(Handle); i++)
handles[i].use = HANDLE_UNUSED;
}
-int
+static int
handle_new(int use, char *name, int fd, DIR *dirp)
{
int i;
- for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
+ for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
if (handles[i].use == HANDLE_UNUSED) {
handles[i].use = use;
handles[i].dirp = dirp;
@@ -159,14 +159,14 @@ handle_new(int use, char *name, int fd, DIR *dirp)
return -1;
}
-int
+static int
handle_is_ok(int i, int type)
{
return i >= 0 && i < sizeof(handles)/sizeof(Handle) &&
handles[i].use == type;
}
-int
+static int
handle_to_string(int handle, char **stringp, int *hlenp)
{
if (stringp == NULL || hlenp == NULL)
@@ -177,7 +177,7 @@ handle_to_string(int handle, char **stringp, int *hlenp)
return 0;
}
-int
+static int
handle_from_string(char *handle, u_int hlen)
{
int val;
@@ -191,7 +191,7 @@ handle_from_string(char *handle, u_int hlen)
return -1;
}
-char *
+static char *
handle_to_name(int handle)
{
if (handle_is_ok(handle, HANDLE_DIR)||
@@ -200,7 +200,7 @@ handle_to_name(int handle)
return NULL;
}
-DIR *
+static DIR *
handle_to_dir(int handle)
{
if (handle_is_ok(handle, HANDLE_DIR))
@@ -208,7 +208,7 @@ handle_to_dir(int handle)
return NULL;
}
-int
+static int
handle_to_fd(int handle)
{
if (handle_is_ok(handle, HANDLE_FILE))
@@ -216,7 +216,7 @@ handle_to_fd(int handle)
return -1;
}
-int
+static int
handle_close(int handle)
{
int ret = -1;
@@ -233,7 +233,7 @@ handle_close(int handle)
return ret;
}
-int
+static int
get_handle(void)
{
char *handle;
@@ -249,7 +249,7 @@ get_handle(void)
/* send replies */
-void
+static void
send_msg(Buffer *m)
{
int mlen = buffer_len(m);
@@ -259,7 +259,7 @@ send_msg(Buffer *m)
buffer_consume(m, mlen);
}
-void
+static void
send_status(u_int32_t id, u_int32_t error)
{
Buffer msg;
@@ -289,7 +289,7 @@ send_status(u_int32_t id, u_int32_t error)
send_msg(&msg);
buffer_free(&msg);
}
-void
+static void
send_data_or_handle(char type, u_int32_t id, char *data, int dlen)
{
Buffer msg;
@@ -302,14 +302,14 @@ send_data_or_handle(char type, u_int32_t id, char *data, int dlen)
buffer_free(&msg);
}
-void
+static void
send_data(u_int32_t id, char *data, int dlen)
{
TRACE("sent data id %d len %d", id, dlen);
send_data_or_handle(SSH2_FXP_DATA, id, data, dlen);
}
-void
+static void
send_handle(u_int32_t id, int handle)
{
char *string;
@@ -321,7 +321,7 @@ send_handle(u_int32_t id, int handle)
xfree(string);
}
-void
+static void
send_names(u_int32_t id, int count, Stat *stats)
{
Buffer msg;
@@ -341,7 +341,7 @@ send_names(u_int32_t id, int count, Stat *stats)
buffer_free(&msg);
}
-void
+static void
send_attrib(u_int32_t id, Attrib *a)
{
Buffer msg;
@@ -357,7 +357,7 @@ send_attrib(u_int32_t id, Attrib *a)
/* parse incoming */
-void
+static void
process_init(void)
{
Buffer msg;
@@ -371,7 +371,7 @@ process_init(void)
buffer_free(&msg);
}
-void
+static void
process_open(void)
{
u_int32_t id, pflags;
@@ -403,7 +403,7 @@ process_open(void)
xfree(name);
}
-void
+static void
process_close(void)
{
u_int32_t id;
@@ -417,7 +417,7 @@ process_close(void)
send_status(id, status);
}
-void
+static void
process_read(void)
{
char buf[64*1024];
@@ -457,7 +457,7 @@ process_read(void)
send_status(id, status);
}
-void
+static void
process_write(void)
{
u_int32_t id;
@@ -495,7 +495,7 @@ process_write(void)
xfree(data);
}
-void
+static void
process_do_stat(int do_lstat)
{
Attrib a;
@@ -520,19 +520,19 @@ process_do_stat(int do_lstat)
xfree(name);
}
-void
+static void
process_stat(void)
{
process_do_stat(0);
}
-void
+static void
process_lstat(void)
{
process_do_stat(1);
}
-void
+static void
process_fstat(void)
{
Attrib a;
@@ -558,7 +558,7 @@ process_fstat(void)
send_status(id, status);
}
-struct timeval *
+static struct timeval *
attrib_to_tv(Attrib *a)
{
static struct timeval tv[2];
@@ -570,7 +570,7 @@ attrib_to_tv(Attrib *a)
return tv;
}
-void
+static void
process_setstat(void)
{
Attrib *a;
@@ -583,6 +583,11 @@ process_setstat(void)
name = get_string(NULL);
a = get_attrib();
TRACE("setstat id %d name %s", id, name);
+ if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
+ ret = truncate(name, a->size);
+ if (ret == -1)
+ status = errno_to_portable(errno);
+ }
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
ret = chmod(name, a->perm & 0777);
if (ret == -1)
@@ -602,7 +607,7 @@ process_setstat(void)
xfree(name);
}
-void
+static void
process_fsetstat(void)
{
Attrib *a;
@@ -618,6 +623,11 @@ process_fsetstat(void)
if (fd < 0) {
status = SSH2_FX_FAILURE;
} else {
+ if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
+ ret = ftruncate(fd, a->size);
+ if (ret == -1)
+ status = errno_to_portable(errno);
+ }
if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
ret = fchmod(fd, a->perm & 0777);
if (ret == -1)
@@ -637,7 +647,7 @@ process_fsetstat(void)
send_status(id, status);
}
-void
+static void
process_opendir(void)
{
DIR *dirp = NULL;
@@ -669,10 +679,10 @@ process_opendir(void)
/*
* drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh
*/
-char *
+static char *
ls_file(char *name, struct stat *st)
{
- int sz = 0;
+ int ulen, glen, sz = 0;
struct passwd *pw;
struct group *gr;
struct tm *ltime = localtime(&st->st_mtime);
@@ -700,12 +710,15 @@ ls_file(char *name, struct stat *st)
}
if (sz == 0)
tbuf[0] = '\0';
- snprintf(buf, sizeof buf, "%s %3d %-8.8s %-8.8s %8llu %s %s", mode,
- st->st_nlink, user, group, (unsigned long long)st->st_size, tbuf, name);
+ ulen = MAX(strlen(user), 8);
+ glen = MAX(strlen(group), 8);
+ snprintf(buf, sizeof buf, "%s %3d %-*s %-*s %8llu %s %s", mode,
+ st->st_nlink, ulen, user, glen, group,
+ (unsigned long long)st->st_size, tbuf, name);
return xstrdup(buf);
}
-void
+static void
process_readdir(void)
{
DIR *dirp;
@@ -733,8 +746,8 @@ process_readdir(void)
stats = xrealloc(stats, nstats * sizeof(Stat));
}
/* XXX OVERFLOW ? */
- snprintf(pathname, sizeof pathname,
- "%s/%s", path, dp->d_name);
+ snprintf(pathname, sizeof pathname, "%s%s%s", path,
+ strcmp(path, "/") ? "/" : "", dp->d_name);
if (lstat(pathname, &st) < 0)
continue;
stat_to_attrib(&st, &(stats[count].attrib));
@@ -748,7 +761,7 @@ process_readdir(void)
}
if (count > 0) {
send_names(id, count, stats);
- for(i = 0; i < count; i++) {
+ for (i = 0; i < count; i++) {
xfree(stats[i].name);
xfree(stats[i].long_name);
}
@@ -759,7 +772,7 @@ process_readdir(void)
}
}
-void
+static void
process_remove(void)
{
char *name;
@@ -776,7 +789,7 @@ process_remove(void)
xfree(name);
}
-void
+static void
process_mkdir(void)
{
Attrib *a;
@@ -796,7 +809,7 @@ process_mkdir(void)
xfree(name);
}
-void
+static void
process_rmdir(void)
{
u_int32_t id;
@@ -812,7 +825,7 @@ process_rmdir(void)
xfree(name);
}
-void
+static void
process_realpath(void)
{
char resolvedname[MAXPATHLEN];
@@ -837,7 +850,7 @@ process_realpath(void)
xfree(path);
}
-void
+static void
process_rename(void)
{
u_int32_t id;
@@ -859,22 +872,23 @@ process_rename(void)
xfree(newpath);
}
-void
+static void
process_readlink(void)
{
u_int32_t id;
+ int len;
char link[MAXPATHLEN];
char *path;
id = get_int();
path = get_string(NULL);
TRACE("readlink id %d path %s", id, path);
- if (readlink(path, link, sizeof(link) - 1) == -1)
+ if ((len = readlink(path, link, sizeof(link) - 1)) == -1)
send_status(id, errno_to_portable(errno));
else {
Stat s;
-
- link[sizeof(link) - 1] = '\0';
+
+ link[len] = '\0';
attrib_clear(&s.attrib);
s.name = s.long_name = link;
send_names(id, 1, &s);
@@ -882,7 +896,7 @@ process_readlink(void)
xfree(path);
}
-void
+static void
process_symlink(void)
{
u_int32_t id;
@@ -904,7 +918,7 @@ process_symlink(void)
xfree(newpath);
}
-void
+static void
process_extended(void)
{
u_int32_t id;
@@ -918,7 +932,7 @@ process_extended(void)
/* stolen from ssh-agent */
-void
+static void
process(void)
{
u_int msg_len;
@@ -927,7 +941,7 @@ process(void)
if (buffer_len(&iqueue) < 5)
return; /* Incomplete message. */
- cp = (u_char *) buffer_ptr(&iqueue);
+ cp = buffer_ptr(&iqueue);
msg_len = GET_32BIT(cp);
if (msg_len > 256 * 1024) {
error("bad message ");
OpenPOWER on IntegriCloud