From b49a1f01b06724abb66e212f3aa641a1578d3534 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Sep 2001 14:27:43 +0000 Subject: fixed the error code handling in can_delete() by converting it to NTSTATUS. This gets the right error codes in SMBunlink (This used to be commit c82f7828c05c747a5782d10c68cc2df80d4071bd) --- source3/smbd/reply.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 8527ebbe34..e3c7c9b856 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -1661,23 +1661,26 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, /******************************************************************* check if a user is allowed to delete a file ********************************************************************/ -static BOOL can_delete(char *fname,connection_struct *conn, int dirtype) +static NTSTATUS can_delete(char *fname,connection_struct *conn, int dirtype) { - SMB_STRUCT_STAT sbuf; - int fmode; + SMB_STRUCT_STAT sbuf; + int fmode; - if (!CAN_WRITE(conn)) return(False); + if (!CAN_WRITE(conn)) return NT_STATUS_MEDIA_WRITE_PROTECTED; - if (conn->vfs_ops.lstat(conn,fname,&sbuf) != 0) return(False); - fmode = dos_mode(conn,fname,&sbuf); - if (fmode & aDIR) return(False); - if (!lp_delete_readonly(SNUM(conn))) { - if (fmode & aRONLY) return(False); - } - if ((fmode & ~dirtype) & (aHIDDEN | aSYSTEM)) - return(False); - if (!check_file_sharing(conn,fname,False)) return(False); - return(True); + if (conn->vfs_ops.lstat(conn,fname,&sbuf) != 0) return NT_STATUS_OBJECT_NAME_NOT_FOUND; + + fmode = dos_mode(conn,fname,&sbuf); + if (fmode & aDIR) return NT_STATUS_FILE_IS_A_DIRECTORY; + if (!lp_delete_readonly(SNUM(conn))) { + if (fmode & aRONLY) return NT_STATUS_CANNOT_DELETE; + } + if ((fmode & ~dirtype) & (aHIDDEN | aSYSTEM)) + return NT_STATUS_CANNOT_DELETE; + + if (!check_file_sharing(conn,fname,False)) return NT_STATUS_SHARING_VIOLATION; + + return NT_STATUS_OK; } /**************************************************************************** @@ -1729,9 +1732,9 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name) if (!has_wild) { pstrcat(directory,"/"); pstrcat(directory,mask); - if (!can_delete(directory,conn,dirtype)) { - return NT_STATUS_SHARING_VIOLATION; - } + error = can_delete(directory,conn,dirtype); + if (!NT_STATUS_IS_OK(error)) return error; + if (vfs_unlink(conn,directory) == 0) { count++; } @@ -1761,9 +1764,9 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name) if(!mask_match(fname, mask, case_sensitive)) continue; - error = NT_STATUS_ACCESS_DENIED; slprintf(fname,sizeof(fname)-1, "%s/%s",directory,dname); - if (!can_delete(fname,conn,dirtype)) continue; + error = can_delete(fname,conn,dirtype); + if (!NT_STATUS_IS_OK(error)) continue; if (vfs_unlink(conn,fname) == 0) count++; DEBUG(3,("unlink_internals: succesful unlink [%s]\n",fname)); } -- cgit