]> andersk Git - openssh.git/blobdiff - sftp-glob.c
[configure.ac] Make sure -lcrypto is before -lsocket for sco3. ok mouring@
[openssh.git] / sftp-glob.c
index 18b44f82e56bb56c00c2691dae35580739e68376..f099227f98e24932e688ba18c4bed499a8094ecf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001 Damien Miller.  All rights reserved.
+ * Copyright (c) 2001,2002 Damien Miller.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sftp-glob.c,v 1.6 2001/06/23 15:12:20 itojun Exp $");
+RCSID("$OpenBSD: sftp-glob.c,v 1.13 2002/09/11 22:41:50 djm 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"
@@ -45,23 +41,24 @@ struct SFTP_OPENDIR {
 };
 
 static struct {
-       int fd_in;
-       int fd_out;
+       struct sftp_conn *conn;
 } cur;
 
 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))
+
+       if (do_readdir(cur.conn, (char *)path, &r->dir)) {
+               xfree(r);
                return(NULL);
+       }
 
        r->offset = 0;
 
-       return((void*)r);
+       return((void *)r);
 }
 
 static struct dirent *
@@ -73,7 +70,7 @@ fudge_readdir(struct SFTP_OPENDIR *od)
 #ifdef __GNU_LIBRARY__
        static int inum = 1;
 #endif /* __GNU_LIBRARY__ */
-       
+
        if (od->dir[od->offset] == NULL)
                return(NULL);
 
@@ -92,7 +89,7 @@ fudge_readdir(struct SFTP_OPENDIR *od)
 #ifdef __GNU_LIBRARY__
        /*
         * Idiot glibc uses extensions to struct dirent for readdir with
-        * ALTDIRFUNCs. Not that this is documented anywhere but the 
+        * ALTDIRFUNCs. Not that this is documented anywhere but the
         * source... Fake an inode number to appease it.
         */
        ret->d_ino = inum++;
@@ -110,35 +107,16 @@ fudge_closedir(struct SFTP_OPENDIR *od)
        xfree(od);
 }
 
-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) {
-               st->st_uid = a->uid;
-               st->st_gid = a->gid;
-       }
-       if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)
-               st->st_mode = a->perm;
-       if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
-               st->st_atime = a->atime;
-               st->st_mtime = a->mtime;
-       }
-}
-
 static int
 fudge_lstat(const char *path, struct stat *st)
 {
        Attrib *a;
-       
-       if (!(a = do_lstat(cur.fd_in, cur.fd_out, (char*)path, 0)))
+
+       if (!(a = do_lstat(cur.conn, (char *)path, 0)))
                return(-1);
-       
+
        attrib_to_stat(a, st);
-       
+
        return(0);
 }
 
@@ -146,29 +124,27 @@ static int
 fudge_stat(const char *path, struct stat *st)
 {
        Attrib *a;
-       
-       if (!(a = do_stat(cur.fd_in, cur.fd_out, (char*)path, 0)))
+
+       if (!(a = do_stat(cur.conn, (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,
+remote_glob(struct sftp_conn *conn, 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;
+       cur.conn = conn;
 
-       return(glob(pattern, flags | GLOB_ALTDIRFUNC, (void*)errfunc,
-           pglob));
+       return(glob(pattern, flags | GLOB_ALTDIRFUNC, errfunc, pglob));
 }
This page took 0.038194 seconds and 4 git commands to generate.