mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 14:39:24 -05:00
And just to prove that psftp.c really is now platform-independent
... here's a Unix port of PSFTP. Woo. (Oddly PSCP looks to be somewhat harder; there's more Windows code interleaved than there was in PSFTP.) [originally from svn r3419]
This commit is contained in:
parent
e0801815c8
commit
66fa6f320e
2
Recipe
2
Recipe
@ -159,7 +159,7 @@ puttytel : [X] UXTERM uxmisc misc ldisc settings pty uxsel be_nossh uxstore
|
|||||||
|
|
||||||
plink : [U] uxplink uxcons NONSSH UXSSH be_all logging UXMISC signal ux_x11
|
plink : [U] uxplink uxcons NONSSH UXSSH be_all logging UXMISC signal ux_x11
|
||||||
|
|
||||||
# psftp : [U] psftp uxsftp console UXSSH be_none SFTP UXMISC
|
psftp : [U] psftp uxsftp uxcons UXSSH be_none SFTP UXMISC
|
||||||
|
|
||||||
PuTTY : [M] terminal wcwidth ldiscucs logging be_all mac macdlg macevlog
|
PuTTY : [M] terminal wcwidth ldiscucs logging be_all mac macdlg macevlog
|
||||||
+ macterm macucs mac_res.rsrc testback NONSSH MACSSH MACMISC CHARSET
|
+ macterm macucs mac_res.rsrc testback NONSSH MACSSH MACMISC CHARSET
|
||||||
|
19
psftp.c
19
psftp.c
@ -894,20 +894,20 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
|
|||||||
default:
|
default:
|
||||||
printf("chmod: file mode '%.*s' contains unrecognised"
|
printf("chmod: file mode '%.*s' contains unrecognised"
|
||||||
" user/group/other specifier '%c'\n",
|
" user/group/other specifier '%c'\n",
|
||||||
strcspn(modebegin, ","), modebegin, *mode);
|
(int)strcspn(modebegin, ","), modebegin, *mode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
mode++;
|
mode++;
|
||||||
}
|
}
|
||||||
if (!*mode || *mode == ',') {
|
if (!*mode || *mode == ',') {
|
||||||
printf("chmod: file mode '%.*s' is incomplete\n",
|
printf("chmod: file mode '%.*s' is incomplete\n",
|
||||||
strcspn(modebegin, ","), modebegin);
|
(int)strcspn(modebegin, ","), modebegin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
action = *mode++;
|
action = *mode++;
|
||||||
if (!*mode || *mode == ',') {
|
if (!*mode || *mode == ',') {
|
||||||
printf("chmod: file mode '%.*s' is incomplete\n",
|
printf("chmod: file mode '%.*s' is incomplete\n",
|
||||||
strcspn(modebegin, ","), modebegin);
|
(int)strcspn(modebegin, ","), modebegin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
perms = 0;
|
perms = 0;
|
||||||
@ -922,7 +922,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
|
|||||||
(subset & 06777) != 02070) {
|
(subset & 06777) != 02070) {
|
||||||
printf("chmod: file mode '%.*s': set[ug]id bit should"
|
printf("chmod: file mode '%.*s': set[ug]id bit should"
|
||||||
" be used with exactly one of u or g only\n",
|
" be used with exactly one of u or g only\n",
|
||||||
strcspn(modebegin, ","), modebegin);
|
(int)strcspn(modebegin, ","), modebegin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
perms |= 06000;
|
perms |= 06000;
|
||||||
@ -930,7 +930,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
|
|||||||
default:
|
default:
|
||||||
printf("chmod: file mode '%.*s' contains unrecognised"
|
printf("chmod: file mode '%.*s' contains unrecognised"
|
||||||
" permission specifier '%c'\n",
|
" permission specifier '%c'\n",
|
||||||
strcspn(modebegin, ","), modebegin, *mode);
|
(int)strcspn(modebegin, ","), modebegin, *mode);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
mode++;
|
mode++;
|
||||||
@ -938,7 +938,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
|
|||||||
if (!(subset & 06777) && (perms &~ subset)) {
|
if (!(subset & 06777) && (perms &~ subset)) {
|
||||||
printf("chmod: file mode '%.*s' contains no user/group/other"
|
printf("chmod: file mode '%.*s' contains no user/group/other"
|
||||||
" specifier and permissions other than 't' \n",
|
" specifier and permissions other than 't' \n",
|
||||||
strcspn(modebegin, ","), modebegin);
|
(int)strcspn(modebegin, ","), modebegin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
perms &= subset;
|
perms &= subset;
|
||||||
@ -1740,6 +1740,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
|
|||||||
{
|
{
|
||||||
char *host, *realhost;
|
char *host, *realhost;
|
||||||
const char *err;
|
const char *err;
|
||||||
|
void *logctx;
|
||||||
|
|
||||||
/* Separate host and username */
|
/* Separate host and username */
|
||||||
host = userhost;
|
host = userhost;
|
||||||
@ -1925,7 +1926,11 @@ int psftp_main(int argc, char *argv[])
|
|||||||
char *batchfile = NULL;
|
char *batchfile = NULL;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
||||||
flags = FLAG_STDERR | FLAG_INTERACTIVE | FLAG_SYNCAGENT;
|
flags = FLAG_STDERR | FLAG_INTERACTIVE
|
||||||
|
#ifdef FLAG_SYNCAGENT
|
||||||
|
| FLAG_SYNCAGENT
|
||||||
|
#endif
|
||||||
|
;
|
||||||
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
|
cmdline_tooltype = TOOLTYPE_FILETRANSFER;
|
||||||
ssh_get_line = &console_get_line;
|
ssh_get_line = &console_get_line;
|
||||||
sk_init();
|
sk_init();
|
||||||
|
6
psftp.h
6
psftp.h
@ -25,4 +25,10 @@ char *psftp_lcd(char *newdir);
|
|||||||
*/
|
*/
|
||||||
int ssh_sftp_loop_iteration(void);
|
int ssh_sftp_loop_iteration(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The main program in psftp.c. Called from main() in the platform-
|
||||||
|
* specific code, after doing any platform-specific initialisation.
|
||||||
|
*/
|
||||||
|
int psftp_main(int argc, char *argv[]);
|
||||||
|
|
||||||
#endif /* PUTTY_PSFTP_H */
|
#endif /* PUTTY_PSFTP_H */
|
||||||
|
5
sftp.c
5
sftp.c
@ -67,10 +67,12 @@ static struct sftp_packet *sftp_pkt_init(int pkt_type)
|
|||||||
sftp_pkt_addbyte(pkt, (unsigned char) pkt_type);
|
sftp_pkt_addbyte(pkt, (unsigned char) pkt_type);
|
||||||
return pkt;
|
return pkt;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
static void sftp_pkt_addbool(struct sftp_packet *pkt, unsigned char value)
|
static void sftp_pkt_addbool(struct sftp_packet *pkt, unsigned char value)
|
||||||
{
|
{
|
||||||
sftp_pkt_adddata(pkt, &value, 1);
|
sftp_pkt_adddata(pkt, &value, 1);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
static void sftp_pkt_adduint32(struct sftp_packet *pkt,
|
static void sftp_pkt_adduint32(struct sftp_packet *pkt,
|
||||||
unsigned long value)
|
unsigned long value)
|
||||||
{
|
{
|
||||||
@ -282,7 +284,6 @@ static tree234 *sftp_requests;
|
|||||||
|
|
||||||
static struct sftp_request *sftp_alloc_request(void)
|
static struct sftp_request *sftp_alloc_request(void)
|
||||||
{
|
{
|
||||||
const unsigned CHANNEL_NUMBER_OFFSET = 256;
|
|
||||||
unsigned low, high, mid;
|
unsigned low, high, mid;
|
||||||
int tsize;
|
int tsize;
|
||||||
struct sftp_request *r;
|
struct sftp_request *r;
|
||||||
@ -296,7 +297,7 @@ static struct sftp_request *sftp_alloc_request(void)
|
|||||||
* B-tree to find the largest ID which is in a contiguous
|
* B-tree to find the largest ID which is in a contiguous
|
||||||
* sequence from the beginning. (Precisely everything in that
|
* sequence from the beginning. (Precisely everything in that
|
||||||
* sequence must have ID equal to its tree index plus
|
* sequence must have ID equal to its tree index plus
|
||||||
* SEQUENCE_NUMBER_OFFSET.)
|
* REQUEST_ID_OFFSET.)
|
||||||
*/
|
*/
|
||||||
tsize = count234(sftp_requests);
|
tsize = count234(sftp_requests);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
Makefile.gtk Makefile
|
Makefile.gtk Makefile
|
||||||
local
|
local
|
||||||
plink pterm putty puttytel
|
plink pterm putty puttytel psftp
|
||||||
*.log
|
*.log
|
||||||
|
11
unix/unix.h
11
unix/unix.h
@ -51,8 +51,6 @@ unsigned long getticks(void); /* based on gettimeofday(2) */
|
|||||||
#define WCHAR wchar_t
|
#define WCHAR wchar_t
|
||||||
#define BYTE unsigned char
|
#define BYTE unsigned char
|
||||||
|
|
||||||
GLOBAL void *logctx;
|
|
||||||
|
|
||||||
/* Things pty.c needs from pterm.c */
|
/* Things pty.c needs from pterm.c */
|
||||||
char *get_x_display(void *frontend);
|
char *get_x_display(void *frontend);
|
||||||
int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */
|
int font_dimension(void *frontend, int which);/* 0 for width, 1 for height */
|
||||||
@ -128,4 +126,13 @@ int init_ucs(struct unicode_data *ucsdata,
|
|||||||
*/
|
*/
|
||||||
int sk_getxdmdata(void *sock, unsigned long *ip, int *port);
|
int sk_getxdmdata(void *sock, unsigned long *ip, int *port);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* General helpful Unix stuff: more helpful version of the FD_SET
|
||||||
|
* macro, which also handles maxfd.
|
||||||
|
*/
|
||||||
|
#define FD_SET_MAX(fd, max, set) do { \
|
||||||
|
FD_SET(fd, &set); \
|
||||||
|
if (max < fd + 1) max = fd + 1; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
int console_batch_mode = FALSE;
|
int console_batch_mode = FALSE;
|
||||||
|
|
||||||
|
static void *console_logctx = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Clean up and exit.
|
* Clean up and exit.
|
||||||
*/
|
*/
|
||||||
@ -258,9 +260,15 @@ void old_keyfile_warning(void)
|
|||||||
fputs(message, stderr);
|
fputs(message, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void console_provide_logctx(void *logctx)
|
||||||
|
{
|
||||||
|
console_logctx = logctx;
|
||||||
|
}
|
||||||
|
|
||||||
void logevent(void *frontend, const char *string)
|
void logevent(void *frontend, const char *string)
|
||||||
{
|
{
|
||||||
log_eventlog(logctx, string);
|
if (console_logctx)
|
||||||
|
log_eventlog(console_logctx, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
int console_get_line(const char *prompt, char *str,
|
int console_get_line(const char *prompt, char *str,
|
||||||
|
@ -14,12 +14,6 @@
|
|||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
/* More helpful version of the FD_SET macro, to also handle maxfd. */
|
|
||||||
#define FD_SET_MAX(fd, max, set) do { \
|
|
||||||
FD_SET(fd, &set); \
|
|
||||||
if (max < fd + 1) max = fd + 1; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
|
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
|
||||||
#include "putty.h"
|
#include "putty.h"
|
||||||
#include "storage.h"
|
#include "storage.h"
|
||||||
@ -287,7 +281,7 @@ int main(int argc, char **argv)
|
|||||||
int connopen;
|
int connopen;
|
||||||
int exitcode;
|
int exitcode;
|
||||||
int errors;
|
int errors;
|
||||||
void *ldisc;
|
void *ldisc, *logctx;
|
||||||
|
|
||||||
ssh_get_line = console_get_line;
|
ssh_get_line = console_get_line;
|
||||||
|
|
||||||
@ -573,6 +567,7 @@ int main(int argc, char **argv)
|
|||||||
* Start up the connection.
|
* Start up the connection.
|
||||||
*/
|
*/
|
||||||
logctx = log_init(NULL, &cfg);
|
logctx = log_init(NULL, &cfg);
|
||||||
|
console_provide_logctx(logctx);
|
||||||
{
|
{
|
||||||
const char *error;
|
const char *error;
|
||||||
char *realhost;
|
char *realhost;
|
||||||
|
224
unix/uxsftp.c
Normal file
224
unix/uxsftp.c
Normal file
@ -0,0 +1,224 @@
|
|||||||
|
/*
|
||||||
|
* uxsftp.c: the Unix-specific parts of PSFTP.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
|
#include "putty.h"
|
||||||
|
#include "psftp.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In PSFTP our selects are synchronous, so these functions are
|
||||||
|
* empty stubs.
|
||||||
|
*/
|
||||||
|
int uxsel_input_add(int fd, int rwx) { return 0; }
|
||||||
|
void uxsel_input_remove(int id) { }
|
||||||
|
|
||||||
|
char *x_get_default(const char *key)
|
||||||
|
{
|
||||||
|
return NULL; /* this is a stub */
|
||||||
|
}
|
||||||
|
|
||||||
|
void platform_get_x11_auth(char *display, int *protocol,
|
||||||
|
unsigned char *data, int *datalen)
|
||||||
|
{
|
||||||
|
/* Do nothing, therefore no auth. */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Default settings that are specific to PSFTP.
|
||||||
|
*/
|
||||||
|
char *platform_default_s(const char *name)
|
||||||
|
{
|
||||||
|
if (!strcmp(name, "UserName")) {
|
||||||
|
/*
|
||||||
|
* Remote login username will default to the local username.
|
||||||
|
*/
|
||||||
|
struct passwd *p;
|
||||||
|
uid_t uid = getuid();
|
||||||
|
char *user, *ret = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First, find who we think we are using getlogin. If this
|
||||||
|
* agrees with our uid, we'll go along with it. This should
|
||||||
|
* allow sharing of uids between several login names whilst
|
||||||
|
* coping correctly with people who have su'ed.
|
||||||
|
*/
|
||||||
|
user = getlogin();
|
||||||
|
setpwent();
|
||||||
|
if (user)
|
||||||
|
p = getpwnam(user);
|
||||||
|
else
|
||||||
|
p = NULL;
|
||||||
|
if (p && p->pw_uid == uid) {
|
||||||
|
/*
|
||||||
|
* The result of getlogin() really does correspond to
|
||||||
|
* our uid. Fine.
|
||||||
|
*/
|
||||||
|
ret = user;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* If that didn't work, for whatever reason, we'll do
|
||||||
|
* the simpler version: look up our uid in the password
|
||||||
|
* file and map it straight to a name.
|
||||||
|
*/
|
||||||
|
p = getpwuid(uid);
|
||||||
|
ret = p->pw_name;
|
||||||
|
}
|
||||||
|
endpwent();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int platform_default_i(const char *name, int def)
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
FontSpec platform_default_fontspec(const char *name)
|
||||||
|
{
|
||||||
|
FontSpec ret;
|
||||||
|
*ret.name = '\0';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
Filename platform_default_filename(const char *name)
|
||||||
|
{
|
||||||
|
Filename ret;
|
||||||
|
if (!strcmp(name, "LogFileName"))
|
||||||
|
strcpy(ret.path, "putty.log");
|
||||||
|
else
|
||||||
|
*ret.path = '\0';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set local current directory. Returns NULL on success, or else an
|
||||||
|
* error message which must be freed after printing.
|
||||||
|
*/
|
||||||
|
char *psftp_lcd(char *dir)
|
||||||
|
{
|
||||||
|
if (chdir(dir) < 0)
|
||||||
|
return dupprintf("%s: chdir: %s", dir, strerror(errno));
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get local current directory. Returns a string which must be
|
||||||
|
* freed.
|
||||||
|
*/
|
||||||
|
char *psftp_getcwd(void)
|
||||||
|
{
|
||||||
|
char *buffer, *ret;
|
||||||
|
int size = 256;
|
||||||
|
|
||||||
|
buffer = snewn(size, char);
|
||||||
|
while (1) {
|
||||||
|
ret = getcwd(buffer, size);
|
||||||
|
if (ret != NULL)
|
||||||
|
return ret;
|
||||||
|
if (errno != ERANGE) {
|
||||||
|
sfree(buffer);
|
||||||
|
return dupprintf("[cwd unavailable: %s]", strerror(errno));
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Otherwise, ERANGE was returned, meaning the buffer
|
||||||
|
* wasn't big enough.
|
||||||
|
*/
|
||||||
|
size = size * 3 / 2;
|
||||||
|
buffer = sresize(buffer, size, char);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait for some network data and process it.
|
||||||
|
*/
|
||||||
|
int ssh_sftp_loop_iteration(void)
|
||||||
|
{
|
||||||
|
fd_set rset, wset, xset;
|
||||||
|
int i, fdcount, fdsize, *fdlist;
|
||||||
|
int fd, fdstate, rwx, ret, maxfd;
|
||||||
|
|
||||||
|
fdlist = NULL;
|
||||||
|
fdcount = fdsize = 0;
|
||||||
|
|
||||||
|
/* Count the currently active fds. */
|
||||||
|
i = 0;
|
||||||
|
for (fd = first_fd(&fdstate, &rwx); fd >= 0;
|
||||||
|
fd = next_fd(&fdstate, &rwx)) i++;
|
||||||
|
|
||||||
|
if (i < 1)
|
||||||
|
return -1; /* doom */
|
||||||
|
|
||||||
|
/* Expand the fdlist buffer if necessary. */
|
||||||
|
if (i > fdsize) {
|
||||||
|
fdsize = i + 16;
|
||||||
|
fdlist = sresize(fdlist, fdsize, int);
|
||||||
|
}
|
||||||
|
|
||||||
|
FD_ZERO(&rset);
|
||||||
|
FD_ZERO(&wset);
|
||||||
|
FD_ZERO(&xset);
|
||||||
|
maxfd = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add all currently open fds to the select sets, and store
|
||||||
|
* them in fdlist as well.
|
||||||
|
*/
|
||||||
|
fdcount = 0;
|
||||||
|
for (fd = first_fd(&fdstate, &rwx); fd >= 0;
|
||||||
|
fd = next_fd(&fdstate, &rwx)) {
|
||||||
|
fdlist[fdcount++] = fd;
|
||||||
|
if (rwx & 1)
|
||||||
|
FD_SET_MAX(fd, maxfd, rset);
|
||||||
|
if (rwx & 2)
|
||||||
|
FD_SET_MAX(fd, maxfd, wset);
|
||||||
|
if (rwx & 4)
|
||||||
|
FD_SET_MAX(fd, maxfd, xset);
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
ret = select(maxfd, &rset, &wset, &xset, NULL);
|
||||||
|
} while (ret < 0 && errno == EINTR);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("select");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < fdcount; i++) {
|
||||||
|
fd = fdlist[i];
|
||||||
|
/*
|
||||||
|
* We must process exceptional notifications before
|
||||||
|
* ordinary readability ones, or we may go straight
|
||||||
|
* past the urgent marker.
|
||||||
|
*/
|
||||||
|
if (FD_ISSET(fd, &xset))
|
||||||
|
select_result(fd, 4);
|
||||||
|
if (FD_ISSET(fd, &rset))
|
||||||
|
select_result(fd, 1);
|
||||||
|
if (FD_ISSET(fd, &wset))
|
||||||
|
select_result(fd, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
sfree(fdlist);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Main program: do platform-specific initialisation and then call
|
||||||
|
* psftp_main().
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
uxsel_init();
|
||||||
|
return psftp_main(argc, argv);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user