r20544: Change copy_file() to return NTSTATUS. This is in preparation of turning
authorVolker Lendecke <vlendec@samba.org>
Fri, 5 Jan 2007 13:13:15 +0000 (13:13 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:16:56 +0000 (12:16 -0500)
close_file() to NTSTATUS as well.

I'm not sure I got all the error codes right, but as I've never come across a
smb_copy() call in all my Samba work, I'm leaving it at that. If I'm
absolutely bored, I will write a thorough torture test.

As far as I can see, Samba4 even does not have a libcli implementation for
it...  :-)

Volker

source/printing/nt_printing.c
source/smbd/reply.c

index d1d7745d4443ab9454743a21a37e31fd65d6f05e..5fa5db54e4bf7b7d5f47a4f2559e6ab2f68eada3 100644 (file)
@@ -1746,7 +1746,6 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
        SMB_STRUCT_STAT st;
        int ver = 0;
        int i;
-       int err;
 
        memset(inbuf, '\0', sizeof(inbuf));
        memset(outbuf, '\0', sizeof(outbuf));
@@ -1826,8 +1825,8 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->driverpath);   
                if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
                        driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                       if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                       if ( !NT_STATUS_IS_OK(copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                new_name, old_name));
                                *perr = WERR_ACCESS_DENIED;
@@ -1842,8 +1841,8 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                        slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->datafile);     
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
                                driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                               if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                               if ( !NT_STATUS_IS_OK(copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = WERR_ACCESS_DENIED;
@@ -1860,8 +1859,8 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                        slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->configfile);   
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
                                driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                               if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                               if ( !NT_STATUS_IS_OK(copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = WERR_ACCESS_DENIED;
@@ -1879,8 +1878,8 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                        slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->helpfile);     
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
                                driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                               if ( !copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
-                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                               if ( !NT_STATUS_IS_OK(copy_file(new_name, old_name, conn, OPENX_FILE_EXISTS_TRUNCATE|
+                                               OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = WERR_ACCESS_DENIED;
@@ -1907,9 +1906,9 @@ WERROR move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract
                                slprintf(old_name, sizeof(old_name)-1, "%s/%s", new_dir, driver->dependentfiles[i]);    
                                if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
                                        driver_unix_convert(new_name, conn, NULL, &bad_path, &st);
-                                       if ( !copy_file(new_name, old_name, conn,
+                                       if ( !NT_STATUS_IS_OK(copy_file(new_name, old_name, conn,
                                                        OPENX_FILE_EXISTS_TRUNCATE|
-                                                       OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False, &err) ) {
+                                                       OPENX_FILE_CREATE_IF_NOT_EXIST, 0, False))) {
                                                DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                                new_name, old_name));
                                                *perr = WERR_ACCESS_DENIED;
index 3ebab1843463c68da0f9f438c8b6fd631498c4f6..b99cb5484079384c68da9df2499f7b0177b88e47 100644 (file)
@@ -4698,8 +4698,12 @@ int reply_mv(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
  Copy a file as part of a reply_copy.
 ******************************************************************/
 
-BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
-                     int count,BOOL target_is_directory, int *err_ret)
+/*
+ * TODO: check error codes on all callers
+ */
+
+NTSTATUS copy_file(char *src, char *dest1,connection_struct *conn, int ofun,
+                  int count, BOOL target_is_directory)
 {
        SMB_STRUCT_STAT src_sbuf, sbuf2;
        SMB_OFF_T ret=-1;
@@ -4708,9 +4712,8 @@ BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
        uint32 dosattrs;
        uint32 new_create_disposition;
        NTSTATUS status;
+       int close_err;
  
-       *err_ret = 0;
-
        pstrcpy(dest,dest1);
        if (target_is_directory) {
                char *p = strrchr_m(src,'/');
@@ -4724,7 +4727,7 @@ BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
        }
 
        if (!vfs_file_exist(conn,src,&src_sbuf)) {
-               return(False);
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
        if (!target_is_directory && count) {
@@ -4732,7 +4735,7 @@ BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
        } else {
                if (!map_open_params_to_ntcreate(dest1,0,ofun,
                                NULL, NULL, &new_create_disposition, NULL)) {
-                       return(False);
+                       return NT_STATUS_INVALID_PARAMETER;
                }
        }
 
@@ -4746,7 +4749,7 @@ BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
                        NULL, &fsp1);
 
        if (!NT_STATUS_IS_OK(status)) {
-               return(False);
+               return status;
        }
 
        dosattrs = dos_mode(conn, src, &src_sbuf);
@@ -4765,7 +4768,7 @@ BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
 
        if (!NT_STATUS_IS_OK(status)) {
                close_file(fsp1,ERROR_CLOSE);
-               return(False);
+               return status;
        }
 
        if ((ofun&3) == 1) {
@@ -4794,9 +4797,17 @@ BOOL copy_file(char *src,char *dest1,connection_struct *conn, int ofun,
         * Thus we don't look at the error return from the
         * close of fsp1.
         */
-       *err_ret = close_file(fsp2,NORMAL_CLOSE);
+       close_err = close_file(fsp2,NORMAL_CLOSE);
 
-       return(ret == (SMB_OFF_T)src_sbuf.st_size);
+       if (close_err != 0) {
+               return map_nt_error_from_unix(close_err);
+       }
+
+       if (ret != (SMB_OFF_T)src_sbuf.st_size) {
+               return NT_STATUS_DISK_FULL;
+       }
+
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
@@ -4903,13 +4914,14 @@ int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
        if (!has_wild) {
                pstrcat(directory,"/");
                pstrcat(directory,mask);
-               if (resolve_wildcards(directory,newname) &&
-                               copy_file(directory,newname,conn,ofun, count,target_is_directory,&err))
+               if (resolve_wildcards(directory,newname)
+                   && NT_STATUS_IS_OK(status = copy_file(
+                                              directory,newname,conn,ofun,
+                                              count,target_is_directory))) 
                        count++;
-               if(!count && err) {
-                       errno = err;
+               if(!count && !NT_STATUS_IS_OK(status)) {
                        END_PROFILE(SMBcopy);
-                       return(UNIXERROR(ERRHRD,ERRgeneral));
+                       return ERROR_NT(status);
                }
                if (!count) {
                        exists = vfs_file_exist(conn,directory,NULL);
@@ -4942,9 +4954,10 @@ int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
                                error = ERRnoaccess;
                                slprintf(fname,sizeof(fname)-1, "%s/%s",directory,dname);
                                pstrcpy(destname,newname);
-                               if (resolve_wildcards(fname,destname) && 
-                                               copy_file(fname,destname,conn,ofun,
-                                               count,target_is_directory,&err))
+                               if (resolve_wildcards(fname,destname)
+                                   && NT_STATUS_IS_OK(status = copy_file(
+                                                              fname,destname,conn,ofun,
+                                                              count,target_is_directory)))
                                        count++;
                                DEBUG(3,("reply_copy : doing copy on %s -> %s\n",fname,destname));
                        }