View | Details | Raw Unified | Return to bug 2067 | Differences between
and this patch

Collapse All | Expand All

(-)openssh-5.8p1-orig/sftp.c (-1 / +70 lines)
Lines 49-55 typedef void EditLine; Link Here
49
#include <string.h>
51
#include <string.h>
50
#include <unistd.h>
52
#include <unistd.h>
51
#include <stdarg.h>
53
#include <stdarg.h>
52
54
#include <time.h>
53
#ifdef HAVE_UTIL_H
55
#ifdef HAVE_UTIL_H
54
# include <util.h>
56
# include <util.h>
55
#endif
57
#endif
Lines 149-154 extern char *__progname; Link Here
149
#define I_SYMLINK	21
151
#define I_SYMLINK	21
150
#define I_VERSION	22
152
#define I_VERSION	22
151
#define I_PROGRESS	23
153
#define I_PROGRESS	23
154
#define I_TOUCH         26
152
155
153
struct CMD {
156
struct CMD {
154
	const char *c;
157
	const char *c;
Lines 192-197 static const struct CMD cmds[] = { Link Here
192
	{ "rm",		I_RM,		REMOTE	},
195
	{ "rm",		I_RM,		REMOTE	},
193
	{ "rmdir",	I_RMDIR,	REMOTE	},
196
	{ "rmdir",	I_RMDIR,	REMOTE	},
194
	{ "symlink",	I_SYMLINK,	REMOTE	},
197
	{ "symlink",	I_SYMLINK,	REMOTE	},
198
	{ "touch",	I_TOUCH,        REMOTE	},
195
	{ "version",	I_VERSION,	NOARGS	},
199
	{ "version",	I_VERSION,	NOARGS	},
196
	{ "!",		I_SHELL,	NOARGS	},
200
	{ "!",		I_SHELL,	NOARGS	},
197
	{ "?",		I_HELP,		NOARGS	},
201
	{ "?",		I_HELP,		NOARGS	},
Lines 254-259 help(void) Link Here
254
	    "rm path                            Delete remote file\n"
258
	    "rm path                            Delete remote file\n"
255
	    "rmdir path                         Remove remote directory\n"
259
	    "rmdir path                         Remove remote directory\n"
256
	    "symlink oldpath newpath            Symlink remote file\n"
260
	    "symlink oldpath newpath            Symlink remote file\n"
261
	    "touch [-h] path                    Touch remote file to create it or set timestamp (-h for symlink)\n"
257
	    "version                            Show SFTP version\n"
262
	    "version                            Show SFTP version\n"
258
	    "!command                           Execute 'command' in local shell\n"
263
	    "!command                           Execute 'command' in local shell\n"
259
	    "!                                  Escape to local shell\n"
264
	    "!                                  Escape to local shell\n"
Lines 482-487 parse_df_flags(const char *cmd, char **a Link Here
482
}
487
}
483
488
484
static int
489
static int
490
parse_touch_flags(const char *cmd, char **argv, int argc, int *hflag)
491
{
492
	extern int opterr, optind, optopt, optreset;
493
	int ch;
494
495
	optind = optreset = 1;
496
	opterr = 0;
497
498
	*hflag = 0;
499
	while ((ch = getopt(argc, argv, "h")) != -1) {
500
		switch (ch) {
501
		case 'h':
502
			*hflag = 1;
503
			break;
504
		default:
505
			error("%s: Invalid flag -%c", cmd, optopt);
506
			return -1;
507
		}
508
	}
509
510
	return optind;
511
}
512
513
static int
485
is_dir(char *path)
514
is_dir(char *path)
486
{
515
{
487
	struct stat sb;
516
	struct stat sb;
Lines 675-680 out: Link Here
675
	return(err);
704
	return(err);
676
}
705
}
677
706
707
int
708
process_touch(struct sftp_conn *conn, char *path, Attrib *a, int hflag)
709
{               
710
        time_t t;
711
	int err = 0;
712
713
	t = time(NULL);
714
	a->flags |= SSH2_FILEXFER_ATTR_ACMODTIME;
715
	a->atime = t;
716
	a->mtime = t;
717
	
718
	debug3("Looking up %s", path);
719
	if (hflag) {
720
	  err=do_lstat(conn,path,1);
721
	  if (err == NULL)
722
	    error("touch: setting times of `link3': No such file or directory",path);
723
	  else
724
	    do_lsetstat(conn, path, a);
725
	}
726
	else {
727
	  err=do_stat(conn,path,1);
728
	  if (err == NULL)
729
	    /* File not found, create it. */
730
	    err=do_create(conn, path, a);
731
	  else
732
	    /* file exists, do (l)setstat to update timestamp */
733
	    do_setstat(conn, path, a);
734
	}
735
	return(err);
736
}
737
678
static int
738
static int
679
sdirent_comp(const void *aa, const void *bb)
739
sdirent_comp(const void *aa, const void *bb)
680
{
740
{
Lines 1274-1279 parse_args(const char **cpp, int *pflag, Link Here
1274
	case I_VERSION:
1335
	case I_VERSION:
1275
	case I_PROGRESS:
1336
	case I_PROGRESS:
1276
		break;
1337
		break;
1338
	case I_TOUCH:
1339
		if ((optidx = parse_touch_flags(cmd, argv, argc, hflag)) == -1)
1340
		  return -1;
1341
                *path1 = xstrdup(argv[optidx]);
1342
	        undo_glob_escape(*path1);
1343
		break;
1277
	default:
1344
	default:
1278
		fatal("Command not implemented");
1345
		fatal("Command not implemented");
1279
	}
1346
	}
Lines 1498-1503 parse_dispatch_command(struct sftp_conn Link Here
1498
		else
1564
		else
1499
			printf("Progress meter disabled\n");
1565
			printf("Progress meter disabled\n");
1500
		break;
1566
		break;
1567
	case I_TOUCH:
1568
	        path1 = make_absolute(path1, *pwd);
1569
		attrib_clear(&a);
1570
		process_touch(conn, path1, &a, hflag);
1571
		break;
1501
	default:
1572
	default:
1502
		fatal("%d is not implemented", cmdnum);
1573
		fatal("%d is not implemented", cmdnum);
1503
	}
1574
	}

Return to bug 2067