s3-auth: Split out get_user_sid_info3_and_extra() from create_local_nt_token_from_info3()
[amitay/samba.git] / source3 / modules / vfs_crossrename.c
index e1d0353d1e9aed9bec12a6703c930c67d8cb5717..c7534b43198e7dde563d9ebf2a6c9f6d0ff16a49 100644 (file)
  */
 
 #include "includes.h"
+#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,
@@ -34,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;
@@ -69,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;
 
@@ -103,9 +106,11 @@ static int copy_reg(const char *source, const char *dest)
         */
 
 #if defined(HAVE_FCHMOD)
-       if (fchmod (ofd, source_stats.st_ex_mode & 07777))
+       if ((fchmod (ofd, source_stats.st_ex_mode & 07777) == -1) &&
+                       (errno != EPERM))
 #else
-       if (chmod (dest, source_stats.st_ex_mode & 07777))
+       if ((chmod (dest, source_stats.st_ex_mode & 07777) == -1) &&
+                       (errno != EPERM))
 #endif
                goto err;
 
@@ -190,7 +195,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);