]> andersk Git - openssh.git/blobdiff - sftp-glob.c
- djm@cvs.openbsd.org 2002/02/12 12:44:46
[openssh.git] / sftp-glob.c
index aec6d27348d34d31690ef54c959c22a5fc7598c2..849ac65ed1c873c12e7bef042428055fefbcfd9f 100644 (file)
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sftp-glob.c,v 1.1 2001/03/13 22:42:54 djm Exp $");
+RCSID("$OpenBSD: sftp-glob.c,v 1.9 2001/12/19 07:18:56 deraadt Exp $");
 
-#include "ssh.h"
 #include "buffer.h"
 #include "bufaux.h"
-#include "getput.h"
 #include "xmalloc.h"
 #include "log.h"
-#include "atomicio.h"
-#include "pathnames.h"
 
 #include "sftp.h"
 #include "sftp-common.h"
@@ -49,12 +45,13 @@ static struct {
        int fd_out;
 } cur;
 
-void *fudge_opendir(const char *path)
+static void *
+fudge_opendir(const char *path)
 {
        struct SFTP_OPENDIR *r;
-       
+
        r = xmalloc(sizeof(*r));
-       
+
        if (do_readdir(cur.fd_in, cur.fd_out, (char*)path, &r->dir))
                return(NULL);
 
@@ -63,9 +60,12 @@ void *fudge_opendir(const char *path)
        return((void*)r);
 }
 
-struct dirent *fudge_readdir(struct SFTP_OPENDIR *od)
+static struct dirent *
+fudge_readdir(struct SFTP_OPENDIR *od)
 {
-       static struct dirent ret;
+       /* 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__ */
@@ -73,34 +73,44 @@ struct dirent *fudge_readdir(struct SFTP_OPENDIR *od)
        if (od->dir[od->offset] == NULL)
                return(NULL);
 
-       memset(&ret, 0, sizeof(ret));
-       strlcpy(ret.d_name, od->dir[od->offset++]->filename, 
-           sizeof(ret.d_name));
+       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++;
+       ret->d_ino = inum++;
        if (!inum)
                inum = 1;
 #endif /* __GNU_LIBRARY__ */
 
-       return(&ret);
+       return(ret);
 }
 
-void fudge_closedir(struct SFTP_OPENDIR *od)
+static void
+fudge_closedir(struct SFTP_OPENDIR *od)
 {
        free_sftp_dirents(od->dir);
-       free(od);
+       xfree(od);
 }
 
-void attrib_to_stat(Attrib *a, struct stat *st)
+static void
+attrib_to_stat(Attrib *a, struct stat *st)
 {
        memset(st, 0, sizeof(*st));
-       
+
        if (a->flags & SSH2_FILEXFER_ATTR_SIZE)
                st->st_size = a->size;
        if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
@@ -115,44 +125,46 @@ void attrib_to_stat(Attrib *a, struct stat *st)
        }
 }
 
-int fudge_lstat(const char *path, struct stat *st)
+static int
+fudge_lstat(const char *path, struct stat *st)
 {
        Attrib *a;
-       
-       if (!(a = do_lstat(cur.fd_in, cur.fd_out, (char*)path)))
+
+       if (!(a = do_lstat(cur.fd_in, cur.fd_out, (char*)path, 0)))
                return(-1);
-       
+
        attrib_to_stat(a, st);
-       
+
        return(0);
 }
 
-int fudge_stat(const char *path, struct stat *st)
+static int
+fudge_stat(const char *path, struct stat *st)
 {
        Attrib *a;
-       
-       if (!(a = do_stat(cur.fd_in, cur.fd_out, (char*)path)))
+
+       if (!(a = do_stat(cur.fd_in, cur.fd_out, (char*)path, 0)))
                return(-1);
-       
+
        attrib_to_stat(a, st);
-       
+
        return(0);
 }
 
 int
-remote_glob(int fd_in, int fd_out, const char *pattern, int flags, 
-    const int (*errfunc)(const char *, int), glob_t *pglob)
+remote_glob(int fd_in, int fd_out, const char *pattern, int flags,
+    int (*errfunc)(const char *, int), glob_t *pglob)
 {
-       pglob->gl_opendir = (void*)fudge_opendir;
-       pglob->gl_readdir = (void*)fudge_readdir;
-       pglob->gl_closedir = (void*)fudge_closedir;
+       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.fd_in = fd_in;
        cur.fd_out = fd_out;
 
-       return(glob(pattern, flags | GLOB_ALTDIRFUNC, (void*)errfunc, 
+       return(glob(pattern, flags | GLOB_ALTDIRFUNC, errfunc,
            pglob));
 }
This page took 0.080542 seconds and 4 git commands to generate.