#include "includes.h"
+extern struct current_user current_user;
extern userdom_struct current_user_info;
extern uint16 global_oplock_port;
extern uint16 global_smbpid;
strlower_m(s);
if (strstr(s,"pipe/")) {
DEBUG(3,("Rejecting named pipe open for %s\n",fname));
- unix_ERR_class = ERRSRV;
- unix_ERR_code = ERRaccess;
- unix_ERR_ntstatus = NT_STATUS_ACCESS_DENIED;
+ set_saved_error_triple(ERRSRV, ERRaccess, NT_STATUS_ACCESS_DENIED);
}
}
static BOOL open_file(files_struct *fsp,connection_struct *conn,
const char *fname,SMB_STRUCT_STAT *psbuf,int flags,mode_t mode, uint32 desired_access)
{
- extern struct current_user current_user;
int accmode = (flags & O_ACCMODE);
int local_flags = flags;
/* Don't create files with Microsoft wildcard characters. */
if ((local_flags & O_CREAT) && !VALID_STAT(*psbuf) && ms_has_wild(fname)) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRinvalidname;
- unix_ERR_ntstatus = NT_STATUS_OBJECT_NAME_INVALID;
+ set_saved_error_triple(ERRDOS, ERRinvalidname, NT_STATUS_OBJECT_NAME_INVALID);
return False;
}
fsp->dev = psbuf->st_dev;
fsp->vuid = current_user.vuid;
fsp->file_pid = global_smbpid;
- fsp->size = psbuf->st_size;
fsp->can_lock = True;
fsp->can_read = ((flags & O_WRONLY)==0);
fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
fsp->is_directory = False;
fsp->is_stat = False;
fsp->directory_delete_on_close = False;
+ if (conn->aio_write_behind_list && is_in_path(fname, conn->aio_write_behind_list, conn->case_sensitive)) {
+ fsp->aio_write_behind = True;
+ }
+
string_set(&fsp->fsp_name,fname);
fsp->wcp = NULL; /* Write cache pointer. */
DEBUG(5,("check_share_mode: Failing open on file %s as delete on close flag is set.\n",
fname ));
/* Use errno to map to correct error. */
- unix_ERR_class = SMB_SUCCESS;
- unix_ERR_code = 0;
- unix_ERR_ntstatus = NT_STATUS_OK;
+ set_saved_error_triple(SMB_SUCCESS, 0, NT_STATUS_OK);
return False;
}
(!GET_ALLOW_SHARE_DELETE(share->share_mode) || !GET_ALLOW_SHARE_DELETE(share_mode))) {
DEBUG(5,("check_share_mode: Failing open on file %s as delete access requests conflict.\n",
fname ));
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
-
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return False;
}
if ((desired_access & DELETE_ACCESS) && !GET_ALLOW_SHARE_DELETE(share->share_mode)) {
DEBUG(5,("check_share_mode: Failing open on file %s as delete access requested and allow share delete not set.\n",
fname ));
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
-
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return False;
}
if ((share->desired_access & DELETE_ACCESS) && !GET_ALLOW_SHARE_DELETE(share_mode)) {
DEBUG(5,("check_share_mode: Failing open on file %s as delete access granted and allow share delete not requested.\n",
fname ));
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return False;
}
#if 0
/* Bluarc test may need this ... needs further investigation. */
if (deny_mode == DENY_ALL || old_deny_mode == DENY_ALL) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return False;
}
#endif
deny_mode,old_deny_mode,old_open_mode,
(int)share->pid,fname, fcbopen, *flags, access_allowed));
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
-
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return False;
}
DEBUG(0,("open_mode_check: FAILED when breaking oplock (%x) on file %s, \
dev = %x, inode = %.0f\n", old_shares[i].op_type, fname, (unsigned int)dev, (double)inode));
SAFE_FREE(old_shares);
- errno = EACCES;
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return -1;
}
if (del_share_entry(dev, inode, &broken_entry->entry, NULL) == -1) {
free_broken_entry_list(broken_entry_list);
errno = EACCES;
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return -1;
}
delete_defered_open_entry_record(conn, dib.dev, dib.inode);
unlock_share_entry(conn, dib.dev, dib.inode);
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return NULL;
}
/* Ensure we don't reprocess this message. */
return print_fsp_open(conn, fname);
}
- fsp = file_new(conn);
- if(!fsp)
- return NULL;
-
DEBUG(10,("open_file_shared: fname = %s, dos_attrs = %x, share_mode = %x, ofun = %x, mode = %o, oplock request = %d\n",
fname, new_dos_mode, share_mode, ofun, (int)mode, oplock_request ));
if (!check_name(fname,conn)) {
- file_free(fsp);
return NULL;
}
/* this is for OS/2 long file names - say we don't support them */
if (strstr(fname,".+,;=[].")) {
- unix_ERR_class = ERRDOS;
/* OS/2 Workplace shell fix may be main code stream in a later release. */
- unix_ERR_code = ERRcannotopen;
- unix_ERR_ntstatus = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ set_saved_error_triple(ERRDOS, ERRcannotopen, NT_STATUS_OBJECT_NAME_NOT_FOUND);
DEBUG(5,("open_file_shared: OS/2 long filenames are not supported.\n"));
- /* need to reset errno or DEVELOPER will cause us to coredump */
- errno = 0;
- file_free(fsp);
return NULL;
}
if ((GET_FILE_OPEN_DISPOSITION(ofun) == FILE_EXISTS_FAIL) && file_existed) {
DEBUG(5,("open_file_shared: create new requested for file %s and file already exists.\n",
fname ));
- file_free(fsp);
if (S_ISDIR(psbuf->st_mode)) {
errno = EISDIR;
} else {
DEBUG(5,("open_file_shared: attributes missmatch for file %s (%x %x) (0%o, 0%o)\n",
fname, existing_dos_mode, new_dos_mode,
(int)psbuf->st_mode, (int)mode ));
- file_free(fsp);
errno = EACCES;
return NULL;
}
append does not mean the same thing under dos and unix */
switch (GET_OPEN_MODE(share_mode)) {
+ case DOS_OPEN_EXEC:
+ case DOS_OPEN_RDONLY:
+ flags = O_RDONLY;
+ if (desired_access == 0)
+ desired_access = FILE_READ_DATA;
+ break;
case DOS_OPEN_WRONLY:
flags = O_WRONLY;
if (desired_access == 0)
desired_access = FILE_READ_DATA|FILE_WRITE_DATA;
break;
default:
- flags = O_RDONLY;
- if (desired_access == 0)
- desired_access = FILE_READ_DATA;
- break;
+ /* Force DOS error. */
+ set_saved_error_triple(ERRDOS, ERRinvalidparam, NT_STATUS_INVALID);
+ return NULL;
}
#if defined(O_SYNC)
if (!fcbopen) {
DEBUG(5,("open_file_shared: read/write access requested for file %s on read only %s\n",
fname, !CAN_WRITE(conn) ? "share" : "file" ));
- file_free(fsp);
errno = EACCES;
return NULL;
}
if (deny_mode > DENY_NONE && deny_mode!=DENY_FCB) {
DEBUG(2,("Invalid deny mode %d on file %s\n",deny_mode,fname));
- file_free(fsp);
errno = EINVAL;
return NULL;
}
}
}
+ fsp = file_new(conn);
+ if(!fsp)
+ return NULL;
+
if (file_existed) {
dev = psbuf->st_dev;
flags,(flags2&~(O_TRUNC|O_CREAT)),(int)mode,(int)fsp_open ));
if (!fsp_open && errno) {
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRnoaccess;
- unix_ERR_ntstatus = NT_STATUS_ACCESS_DENIED;
+ /* Default error. */
+ set_saved_error_triple(ERRDOS, ERRnoaccess, NT_STATUS_ACCESS_DENIED);
}
/*
* the braindead 1 second delay.
*/
- if (!internal_only_open && NT_STATUS_EQUAL(unix_ERR_ntstatus,NT_STATUS_SHARING_VIOLATION)) {
- /* The fsp->open_time here represents the current time of day. */
- defer_open_sharing_error(conn, &fsp->open_time, fname, dev, inode);
+ if (!internal_only_open) {
+ NTSTATUS status;
+ get_saved_error_triple(NULL, NULL, &status);
+ if (NT_STATUS_EQUAL(status,NT_STATUS_SHARING_VIOLATION)) {
+ /* The fsp->open_time here represents the current time of day. */
+ defer_open_sharing_error(conn, &fsp->open_time, fname, dev, inode);
+ }
}
unlock_share_entry(conn, dev, inode);
* We have detected a sharing violation here
* so return the correct error code
*/
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
}
file_free(fsp);
return NULL;
* the braindead 1 second delay.
*/
- if (!internal_only_open && NT_STATUS_EQUAL(unix_ERR_ntstatus,NT_STATUS_SHARING_VIOLATION)) {
+ NTSTATUS status;
+ get_saved_error_triple(NULL, NULL, &status);
+ if (NT_STATUS_EQUAL(status,NT_STATUS_SHARING_VIOLATION)) {
/* The fsp->open_time here represents the current time of day. */
defer_open_sharing_error(conn, &fsp->open_time, fname, dev, inode);
}
* We have detected a sharing violation here, so
* return the correct code.
*/
- unix_ERR_class = ERRDOS;
- unix_ERR_code = ERRbadshare;
- unix_ERR_ntstatus = NT_STATUS_SHARING_VIOLATION;
+ set_saved_error_triple(ERRDOS, ERRbadshare, NT_STATUS_SHARING_VIOLATION);
return NULL;
}
DEBUG(10,("open_file_shared : share_mode = %x\n", fsp->share_mode ));
if (Access) {
- (*Access) = open_mode;
+ (*Access) = (SET_DENY_MODE(deny_mode) | SET_OPEN_MODE(open_mode));
}
action = 0;
fd_close(conn,fsp);
file_free(fsp);
ntstatus_to_dos(result, &u_e_c, &u_e_code);
- unix_ERR_ntstatus = result;
- unix_ERR_class = u_e_c;
- unix_ERR_code = u_e_code;
+ set_saved_error_triple(u_e_c, u_e_code, result);
return NULL;
}
}
files_struct *open_directory(connection_struct *conn, const char *fname, SMB_STRUCT_STAT *psbuf,
uint32 desired_access, int share_mode, int smb_ofun, int *action)
{
- extern struct current_user current_user;
BOOL got_stat = False;
files_struct *fsp = file_new(conn);
BOOL delete_on_close = GET_DELETE_ON_CLOSE_FLAG(share_mode);
fname, strerror(errno) ));
file_free(fsp);
/* Ensure we return the correct NT status to the client. */
- unix_ERR_ntstatus = status;
+ set_saved_error_triple(0, 0, status);
return NULL;
}
fsp->mode = psbuf->st_mode;
fsp->inode = psbuf->st_ino;
fsp->dev = psbuf->st_dev;
- fsp->size = psbuf->st_size;
fsp->vuid = current_user.vuid;
fsp->file_pid = global_smbpid;
fsp->can_lock = True;
files_struct *open_file_stat(connection_struct *conn, char *fname, SMB_STRUCT_STAT *psbuf)
{
- extern struct current_user current_user;
files_struct *fsp = NULL;
if (!VALID_STAT(*psbuf))
fsp->mode = psbuf->st_mode;
fsp->inode = psbuf->st_ino;
fsp->dev = psbuf->st_dev;
- fsp->size = psbuf->st_size;
fsp->vuid = current_user.vuid;
fsp->file_pid = global_smbpid;
fsp->can_lock = False;