s3-vfs: Don't leak file descriptor on error.
[metze/samba/wip.git] / source3 / modules / vfs_crossrename.c
index ffb807da487217d108225d5b05c8ae070be8215b..9bb42b9958ee9c793f342736dbbd97b378aa1a30 100644 (file)
 #include "smbd/smbd.h"
 #include "system/filesys.h"
 #include "transfer_file.h"
-
+#include "smbprofile.h"
 
 #define MODULE "crossrename"
-static SMB_OFF_T module_sizelimit;
+static off_t module_sizelimit;
 
 static int crossrename_connect(
                 struct vfs_handle_struct *  handle,
@@ -35,7 +35,7 @@ static int crossrename_connect(
                return ret;
        }
 
-       module_sizelimit = (SMB_OFF_T) lp_parm_int(SNUM(handle->conn),
+       module_sizelimit = (off_t) lp_parm_int(SNUM(handle->conn),
                                        MODULE, "sizelimit", 20);
        /* convert from MiB to byte: */
        module_sizelimit *= 1048576;
@@ -70,16 +70,18 @@ static int copy_reg(const char *source, const char *dest)
                return -1;
        }
 
-       if((ifd = sys_open (source, O_RDONLY, 0)) < 0)
+       if((ifd = open (source, O_RDONLY, 0)) < 0)
                return -1;
 
-       if (unlink (dest) && errno != ENOENT)
+       if (unlink (dest) && errno != ENOENT) {
+               close(ifd);
                return -1;
+       }
 
 #ifdef O_NOFOLLOW
-       if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )
+       if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )
 #else
-       if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )
+       if((ofd = open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )
 #endif
                goto err;
 
@@ -191,7 +193,7 @@ static int crossrename_rename(vfs_handle_struct *handle,
 
 static struct vfs_fn_pointers vfs_crossrename_fns = {
        .connect_fn = crossrename_connect,
-       .rename = crossrename_rename
+       .rename_fn = crossrename_rename
 };
 
 NTSTATUS vfs_crossrename_init(void);