mirror of
git://anongit.mindrot.org/openssh.git
synced 2024-12-25 03:12:10 +00:00
a627d42e51
[xmalloc.h cipher.c sftp-glob.c ssh-keyscan.c ssh.c sftp-common.c ssh-ecdsa.c auth2-chall.c compat.c readconf.c kexgexs.c monitor.c gss-genr.c cipher-3des1.c kex.c monitor_wrap.c ssh-pkcs11-client.c auth-options.c rsa.c auth2-pubkey.c sftp.c hostfile.c auth2.c servconf.c auth.c authfile.c xmalloc.c uuencode.c sftp-client.c auth2-gss.c sftp-server.c bufaux.c mac.c session.c jpake.c kexgexc.c sshconnect.c auth-chall.c auth2-passwd.c sshconnect1.c buffer.c kexecdhs.c kexdhs.c ssh-rsa.c auth1.c ssh-pkcs11.c auth2-kbdint.c kexdhc.c sshd.c umac.c ssh-dss.c auth2-jpake.c bufbn.c clientloop.c monitor_mm.c scp.c roaming_client.c serverloop.c key.c auth-rsa.c ssh-pkcs11-helper.c ssh-keysign.c ssh-keygen.c match.c channels.c sshconnect2.c addrmatch.c mux.c canohost.c kexecdhc.c schnorr.c ssh-add.c misc.c auth2-hostbased.c ssh-agent.c bufec.c groupaccess.c dns.c packet.c readpass.c authfd.c moduli.c] bye, bye xfree(); ok markus@
150 lines
3.4 KiB
C
150 lines
3.4 KiB
C
/* $OpenBSD: sftp-glob.c,v 1.24 2013/05/17 00:13:14 djm Exp $ */
|
|
/*
|
|
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#include "includes.h"
|
|
|
|
#include <sys/types.h>
|
|
#ifdef HAVE_SYS_STAT_H
|
|
# include <sys/stat.h>
|
|
#endif
|
|
|
|
#include <dirent.h>
|
|
#include <string.h>
|
|
|
|
#include "xmalloc.h"
|
|
#include "sftp.h"
|
|
#include "buffer.h"
|
|
#include "sftp-common.h"
|
|
#include "sftp-client.h"
|
|
|
|
int remote_glob(struct sftp_conn *, const char *, int,
|
|
int (*)(const char *, int), glob_t *);
|
|
|
|
struct SFTP_OPENDIR {
|
|
SFTP_DIRENT **dir;
|
|
int offset;
|
|
};
|
|
|
|
static struct {
|
|
struct sftp_conn *conn;
|
|
} cur;
|
|
|
|
static void *
|
|
fudge_opendir(const char *path)
|
|
{
|
|
struct SFTP_OPENDIR *r;
|
|
|
|
r = xmalloc(sizeof(*r));
|
|
|
|
if (do_readdir(cur.conn, (char *)path, &r->dir)) {
|
|
free(r);
|
|
return(NULL);
|
|
}
|
|
|
|
r->offset = 0;
|
|
|
|
return((void *)r);
|
|
}
|
|
|
|
static struct dirent *
|
|
fudge_readdir(struct SFTP_OPENDIR *od)
|
|
{
|
|
/* Solaris needs sizeof(dirent) + path length (see below) */
|
|
static char buf[sizeof(struct dirent) + MAXPATHLEN];
|
|
struct dirent *ret = (struct dirent *)buf;
|
|
#ifdef __GNU_LIBRARY__
|
|
static int inum = 1;
|
|
#endif /* __GNU_LIBRARY__ */
|
|
|
|
if (od->dir[od->offset] == NULL)
|
|
return(NULL);
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
/*
|
|
* Solaris defines dirent->d_name as a one byte array and expects
|
|
* you to hack around it.
|
|
*/
|
|
#ifdef BROKEN_ONE_BYTE_DIRENT_D_NAME
|
|
strlcpy(ret->d_name, od->dir[od->offset++]->filename, MAXPATHLEN);
|
|
#else
|
|
strlcpy(ret->d_name, od->dir[od->offset++]->filename,
|
|
sizeof(ret->d_name));
|
|
#endif
|
|
#ifdef __GNU_LIBRARY__
|
|
/*
|
|
* Idiot glibc uses extensions to struct dirent for readdir with
|
|
* ALTDIRFUNCs. Not that this is documented anywhere but the
|
|
* source... Fake an inode number to appease it.
|
|
*/
|
|
ret->d_ino = inum++;
|
|
if (!inum)
|
|
inum = 1;
|
|
#endif /* __GNU_LIBRARY__ */
|
|
|
|
return(ret);
|
|
}
|
|
|
|
static void
|
|
fudge_closedir(struct SFTP_OPENDIR *od)
|
|
{
|
|
free_sftp_dirents(od->dir);
|
|
free(od);
|
|
}
|
|
|
|
static int
|
|
fudge_lstat(const char *path, struct stat *st)
|
|
{
|
|
Attrib *a;
|
|
|
|
if (!(a = do_lstat(cur.conn, (char *)path, 1)))
|
|
return(-1);
|
|
|
|
attrib_to_stat(a, st);
|
|
|
|
return(0);
|
|
}
|
|
|
|
static int
|
|
fudge_stat(const char *path, struct stat *st)
|
|
{
|
|
Attrib *a;
|
|
|
|
if (!(a = do_stat(cur.conn, (char *)path, 1)))
|
|
return(-1);
|
|
|
|
attrib_to_stat(a, st);
|
|
|
|
return(0);
|
|
}
|
|
|
|
int
|
|
remote_glob(struct sftp_conn *conn, const char *pattern, int flags,
|
|
int (*errfunc)(const char *, int), glob_t *pglob)
|
|
{
|
|
pglob->gl_opendir = fudge_opendir;
|
|
pglob->gl_readdir = (struct dirent *(*)(void *))fudge_readdir;
|
|
pglob->gl_closedir = (void (*)(void *))fudge_closedir;
|
|
pglob->gl_lstat = fudge_lstat;
|
|
pglob->gl_stat = fudge_stat;
|
|
|
|
memset(&cur, 0, sizeof(cur));
|
|
cur.conn = conn;
|
|
|
|
return(glob(pattern, flags | GLOB_ALTDIRFUNC, errfunc, pglob));
|
|
}
|