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

Collapse All | Expand All

(-)a/includes.h (-6 / +1 lines)
Lines 32-43 Link Here
32
#ifdef HAVE_BSTRING_H
32
#ifdef HAVE_BSTRING_H
33
# include <bstring.h>
33
# include <bstring.h>
34
#endif
34
#endif
35
#if defined(HAVE_GLOB_H) && defined(GLOB_HAS_ALTDIRFUNC) && \
35
#include <glob.h>
36
    defined(GLOB_HAS_GL_MATCHC) && defined(GLOB_HAS_GL_STATV) && \
37
    defined(HAVE_DECL_GLOB_NOMATCH) &&  HAVE_DECL_GLOB_NOMATCH != 0 && \
38
    !defined(BROKEN_GLOB)
39
# include <glob.h>
40
#endif
41
#ifdef HAVE_ENDIAN_H
36
#ifdef HAVE_ENDIAN_H
42
# include <endian.h>
37
# include <endian.h>
43
#endif
38
#endif
(-)a/openbsd-compat/glob.c (-78 / +78 lines)
Lines 129-140 typedef char Char; Link Here
129
#define	M_CLASS		META(':')
129
#define	M_CLASS		META(':')
130
#define	ismeta(c)	(((c)&M_QUOTE) != 0)
130
#define	ismeta(c)	(((c)&M_QUOTE) != 0)
131
131
132
#define	GLOB_LIMIT_MALLOC	65536
132
#define	COMPAT_GLOB_LIMIT_MALLOC	65536
133
#define	GLOB_LIMIT_STAT		128
133
#define	COMPAT_GLOB_LIMIT_STAT		128
134
#define	GLOB_LIMIT_READDIR	16384
134
#define	COMPAT_GLOB_LIMIT_READDIR	16384
135
135
136
/* Limit of recursion during matching attempts. */
136
/* Limit of recursion during matching attempts. */
137
#define GLOB_LIMIT_RECUR	64
137
#define COMPAT_GLOB_LIMIT_RECUR	64
138
138
139
struct glob_lim {
139
struct glob_lim {
140
	size_t	glim_malloc;
140
	size_t	glim_malloc;
Lines 150-172 struct glob_path_stat { Link Here
150
static int	 compare(const void *, const void *);
150
static int	 compare(const void *, const void *);
151
static int	 compare_gps(const void *, const void *);
151
static int	 compare_gps(const void *, const void *);
152
static int	 g_Ctoc(const Char *, char *, u_int);
152
static int	 g_Ctoc(const Char *, char *, u_int);
153
static int	 g_lstat(Char *, struct stat *, glob_t *);
153
static int	 g_lstat(Char *, struct stat *, compat_glob_t *);
154
static DIR	*g_opendir(Char *, glob_t *);
154
static DIR	*g_opendir(Char *, compat_glob_t *);
155
static Char	*g_strchr(const Char *, int);
155
static Char	*g_strchr(const Char *, int);
156
static int	 g_strncmp(const Char *, const char *, size_t);
156
static int	 g_strncmp(const Char *, const char *, size_t);
157
static int	 g_stat(Char *, struct stat *, glob_t *);
157
static int	 g_stat(Char *, struct stat *, compat_glob_t *);
158
static int	 glob0(const Char *, glob_t *, struct glob_lim *);
158
static int	 glob0(const Char *, compat_glob_t *, struct glob_lim *);
159
static int	 glob1(Char *, Char *, glob_t *, struct glob_lim *);
159
static int	 glob1(Char *, Char *, compat_glob_t *, struct glob_lim *);
160
static int	 glob2(Char *, Char *, Char *, Char *, Char *, Char *,
160
static int	 glob2(Char *, Char *, Char *, Char *, Char *, Char *,
161
		    glob_t *, struct glob_lim *);
161
		    compat_glob_t *, struct glob_lim *);
162
static int	 glob3(Char *, Char *, Char *, Char *, Char *,
162
static int	 glob3(Char *, Char *, Char *, Char *, Char *,
163
		    Char *, Char *, glob_t *, struct glob_lim *);
163
		    Char *, Char *, compat_glob_t *, struct glob_lim *);
164
static int	 globextend(const Char *, glob_t *, struct glob_lim *,
164
static int	 globextend(const Char *, compat_glob_t *, struct glob_lim *,
165
		    struct stat *);
165
		    struct stat *);
166
static const Char *
166
static const Char *
167
		 globtilde(const Char *, Char *, size_t, glob_t *);
167
		 globtilde(const Char *, Char *, size_t, compat_glob_t *);
168
static int	 globexp1(const Char *, glob_t *, struct glob_lim *);
168
static int	 globexp1(const Char *, compat_glob_t *, struct glob_lim *);
169
static int	 globexp2(const Char *, const Char *, glob_t *,
169
static int	 globexp2(const Char *, const Char *, compat_glob_t *,
170
		    struct glob_lim *);
170
		    struct glob_lim *);
171
static int	 match(Char *, Char *, Char *, int);
171
static int	 match(Char *, Char *, Char *, int);
172
#ifdef DEBUG
172
#ifdef DEBUG
Lines 174-181 static void qprintf(const char *, Char *); Link Here
174
#endif
174
#endif
175
175
176
int
176
int
177
glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
177
compat_glob(const char *pattern, int flags, int (*errfunc)(const char *, int),
178
    glob_t *pglob)
178
    compat_glob_t *pglob)
179
{
179
{
180
	const u_char *patnext;
180
	const u_char *patnext;
181
	int c;
181
	int c;
Lines 183-210 glob(const char *pattern, int flags, int (*errfunc)(const char *, int), Link Here
183
	struct glob_lim limit = { 0, 0, 0 };
183
	struct glob_lim limit = { 0, 0, 0 };
184
184
185
	if (strnlen(pattern, PATH_MAX) == PATH_MAX)
185
	if (strnlen(pattern, PATH_MAX) == PATH_MAX)
186
		return(GLOB_NOMATCH);
186
		return(COMPAT_GLOB_NOMATCH);
187
187
188
	patnext = (u_char *) pattern;
188
	patnext = (u_char *) pattern;
189
	if (!(flags & GLOB_APPEND)) {
189
	if (!(flags & COMPAT_GLOB_APPEND)) {
190
		pglob->gl_pathc = 0;
190
		pglob->gl_pathc = 0;
191
		pglob->gl_pathv = NULL;
191
		pglob->gl_pathv = NULL;
192
		pglob->gl_statv = NULL;
192
		pglob->gl_statv = NULL;
193
		if (!(flags & GLOB_DOOFFS))
193
		if (!(flags & COMPAT_GLOB_DOOFFS))
194
			pglob->gl_offs = 0;
194
			pglob->gl_offs = 0;
195
	}
195
	}
196
	pglob->gl_flags = flags & ~GLOB_MAGCHAR;
196
	pglob->gl_flags = flags & ~COMPAT_GLOB_MAGCHAR;
197
	pglob->gl_errfunc = errfunc;
197
	pglob->gl_errfunc = errfunc;
198
	pglob->gl_matchc = 0;
198
	pglob->gl_matchc = 0;
199
199
200
	if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 ||
200
	if (pglob->gl_offs < 0 || pglob->gl_pathc < 0 ||
201
	    pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX ||
201
	    pglob->gl_offs >= INT_MAX || pglob->gl_pathc >= INT_MAX ||
202
	    pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1)
202
	    pglob->gl_pathc >= INT_MAX - pglob->gl_offs - 1)
203
		return GLOB_NOSPACE;
203
		return COMPAT_GLOB_NOSPACE;
204
204
205
	bufnext = patbuf;
205
	bufnext = patbuf;
206
	bufend = bufnext + MAXPATHLEN - 1;
206
	bufend = bufnext + MAXPATHLEN - 1;
207
	if (flags & GLOB_NOESCAPE)
207
	if (flags & COMPAT_GLOB_NOESCAPE)
208
		while (bufnext < bufend && (c = *patnext++) != EOS)
208
		while (bufnext < bufend && (c = *patnext++) != EOS)
209
			*bufnext++ = c;
209
			*bufnext++ = c;
210
	else {
210
	else {
Lines 221-227 glob(const char *pattern, int flags, int (*errfunc)(const char *, int), Link Here
221
	}
221
	}
222
	*bufnext = EOS;
222
	*bufnext = EOS;
223
223
224
	if (flags & GLOB_BRACE)
224
	if (flags & COMPAT_GLOB_BRACE)
225
		return globexp1(patbuf, pglob, &limit);
225
		return globexp1(patbuf, pglob, &limit);
226
	else
226
	else
227
		return glob0(patbuf, pglob, &limit);
227
		return glob0(patbuf, pglob, &limit);
Lines 233-239 glob(const char *pattern, int flags, int (*errfunc)(const char *, int), Link Here
233
 * characters
233
 * characters
234
 */
234
 */
235
static int
235
static int
236
globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
236
globexp1(const Char *pattern, compat_glob_t *pglob, struct glob_lim *limitp)
237
{
237
{
238
	const Char* ptr = pattern;
238
	const Char* ptr = pattern;
239
239
Lines 254-260 globexp1(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) Link Here
254
 * If it fails then it tries to glob the rest of the pattern and returns.
254
 * If it fails then it tries to glob the rest of the pattern and returns.
255
 */
255
 */
256
static int
256
static int
257
globexp2(const Char *ptr, const Char *pattern, glob_t *pglob,
257
globexp2(const Char *ptr, const Char *pattern, compat_glob_t *pglob,
258
    struct glob_lim *limitp)
258
    struct glob_lim *limitp)
259
{
259
{
260
	int     i, rv;
260
	int     i, rv;
Lines 338-344 globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, Link Here
338
				qprintf("globexp2:", patbuf);
338
				qprintf("globexp2:", patbuf);
339
#endif
339
#endif
340
				rv = globexp1(patbuf, pglob, limitp);
340
				rv = globexp1(patbuf, pglob, limitp);
341
				if (rv && rv != GLOB_NOMATCH)
341
				if (rv && rv != COMPAT_GLOB_NOMATCH)
342
					return rv;
342
					return rv;
343
343
344
				/* move after the comma, to the next string */
344
				/* move after the comma, to the next string */
Lines 359-372 globexp2(const Char *ptr, const Char *pattern, glob_t *pglob, Link Here
359
 * expand tilde from the passwd file.
359
 * expand tilde from the passwd file.
360
 */
360
 */
361
static const Char *
361
static const Char *
362
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, glob_t *pglob)
362
globtilde(const Char *pattern, Char *patbuf, size_t patbuf_len, compat_glob_t *pglob)
363
{
363
{
364
	struct passwd *pwd;
364
	struct passwd *pwd;
365
	char *h;
365
	char *h;
366
	const Char *p;
366
	const Char *p;
367
	Char *b, *eb;
367
	Char *b, *eb;
368
368
369
	if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
369
	if (*pattern != TILDE || !(pglob->gl_flags & COMPAT_GLOB_TILDE))
370
		return pattern;
370
		return pattern;
371
371
372
	/* Copy up to the end of the string or / */
372
	/* Copy up to the end of the string or / */
Lines 468-474 g_charclass(const Char **patternp, Char **bufnextp) Link Here
468
 * to find no matches.
468
 * to find no matches.
469
 */
469
 */
470
static int
470
static int
471
glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp)
471
glob0(const Char *pattern, compat_glob_t *pglob, struct glob_lim *limitp)
472
{
472
{
473
	const Char *qpatnext;
473
	const Char *qpatnext;
474
	int c, err, oldpathc;
474
	int c, err, oldpathc;
Lines 506-513 glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) Link Here
506
						c = *qpatnext++;
506
						c = *qpatnext++;
507
					} while (c == LBRACKET && *qpatnext == ':');
507
					} while (c == LBRACKET && *qpatnext == ':');
508
					if (err == -1 &&
508
					if (err == -1 &&
509
					    !(pglob->gl_flags & GLOB_NOCHECK))
509
					    !(pglob->gl_flags & COMPAT_GLOB_NOCHECK))
510
						return GLOB_NOMATCH;
510
						return COMPAT_GLOB_NOMATCH;
511
					if (c == RBRACKET)
511
					if (c == RBRACKET)
512
						break;
512
						break;
513
				}
513
				}
Lines 519-533 glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) Link Here
519
					qpatnext += 2;
519
					qpatnext += 2;
520
				}
520
				}
521
			} while ((c = *qpatnext++) != RBRACKET);
521
			} while ((c = *qpatnext++) != RBRACKET);
522
			pglob->gl_flags |= GLOB_MAGCHAR;
522
			pglob->gl_flags |= COMPAT_GLOB_MAGCHAR;
523
			*bufnext++ = M_END;
523
			*bufnext++ = M_END;
524
			break;
524
			break;
525
		case QUESTION:
525
		case QUESTION:
526
			pglob->gl_flags |= GLOB_MAGCHAR;
526
			pglob->gl_flags |= COMPAT_GLOB_MAGCHAR;
527
			*bufnext++ = M_ONE;
527
			*bufnext++ = M_ONE;
528
			break;
528
			break;
529
		case STAR:
529
		case STAR:
530
			pglob->gl_flags |= GLOB_MAGCHAR;
530
			pglob->gl_flags |= COMPAT_GLOB_MAGCHAR;
531
			/* collapse adjacent stars to one,
531
			/* collapse adjacent stars to one,
532
			 * to avoid exponential behavior
532
			 * to avoid exponential behavior
533
			 */
533
			 */
Lines 554-568 glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) Link Here
554
	 * GLOB_NOMAGIC is there just for compatibility with csh.
554
	 * GLOB_NOMAGIC is there just for compatibility with csh.
555
	 */
555
	 */
556
	if (pglob->gl_pathc == oldpathc) {
556
	if (pglob->gl_pathc == oldpathc) {
557
		if ((pglob->gl_flags & GLOB_NOCHECK) ||
557
		if ((pglob->gl_flags & COMPAT_GLOB_NOCHECK) ||
558
		    ((pglob->gl_flags & GLOB_NOMAGIC) &&
558
		    ((pglob->gl_flags & COMPAT_GLOB_NOMAGIC) &&
559
		    !(pglob->gl_flags & GLOB_MAGCHAR)))
559
		    !(pglob->gl_flags & COMPAT_GLOB_MAGCHAR)))
560
			return(globextend(pattern, pglob, limitp, NULL));
560
			return(globextend(pattern, pglob, limitp, NULL));
561
		else
561
		else
562
			return(GLOB_NOMATCH);
562
			return(COMPAT_GLOB_NOMATCH);
563
	}
563
	}
564
	if (!(pglob->gl_flags & GLOB_NOSORT)) {
564
	if (!(pglob->gl_flags & COMPAT_GLOB_NOSORT)) {
565
		if ((pglob->gl_flags & GLOB_KEEPSTAT)) {
565
		if ((pglob->gl_flags & COMPAT_GLOB_KEEPSTAT)) {
566
			/* Keep the paths and stat info synced during sort */
566
			/* Keep the paths and stat info synced during sort */
567
			struct glob_path_stat *path_stat;
567
			struct glob_path_stat *path_stat;
568
			int i;
568
			int i;
Lines 570-576 glob0(const Char *pattern, glob_t *pglob, struct glob_lim *limitp) Link Here
570
			int o = pglob->gl_offs + oldpathc;
570
			int o = pglob->gl_offs + oldpathc;
571
571
572
			if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL)
572
			if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL)
573
				return GLOB_NOSPACE;
573
				return COMPAT_GLOB_NOSPACE;
574
			for (i = 0; i < n; i++) {
574
			for (i = 0; i < n; i++) {
575
				path_stat[i].gps_path = pglob->gl_pathv[o + i];
575
				path_stat[i].gps_path = pglob->gl_pathv[o + i];
576
				path_stat[i].gps_stat = pglob->gl_statv[o + i];
576
				path_stat[i].gps_stat = pglob->gl_statv[o + i];
Lines 606-612 compare_gps(const void *_p, const void *_q) Link Here
606
}
606
}
607
607
608
static int
608
static int
609
glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
609
glob1(Char *pattern, Char *pattern_last, compat_glob_t *pglob, struct glob_lim *limitp)
610
{
610
{
611
	Char pathbuf[MAXPATHLEN];
611
	Char pathbuf[MAXPATHLEN];
612
612
Lines 625-631 glob1(Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp) Link Here
625
 */
625
 */
626
static int
626
static int
627
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
627
glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
628
    Char *pattern, Char *pattern_last, glob_t *pglob, struct glob_lim *limitp)
628
    Char *pattern, Char *pattern_last, compat_glob_t *pglob, struct glob_lim *limitp)
629
{
629
{
630
	struct stat sb;
630
	struct stat sb;
631
	Char *p, *q;
631
	Char *p, *q;
Lines 641-655 glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
641
			if (g_lstat(pathbuf, &sb, pglob))
641
			if (g_lstat(pathbuf, &sb, pglob))
642
				return(0);
642
				return(0);
643
643
644
			if ((pglob->gl_flags & GLOB_LIMIT) &&
644
			if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) &&
645
			    limitp->glim_stat++ >= GLOB_LIMIT_STAT) {
645
			    limitp->glim_stat++ >= COMPAT_GLOB_LIMIT_STAT) {
646
				errno = 0;
646
				errno = 0;
647
				*pathend++ = SEP;
647
				*pathend++ = SEP;
648
				*pathend = EOS;
648
				*pathend = EOS;
649
				return(GLOB_NOSPACE);
649
				return(COMPAT_GLOB_NOSPACE);
650
			}
650
			}
651
651
652
			if (((pglob->gl_flags & GLOB_MARK) &&
652
			if (((pglob->gl_flags & COMPAT_GLOB_MARK) &&
653
			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) ||
653
			    pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) ||
654
			    (S_ISLNK(sb.st_mode) &&
654
			    (S_ISLNK(sb.st_mode) &&
655
			    (g_stat(pathbuf, &sb, pglob) == 0) &&
655
			    (g_stat(pathbuf, &sb, pglob) == 0) &&
Lines 693-699 glob2(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
693
693
694
static int
694
static int
695
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
695
glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last,
696
    Char *pattern, Char *restpattern, Char *restpattern_last, glob_t *pglob,
696
    Char *pattern, Char *restpattern, Char *restpattern_last, compat_glob_t *pglob,
697
    struct glob_lim *limitp)
697
    struct glob_lim *limitp)
698
{
698
{
699
	struct dirent *dp;
699
	struct dirent *dp;
Lines 718-727 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
718
		/* TODO: don't call for ENOENT or ENOTDIR? */
718
		/* TODO: don't call for ENOENT or ENOTDIR? */
719
		if (pglob->gl_errfunc) {
719
		if (pglob->gl_errfunc) {
720
			if (g_Ctoc(pathbuf, buf, sizeof(buf)))
720
			if (g_Ctoc(pathbuf, buf, sizeof(buf)))
721
				return(GLOB_ABORTED);
721
				return(COMPAT_GLOB_ABORTED);
722
			if (pglob->gl_errfunc(buf, errno) ||
722
			if (pglob->gl_errfunc(buf, errno) ||
723
			    pglob->gl_flags & GLOB_ERR)
723
			    pglob->gl_flags & COMPAT_GLOB_ERR)
724
				return(GLOB_ABORTED);
724
				return(COMPAT_GLOB_ABORTED);
725
		}
725
		}
726
		return(0);
726
		return(0);
727
	}
727
	}
Lines 729-735 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
729
	err = 0;
729
	err = 0;
730
730
731
	/* Search directory for matching names. */
731
	/* Search directory for matching names. */
732
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
732
	if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC)
733
		readdirfunc = pglob->gl_readdir;
733
		readdirfunc = pglob->gl_readdir;
734
	else
734
	else
735
		readdirfunc = (struct dirent *(*)(void *))readdir;
735
		readdirfunc = (struct dirent *(*)(void *))readdir;
Lines 737-748 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
737
		u_char *sc;
737
		u_char *sc;
738
		Char *dc;
738
		Char *dc;
739
739
740
		if ((pglob->gl_flags & GLOB_LIMIT) &&
740
		if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) &&
741
		    limitp->glim_readdir++ >= GLOB_LIMIT_READDIR) {
741
		    limitp->glim_readdir++ >= COMPAT_GLOB_LIMIT_READDIR) {
742
			errno = 0;
742
			errno = 0;
743
			*pathend++ = SEP;
743
			*pathend++ = SEP;
744
			*pathend = EOS;
744
			*pathend = EOS;
745
			err = GLOB_NOSPACE;
745
			err = COMPAT_GLOB_NOSPACE;
746
			break;
746
			break;
747
		}
747
		}
748
748
Lines 759-765 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
759
			break;
759
			break;
760
		}
760
		}
761
761
762
		if (!match(pathend, pattern, restpattern, GLOB_LIMIT_RECUR)) {
762
		if (!match(pathend, pattern, restpattern, COMPAT_GLOB_LIMIT_RECUR)) {
763
			*pathend = EOS;
763
			*pathend = EOS;
764
			continue;
764
			continue;
765
		}
765
		}
Lines 769-775 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
769
			break;
769
			break;
770
	}
770
	}
771
771
772
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
772
	if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC)
773
		(*pglob->gl_closedir)(dirp);
773
		(*pglob->gl_closedir)(dirp);
774
	else
774
	else
775
		closedir(dirp);
775
		closedir(dirp);
Lines 792-798 glob3(Char *pathbuf, Char *pathbuf_last, Char *pathend, Char *pathend_last, Link Here
792
 *	gl_pathv points to (gl_offs + gl_pathc + 1) items.
792
 *	gl_pathv points to (gl_offs + gl_pathc + 1) items.
793
 */
793
 */
794
static int
794
static int
795
globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp,
795
globextend(const Char *path, compat_glob_t *pglob, struct glob_lim *limitp,
796
    struct stat *sb)
796
    struct stat *sb)
797
{
797
{
798
	char **pathv;
798
	char **pathv;
Lines 812-818 globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, Link Here
812
		for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) {
812
		for (i = pglob->gl_offs; i < (ssize_t)(newn - 2); i++) {
813
			if (pglob->gl_pathv && pglob->gl_pathv[i])
813
			if (pglob->gl_pathv && pglob->gl_pathv[i])
814
				free(pglob->gl_pathv[i]);
814
				free(pglob->gl_pathv[i]);
815
			if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0 &&
815
			if ((pglob->gl_flags & COMPAT_GLOB_KEEPSTAT) != 0 &&
816
			    pglob->gl_pathv && pglob->gl_pathv[i])
816
			    pglob->gl_pathv && pglob->gl_pathv[i])
817
				free(pglob->gl_statv[i]);
817
				free(pglob->gl_statv[i]);
818
		}
818
		}
Lines 824-830 globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, Link Here
824
			free(pglob->gl_statv);
824
			free(pglob->gl_statv);
825
			pglob->gl_statv = NULL;
825
			pglob->gl_statv = NULL;
826
		}
826
		}
827
		return(GLOB_NOSPACE);
827
		return(COMPAT_GLOB_NOSPACE);
828
	}
828
	}
829
829
830
	pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv));
830
	pathv = realloc(pglob->gl_pathv, newn * sizeof(*pathv));
Lines 838-844 globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, Link Here
838
	}
838
	}
839
	pglob->gl_pathv = pathv;
839
	pglob->gl_pathv = pathv;
840
840
841
	if ((pglob->gl_flags & GLOB_KEEPSTAT) != 0) {
841
	if ((pglob->gl_flags & COMPAT_GLOB_KEEPSTAT) != 0) {
842
		statv = realloc(pglob->gl_statv, newn * sizeof(*statv));
842
		statv = realloc(pglob->gl_statv, newn * sizeof(*statv));
843
		if (statv == NULL)
843
		if (statv == NULL)
844
			goto nospace;
844
			goto nospace;
Lines 853-862 globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, Link Here
853
			statv[pglob->gl_offs + pglob->gl_pathc] = NULL;
853
			statv[pglob->gl_offs + pglob->gl_pathc] = NULL;
854
		else {
854
		else {
855
			limitp->glim_malloc += sizeof(**statv);
855
			limitp->glim_malloc += sizeof(**statv);
856
			if ((pglob->gl_flags & GLOB_LIMIT) &&
856
			if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) &&
857
			    limitp->glim_malloc >= GLOB_LIMIT_MALLOC) {
857
			    limitp->glim_malloc >= COMPAT_GLOB_LIMIT_MALLOC) {
858
				errno = 0;
858
				errno = 0;
859
				return(GLOB_NOSPACE);
859
				return(COMPAT_GLOB_NOSPACE);
860
			}
860
			}
861
			if ((statv[pglob->gl_offs + pglob->gl_pathc] =
861
			if ((statv[pglob->gl_offs + pglob->gl_pathc] =
862
			    malloc(sizeof(**statv))) == NULL)
862
			    malloc(sizeof(**statv))) == NULL)
Lines 874-893 globextend(const Char *path, glob_t *pglob, struct glob_lim *limitp, Link Here
874
	if ((copy = malloc(len)) != NULL) {
874
	if ((copy = malloc(len)) != NULL) {
875
		if (g_Ctoc(path, copy, len)) {
875
		if (g_Ctoc(path, copy, len)) {
876
			free(copy);
876
			free(copy);
877
			return(GLOB_NOSPACE);
877
			return(COMPAT_GLOB_NOSPACE);
878
		}
878
		}
879
		pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
879
		pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
880
	}
880
	}
881
	pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
881
	pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
882
882
883
	if ((pglob->gl_flags & GLOB_LIMIT) &&
883
	if ((pglob->gl_flags & COMPAT_GLOB_LIMIT) &&
884
	    (newn * sizeof(*pathv)) + limitp->glim_malloc >
884
	    (newn * sizeof(*pathv)) + limitp->glim_malloc >
885
	    GLOB_LIMIT_MALLOC) {
885
	    COMPAT_GLOB_LIMIT_MALLOC) {
886
		errno = 0;
886
		errno = 0;
887
		return(GLOB_NOSPACE);
887
		return(COMPAT_GLOB_NOSPACE);
888
	}
888
	}
889
 copy_error:
889
 copy_error:
890
	return(copy == NULL ? GLOB_NOSPACE : 0);
890
	return(copy == NULL ? COMPAT_GLOB_NOSPACE : 0);
891
}
891
}
892
892
893
893
Lines 902-908 match(Char *name, Char *pat, Char *patend, int recur) Link Here
902
	Char c, k;
902
	Char c, k;
903
903
904
	if (recur-- == 0)
904
	if (recur-- == 0)
905
		return(GLOB_NOSPACE);
905
		return(COMPAT_GLOB_NOSPACE);
906
906
907
	while (pat < patend) {
907
	while (pat < patend) {
908
		c = *pat++;
908
		c = *pat++;
Lines 956-962 match(Char *name, Char *pat, Char *patend, int recur) Link Here
956
956
957
/* Free allocated data belonging to a glob_t structure. */
957
/* Free allocated data belonging to a glob_t structure. */
958
void
958
void
959
globfree(glob_t *pglob)
959
compat_globfree(compat_glob_t *pglob)
960
{
960
{
961
	int i;
961
	int i;
962
	char **pp;
962
	char **pp;
Lines 980-986 globfree(glob_t *pglob) Link Here
980
}
980
}
981
981
982
static DIR *
982
static DIR *
983
g_opendir(Char *str, glob_t *pglob)
983
g_opendir(Char *str, compat_glob_t *pglob)
984
{
984
{
985
	char buf[MAXPATHLEN];
985
	char buf[MAXPATHLEN];
986
986
Lines 991-1022 g_opendir(Char *str, glob_t *pglob) Link Here
991
			return(NULL);
991
			return(NULL);
992
	}
992
	}
993
993
994
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
994
	if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC)
995
		return((*pglob->gl_opendir)(buf));
995
		return((*pglob->gl_opendir)(buf));
996
996
997
	return(opendir(buf));
997
	return(opendir(buf));
998
}
998
}
999
999
1000
static int
1000
static int
1001
g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
1001
g_lstat(Char *fn, struct stat *sb, compat_glob_t *pglob)
1002
{
1002
{
1003
	char buf[MAXPATHLEN];
1003
	char buf[MAXPATHLEN];
1004
1004
1005
	if (g_Ctoc(fn, buf, sizeof(buf)))
1005
	if (g_Ctoc(fn, buf, sizeof(buf)))
1006
		return(-1);
1006
		return(-1);
1007
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1007
	if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC)
1008
		return((*pglob->gl_lstat)(buf, sb));
1008
		return((*pglob->gl_lstat)(buf, sb));
1009
	return(lstat(buf, sb));
1009
	return(lstat(buf, sb));
1010
}
1010
}
1011
1011
1012
static int
1012
static int
1013
g_stat(Char *fn, struct stat *sb, glob_t *pglob)
1013
g_stat(Char *fn, struct stat *sb, compat_glob_t *pglob)
1014
{
1014
{
1015
	char buf[MAXPATHLEN];
1015
	char buf[MAXPATHLEN];
1016
1016
1017
	if (g_Ctoc(fn, buf, sizeof(buf)))
1017
	if (g_Ctoc(fn, buf, sizeof(buf)))
1018
		return(-1);
1018
		return(-1);
1019
	if (pglob->gl_flags & GLOB_ALTDIRFUNC)
1019
	if (pglob->gl_flags & COMPAT_GLOB_ALTDIRFUNC)
1020
		return((*pglob->gl_stat)(buf, sb));
1020
		return((*pglob->gl_stat)(buf, sb));
1021
	return(stat(buf, sb));
1021
	return(stat(buf, sb));
1022
}
1022
}
(-)a/openbsd-compat/glob.h (-26 / +26 lines)
Lines 42-49 Link Here
42
    !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \
42
    !defined(HAVE_DECL_GLOB_NOMATCH) || HAVE_DECL_GLOB_NOMATCH == 0 || \
43
    defined(BROKEN_GLOB)
43
    defined(BROKEN_GLOB)
44
44
45
#ifndef _GLOB_H_
45
#ifndef _COMPAT_GLOB_H_
46
#define	_GLOB_H_
46
#define	_COMPAT_GLOB_H_
47
47
48
#include <sys/stat.h>
48
#include <sys/stat.h>
49
49
Lines 68-102 typedef struct { Link Here
68
	void *(*gl_opendir)(const char *);
68
	void *(*gl_opendir)(const char *);
69
	int (*gl_lstat)(const char *, struct stat *);
69
	int (*gl_lstat)(const char *, struct stat *);
70
	int (*gl_stat)(const char *, struct stat *);
70
	int (*gl_stat)(const char *, struct stat *);
71
} glob_t;
71
} compat_glob_t;
72
72
73
#define	GLOB_APPEND	0x0001	/* Append to output from previous call. */
73
#define	COMPAT_GLOB_APPEND	0x0001	/* Append to output from previous call. */
74
#define	GLOB_DOOFFS	0x0002	/* Use gl_offs. */
74
#define	COMPAT_GLOB_DOOFFS	0x0002	/* Use gl_offs. */
75
#define	GLOB_ERR	0x0004	/* Return on error. */
75
#define	COMPAT_GLOB_ERR	0x0004	/* Return on error. */
76
#define	GLOB_MARK	0x0008	/* Append / to matching directories. */
76
#define	COMPAT_GLOB_MARK	0x0008	/* Append / to matching directories. */
77
#define	GLOB_NOCHECK	0x0010	/* Return pattern itself if nothing matches. */
77
#define	COMPAT_GLOB_NOCHECK	0x0010	/* Return pattern itself if nothing matches. */
78
#define	GLOB_NOSORT	0x0020	/* Don't sort. */
78
#define	COMPAT_GLOB_NOSORT	0x0020	/* Don't sort. */
79
#define	GLOB_NOESCAPE	0x1000	/* Disable backslash escaping. */
79
#define	COMPAT_GLOB_NOESCAPE	0x1000	/* Disable backslash escaping. */
80
80
81
#define	GLOB_NOSPACE	(-1)	/* Malloc call failed. */
81
#define	COMPAT_GLOB_NOSPACE	(-1)	/* Malloc call failed. */
82
#define	GLOB_ABORTED	(-2)	/* Unignored error. */
82
#define	COMPAT_GLOB_ABORTED	(-2)	/* Unignored error. */
83
#define	GLOB_NOMATCH	(-3)	/* No match and GLOB_NOCHECK not set. */
83
#define	COMPAT_GLOB_NOMATCH	(-3)	/* No match and GLOB_NOCHECK not set. */
84
#define	GLOB_NOSYS	(-4)	/* Function not supported. */
84
#define	COMPAT_GLOB_NOSYS	(-4)	/* Function not supported. */
85
85
86
#define	GLOB_ALTDIRFUNC	0x0040	/* Use alternately specified directory funcs. */
86
#define	COMPAT_GLOB_ALTDIRFUNC	0x0040	/* Use alternately specified directory funcs. */
87
#define	GLOB_BRACE	0x0080	/* Expand braces ala csh. */
87
#define	COMPAT_GLOB_BRACE	0x0080	/* Expand braces ala csh. */
88
#define	GLOB_MAGCHAR	0x0100	/* Pattern had globbing characters. */
88
#define	COMPAT_GLOB_MAGCHAR	0x0100	/* Pattern had globbing characters. */
89
#define	GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
89
#define	COMPAT_GLOB_NOMAGIC	0x0200	/* GLOB_NOCHECK without magic chars (csh). */
90
#define	GLOB_QUOTE	0x0400	/* Quote special chars with \. */
90
#define	COMPAT_GLOB_QUOTE	0x0400	/* Quote special chars with \. */
91
#define	GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
91
#define	COMPAT_GLOB_TILDE	0x0800	/* Expand tilde names from the passwd file. */
92
#define GLOB_LIMIT	0x2000	/* Limit pattern match output to ARG_MAX */
92
#define COMPAT_GLOB_LIMIT	0x2000	/* Limit pattern match output to ARG_MAX */
93
#define	GLOB_KEEPSTAT	0x4000	/* Retain stat data for paths in gl_statv. */
93
#define	COMPAT_GLOB_KEEPSTAT	0x4000	/* Retain stat data for paths in gl_statv. */
94
#define GLOB_ABEND	GLOB_ABORTED /* backward compatibility */
94
#define COMPAT_GLOB_ABEND	COMPAT_GLOB_ABORTED /* backward compatibility */
95
95
96
int	glob(const char *, int, int (*)(const char *, int), glob_t *);
96
int	compat_glob(const char *, int, int (*)(const char *, int), compat_glob_t *);
97
void	globfree(glob_t *);
97
void	compat_globfree(compat_glob_t *);
98
98
99
#endif /* !_GLOB_H_ */
99
#endif /* !_COMPAT_GLOB_H_ */
100
100
101
#endif /* !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC)  ||
101
#endif /* !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC)  ||
102
	  !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOH_HAS_GL_STATV) */
102
	  !defined(GLOB_HAS_GL_MATCHC) || !defined(GLOH_HAS_GL_STATV) */
(-)a/sftp-glob.c (-3 / +3 lines)
Lines 33-39 Link Here
33
#include "sftp-client.h"
33
#include "sftp-client.h"
34
34
35
int remote_glob(struct sftp_conn *, const char *, int,
35
int remote_glob(struct sftp_conn *, const char *, int,
36
    int (*)(const char *, int), glob_t *);
36
    int (*)(const char *, int), compat_glob_t *);
37
37
38
struct SFTP_OPENDIR {
38
struct SFTP_OPENDIR {
39
	SFTP_DIRENT **dir;
39
	SFTP_DIRENT **dir;
Lines 135-141 fudge_stat(const char *path, struct stat *st) Link Here
135
135
136
int
136
int
137
remote_glob(struct sftp_conn *conn, const char *pattern, int flags,
137
remote_glob(struct sftp_conn *conn, const char *pattern, int flags,
138
    int (*errfunc)(const char *, int), glob_t *pglob)
138
    int (*errfunc)(const char *, int), compat_glob_t *pglob)
139
{
139
{
140
	pglob->gl_opendir = fudge_opendir;
140
	pglob->gl_opendir = fudge_opendir;
141
	pglob->gl_readdir = (struct dirent *(*)(void *))fudge_readdir;
141
	pglob->gl_readdir = (struct dirent *(*)(void *))fudge_readdir;
Lines 146-150 remote_glob(struct sftp_conn *conn, const char *pattern, int flags, Link Here
146
	memset(&cur, 0, sizeof(cur));
146
	memset(&cur, 0, sizeof(cur));
147
	cur.conn = conn;
147
	cur.conn = conn;
148
148
149
	return(glob(pattern, flags | GLOB_ALTDIRFUNC, errfunc, pglob));
149
	return(compat_glob(pattern, flags | COMPAT_GLOB_ALTDIRFUNC, errfunc, pglob));
150
}
150
}
(-)a/sftp.c (-25 / +24 lines)
Lines 113-119 struct complete_ctx { Link Here
113
};
113
};
114
114
115
int remote_glob(struct sftp_conn *, const char *, int,
115
int remote_glob(struct sftp_conn *, const char *, int,
116
    int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */
116
    int (*)(const char *, int), compat_glob_t *); /* proto for sftp-glob.c */
117
117
118
extern char *__progname;
118
extern char *__progname;
119
119
Lines 590-596 process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, Link Here
590
{
590
{
591
	char *abs_src = NULL;
591
	char *abs_src = NULL;
592
	char *abs_dst = NULL;
592
	char *abs_dst = NULL;
593
	glob_t g;
593
	compat_glob_t g;
594
	char *filename, *tmp=NULL;
594
	char *filename, *tmp=NULL;
595
	int i, r, err = 0;
595
	int i, r, err = 0;
596
596
Lines 599-606 process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, Link Here
599
	memset(&g, 0, sizeof(g));
599
	memset(&g, 0, sizeof(g));
600
600
601
	debug3("Looking up %s", abs_src);
601
	debug3("Looking up %s", abs_src);
602
	if ((r = remote_glob(conn, abs_src, GLOB_MARK, NULL, &g)) != 0) {
602
	if ((r = remote_glob(conn, abs_src, COMPAT_GLOB_MARK, NULL, &g)) != 0) {
603
		if (r == GLOB_NOSPACE) {
603
		if (r == COMPAT_GLOB_NOSPACE) {
604
			error("Too many matches for \"%s\".", abs_src);
604
			error("Too many matches for \"%s\".", abs_src);
605
		} else {
605
		} else {
606
			error("File \"%s\" not found.", abs_src);
606
			error("File \"%s\" not found.", abs_src);
Lines 664-670 process_get(struct sftp_conn *conn, char *src, char *dst, char *pwd, Link Here
664
664
665
out:
665
out:
666
	free(abs_src);
666
	free(abs_src);
667
	globfree(&g);
667
	compat_globfree(&g);
668
	return(err);
668
	return(err);
669
}
669
}
670
670
Lines 675-681 process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, Link Here
675
	char *tmp_dst = NULL;
675
	char *tmp_dst = NULL;
676
	char *abs_dst = NULL;
676
	char *abs_dst = NULL;
677
	char *tmp = NULL, *filename = NULL;
677
	char *tmp = NULL, *filename = NULL;
678
	glob_t g;
678
	compat_glob_t g;
679
	int err = 0;
679
	int err = 0;
680
	int i, dst_is_dir = 1;
680
	int i, dst_is_dir = 1;
681
	struct stat sb;
681
	struct stat sb;
Lines 687-693 process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, Link Here
687
687
688
	memset(&g, 0, sizeof(g));
688
	memset(&g, 0, sizeof(g));
689
	debug3("Looking up %s", src);
689
	debug3("Looking up %s", src);
690
	if (glob(src, GLOB_NOCHECK | GLOB_MARK, NULL, &g)) {
690
	if (compat_glob(src, GLOB_NOCHECK | GLOB_MARK, NULL, &g)) {
691
		error("File \"%s\" not found.", src);
691
		error("File \"%s\" not found.", src);
692
		err = -1;
692
		err = -1;
693
		goto out;
693
		goto out;
Lines 755-761 process_put(struct sftp_conn *conn, char *src, char *dst, char *pwd, Link Here
755
out:
755
out:
756
	free(abs_dst);
756
	free(abs_dst);
757
	free(tmp_dst);
757
	free(tmp_dst);
758
	globfree(&g);
758
	compat_globfree(&g);
759
	return(err);
759
	return(err);
760
}
760
}
761
761
Lines 868-887 do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, Link Here
868
    int lflag)
868
    int lflag)
869
{
869
{
870
	char *fname, *lname;
870
	char *fname, *lname;
871
	glob_t g;
871
	compat_glob_t g;
872
	int err, r;
872
	int err, r;
873
	struct winsize ws;
873
	struct winsize ws;
874
	u_int i, c = 1, colspace = 0, columns = 1, m = 0, width = 80;
874
	u_int i, c = 1, colspace = 0, columns = 1, m = 0, width = 80;
875
875
876
	memset(&g, 0, sizeof(g));
876
	memset(&g, 0, sizeof(g));
877
877
878
	if ((r = remote_glob(conn, path,
878
	if ((r = remote_glob(conn, path,COMPAT_GLOB_MARK|COMPAT_GLOB_NOCHECK|
879
	    GLOB_MARK|GLOB_NOCHECK|GLOB_BRACE|GLOB_KEEPSTAT|GLOB_NOSORT,
879
	    COMPAT_GLOB_BRACE|COMPAT_GLOB_KEEPSTAT|COMPAT_GLOB_NOSORT,
880
	    NULL, &g)) != 0 ||
880
	    NULL, &g)) != 0 ||
881
	    (g.gl_pathc && !g.gl_matchc)) {
881
	    (g.gl_pathc && !g.gl_matchc)) {
882
		if (g.gl_pathc)
882
		if (g.gl_pathc)
883
			globfree(&g);
883
			compat_globfree(&g);
884
		if (r == GLOB_NOSPACE) {
884
		if (r == COMPAT_GLOB_NOSPACE) {
885
			error("Can't ls: Too many matches for \"%s\"", path);
885
			error("Can't ls: Too many matches for \"%s\"", path);
886
		} else {
886
		} else {
887
			error("Can't ls: \"%s\" not found", path);
887
			error("Can't ls: \"%s\" not found", path);
Lines 899-905 do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, Link Here
899
	if (g.gl_matchc == 1 && g.gl_statv[0] != NULL &&
899
	if (g.gl_matchc == 1 && g.gl_statv[0] != NULL &&
900
	    S_ISDIR(g.gl_statv[0]->st_mode)) {
900
	    S_ISDIR(g.gl_statv[0]->st_mode)) {
901
		err = do_ls_dir(conn, g.gl_pathv[0], strip_path, lflag);
901
		err = do_ls_dir(conn, g.gl_pathv[0], strip_path, lflag);
902
		globfree(&g);
902
		compat_globfree(&g);
903
		return err;
903
		return err;
904
	}
904
	}
905
905
Lines 943-949 do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, Link Here
943
943
944
 out:
944
 out:
945
	if (g.gl_pathc)
945
	if (g.gl_pathc)
946
		globfree(&g);
946
		compat_globfree(&g);
947
947
948
	return 0;
948
	return 0;
949
}
949
}
Lines 1405-1411 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1405
	Attrib a, *aa;
1405
	Attrib a, *aa;
1406
	char path_buf[PATH_MAX];
1406
	char path_buf[PATH_MAX];
1407
	int err = 0;
1407
	int err = 0;
1408
	glob_t g;
1408
	compat_glob_t g;
1409
1409
1410
	path1 = path2 = NULL;
1410
	path1 = path2 = NULL;
1411
	cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
1411
	cmdnum = parse_args(&cmd, &ignore_errors, &aflag, &fflag, &hflag,
Lines 1453-1459 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1453
		break;
1453
		break;
1454
	case I_RM:
1454
	case I_RM:
1455
		path1 = make_absolute(path1, *pwd);
1455
		path1 = make_absolute(path1, *pwd);
1456
		remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
1456
		remote_glob(conn, path1, COMPAT_GLOB_NOCHECK, NULL, &g);
1457
		for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1457
		for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1458
			if (!quiet)
1458
			if (!quiet)
1459
				printf("Removing %s\n", g.gl_pathv[i]);
1459
				printf("Removing %s\n", g.gl_pathv[i]);
Lines 1553-1559 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1553
		attrib_clear(&a);
1553
		attrib_clear(&a);
1554
		a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;
1554
		a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;
1555
		a.perm = n_arg;
1555
		a.perm = n_arg;
1556
		remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
1556
		remote_glob(conn, path1, COMPAT_GLOB_NOCHECK, NULL, &g);
1557
		for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1557
		for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1558
			if (!quiet)
1558
			if (!quiet)
1559
				printf("Changing mode on %s\n", g.gl_pathv[i]);
1559
				printf("Changing mode on %s\n", g.gl_pathv[i]);
Lines 1565-1571 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1565
	case I_CHOWN:
1565
	case I_CHOWN:
1566
	case I_CHGRP:
1566
	case I_CHGRP:
1567
		path1 = make_absolute(path1, *pwd);
1567
		path1 = make_absolute(path1, *pwd);
1568
		remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
1568
		remote_glob(conn, path1, COMPAT_GLOB_NOCHECK, NULL, &g);
1569
		for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1569
		for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
1570
			if (!(aa = do_stat(conn, g.gl_pathv[i], 0))) {
1570
			if (!(aa = do_stat(conn, g.gl_pathv[i], 0))) {
1571
				if (err_abort) {
1571
				if (err_abort) {
Lines 1632-1638 parse_dispatch_command(struct sftp_conn *conn, const char *cmd, char **pwd, Link Here
1632
	}
1632
	}
1633
1633
1634
	if (g.gl_pathc)
1634
	if (g.gl_pathc)
1635
		globfree(&g);
1635
		compat_globfree(&g);
1636
	free(path1);
1636
	free(path1);
1637
	free(path2);
1637
	free(path2);
1638
1638
Lines 1820-1826 static int Link Here
1820
complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1820
complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path,
1821
    char *file, int remote, int lastarg, char quote, int terminated)
1821
    char *file, int remote, int lastarg, char quote, int terminated)
1822
{
1822
{
1823
	glob_t g;
1823
	compat_glob_t g;
1824
	char *tmp, *tmp2, ins[8];
1824
	char *tmp, *tmp2, ins[8];
1825
	u_int i, hadglob, pwdlen, len, tmplen, filelen, cesc, isesc, isabs;
1825
	u_int i, hadglob, pwdlen, len, tmplen, filelen, cesc, isesc, isabs;
1826
	int clen;
1826
	int clen;
Lines 1838-1846 complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, Link Here
1838
	memset(&g, 0, sizeof(g));
1838
	memset(&g, 0, sizeof(g));
1839
	if (remote != LOCAL) {
1839
	if (remote != LOCAL) {
1840
		tmp = make_absolute(tmp, remote_path);
1840
		tmp = make_absolute(tmp, remote_path);
1841
		remote_glob(conn, tmp, GLOB_DOOFFS|GLOB_MARK, NULL, &g);
1841
		remote_glob(conn, tmp, COMPAT_GLOB_DOOFFS|COMPAT_GLOB_MARK, NULL, &g);
1842
	} else
1842
	} else
1843
		glob(tmp, GLOB_DOOFFS|GLOB_MARK, NULL, &g);
1843
		compat_glob(tmp, COMPAT_GLOB_DOOFFS|COMPAT_GLOB_MARK, NULL, &g);
1844
1844
1845
	/* Determine length of pwd so we can trim completion display */
1845
	/* Determine length of pwd so we can trim completion display */
1846
	for (hadglob = tmplen = pwdlen = 0; tmp[tmplen] != 0; tmplen++) {
1846
	for (hadglob = tmplen = pwdlen = 0; tmp[tmplen] != 0; tmplen++) {
Lines 1938-1944 complete_match(EditLine *el, struct sftp_conn *conn, char *remote_path, Link Here
1938
	free(tmp);
1938
	free(tmp);
1939
1939
1940
 out:
1940
 out:
1941
	globfree(&g);
1941
	compat_globfree(&g);
1942
	return g.gl_matchc;
1942
	return g.gl_matchc;
1943
}
1943
}
1944
1944
1945
- 

Return to bug 2463