SMB transaction2 handling
Copyright (C) Jeremy Allison 1994-2003
Copyright (C) Stefan (metze) Metzmacher 2003
+ Copyright (C) Volker Lendecke 2005
+ Copyright (C) Steve French 2005
Extensively modified by Andrew Tridgell, 1995
extern int max_send;
extern enum protocol_types Protocol;
extern int smb_read_error;
-extern int global_oplock_break;
extern uint32 global_client_caps;
extern struct current_user current_user;
return False;
}
- if (fsp && fsp->fd != -1) {
- sizeret = SMB_VFS_FGETXATTR(fsp, fsp->fd, ea_name, val, attr_size);
+ if (fsp && fsp->fh->fd != -1) {
+ sizeret = SMB_VFS_FGETXATTR(fsp, fsp->fh->fd, ea_name, val, attr_size);
} else {
sizeret = SMB_VFS_GETXATTR(conn, fname, ea_name, val, attr_size);
}
return False;
}
- DEBUG(10,("get_ea_value: EA %s is of length %d: ", ea_name, sizeret));
+ DEBUG(10,("get_ea_value: EA %s is of length %u: ", ea_name, (unsigned int)sizeret));
dump_data(10, val, sizeret);
pea->flags = 0;
for (i = 0, ea_namelist = TALLOC(mem_ctx, ea_namelist_size); i < 6;
ea_namelist = TALLOC_REALLOC_ARRAY(mem_ctx, ea_namelist, char, ea_namelist_size), i++) {
- if (fsp && fsp->fd != -1) {
- sizeret = SMB_VFS_FLISTXATTR(fsp, fsp->fd, ea_namelist, ea_namelist_size);
+ if (fsp && fsp->fh->fd != -1) {
+ sizeret = SMB_VFS_FLISTXATTR(fsp, fsp->fh->fd, ea_namelist, ea_namelist_size);
} else {
sizeret = SMB_VFS_LISTXATTR(conn, fname, ea_namelist, ea_namelist_size);
}
if (sizeret == -1)
return NULL;
- DEBUG(10,("get_ea_list_from_file: ea_namelist size = %d\n", sizeret ));
+ DEBUG(10,("get_ea_list_from_file: ea_namelist size = %u\n", (unsigned int)sizeret ));
if (sizeret) {
for (p = ea_namelist; p - ea_namelist < sizeret; p += strlen(p) + 1) {
push_ascii_fstring(dos_ea_name, listp->ea.name);
*pea_total_len += 4 + strlen(dos_ea_name) + 1 + listp->ea.value.length;
DEBUG(10,("get_ea_list_from_file: total_len = %u, %s, val len = %u\n",
- *pea_total_len, dos_ea_name,
+ (unsigned int)*pea_total_len, dos_ea_name,
(unsigned int)listp->ea.value.length ));
}
DLIST_ADD_END(ea_list_head, listp, tmp);
}
}
- DEBUG(10,("get_ea_list_from_file: total_len = %u\n", *pea_total_len));
+ DEBUG(10,("get_ea_list_from_file: total_len = %u\n", (unsigned int)*pea_total_len));
return ea_list_head;
}
canonicalize_ea_name(conn, fsp, fname, unix_ea_name);
- DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name, ea_list->ea.value.length));
+ DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name, (unsigned int)ea_list->ea.value.length));
if (samba_private_attr_name(unix_ea_name)) {
DEBUG(10,("set_ea: ea name %s is a private Samba name.\n", unix_ea_name));
if (ea_list->ea.value.length == 0) {
/* Remove the attribute. */
- if (fsp && (fsp->fd != -1)) {
+ if (fsp && (fsp->fh->fd != -1)) {
DEBUG(10,("set_ea: deleting ea name %s on file %s by file descriptor.\n",
unix_ea_name, fsp->fsp_name));
- ret = SMB_VFS_FREMOVEXATTR(fsp, fsp->fd, unix_ea_name);
+ ret = SMB_VFS_FREMOVEXATTR(fsp, fsp->fh->fd, unix_ea_name);
} else {
DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
unix_ea_name, fname));
}
#endif
} else {
- if (fsp && (fsp->fd != -1)) {
+ if (fsp && (fsp->fh->fd != -1)) {
DEBUG(10,("set_ea: setting ea name %s on file %s by file descriptor.\n",
unix_ea_name, fsp->fsp_name));
- ret = SMB_VFS_FSETXATTR(fsp, fsp->fd, unix_ea_name,
+ ret = SMB_VFS_FSETXATTR(fsp, fsp->fh->fd, unix_ea_name,
ea_list->ea.value.data, ea_list->ea.value.length, 0);
} else {
DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
}
DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));
- dump_data(10, eal->ea.value.data, eal->ea.value.length);
+ dump_data(10, (const char *)eal->ea.value.data, eal->ea.value.length);
return eal;
}
/* If there genuinely are no parameters or data to send just send the empty packet */
if(params_to_send == 0 && data_to_send == 0) {
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("send_trans2_replies: send_smb failed.");
return 0;
params_to_send, data_to_send, paramsize, datasize));
/* Send the packet */
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("send_trans2_replies: send_smb failed.");
{
char *params = *pparams;
char *pdata = *ppdata;
- int16 open_mode;
- int16 open_attr;
+ int deny_mode;
+ int32 open_attr;
BOOL oplock_request;
#if 0
BOOL return_additional_info;
int16 open_sattr;
time_t open_time;
#endif
- int16 open_ofun;
+ int open_ofun;
int32 open_size;
char *pname;
pstring fname;
SMB_OFF_T size=0;
- int fmode=0,mtime=0,rmode;
+ int fattr=0,mtime=0;
SMB_INO_T inode = 0;
SMB_STRUCT_STAT sbuf;
int smb_action = 0;
struct ea_list *ea_list = NULL;
uint16 flags = 0;
NTSTATUS status;
+ uint32 access_mask;
+ uint32 share_mode;
+ uint32 create_disposition;
+ uint32 create_options = 0;
/*
* Ensure we have enough parameters to perform the operation.
}
flags = SVAL(params, 0);
- open_mode = SVAL(params, 2);
+ deny_mode = SVAL(params, 2);
open_attr = SVAL(params,6);
oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
if (oplock_request) {
open_size = IVAL(params,14);
pname = ¶ms[28];
- if (IS_IPC(conn))
+ if (IS_IPC(conn)) {
return(ERROR_DOS(ERRSRV,ERRaccess));
+ }
- srvstr_get_path(inbuf, fname, pname, sizeof(fname), -1, STR_TERMINATE, &status, False);
+ srvstr_get_path(inbuf, fname, pname, sizeof(fname), -1, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
- DEBUG(3,("call_trans2open %s mode=%d attr=%d ofun=%d size=%d\n",
- fname,open_mode, open_attr, open_ofun, open_size));
+ DEBUG(3,("call_trans2open %s deny_mode=0x%x attr=%d ofun=0x%x size=%d\n",
+ fname, (unsigned int)deny_mode, (unsigned int)open_attr,
+ (unsigned int)open_ofun, open_size));
/* XXXX we need to handle passed times, sattr and flags */
return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
}
- /* Strange open mode mapping. */
- if (open_ofun == 0) {
- if (GET_OPEN_MODE(open_mode) == DOS_OPEN_EXEC) {
- open_ofun = FILE_EXISTS_FAIL | FILE_CREATE_IF_NOT_EXIST;
- }
+ if (!map_open_params_to_ntcreate(fname, deny_mode, open_ofun,
+ &access_mask,
+ &share_mode,
+ &create_disposition,
+ &create_options)) {
+ return ERROR_DOS(ERRDOS, ERRbadaccess);
}
/* Any data in this call is an EA list. */
- if (total_data && !lp_ea_support(SNUM(conn))) {
+ if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
}
- if (total_data) {
+ if (total_data != 4) {
if (total_data < 10) {
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
talloc_destroy(ctx);
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
+ } else if (IVAL(pdata,0) != 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
- fsp = open_file_shared(conn,fname,&sbuf,open_mode,open_ofun,(uint32)open_attr,
- oplock_request, &rmode,&smb_action);
+ fsp = open_file_ntcreate(conn,fname,&sbuf,
+ access_mask,
+ share_mode,
+ create_disposition,
+ create_options,
+ open_attr,
+ oplock_request,
+ &smb_action);
if (!fsp) {
talloc_destroy(ctx);
}
size = get_file_size(sbuf);
- fmode = dos_mode(conn,fname,&sbuf);
+ fattr = dos_mode(conn,fname,&sbuf);
mtime = sbuf.st_mtime;
inode = sbuf.st_ino;
- if (fmode & aDIR) {
+ if (fattr & aDIR) {
talloc_destroy(ctx);
close_file(fsp,False);
return(ERROR_DOS(ERRDOS,ERRnoaccess));
*pparams = params;
SSVAL(params,0,fsp->fnum);
- SSVAL(params,2,fmode);
- put_dos_date2(params,4, mtime);
+ SSVAL(params,2,open_attr);
+ srv_put_dos_date2(params,4, mtime);
SIVAL(params,8, (uint32)size);
- SSVAL(params,12,rmode);
- SSVAL(params,16,0); /* Padding. */
+ SSVAL(params,12,deny_mode);
+ SSVAL(params,14,0); /* open_type - file or directory. */
+ SSVAL(params,16,0); /* open_state - only valid for IPC device. */
if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
smb_action |= EXTENDED_OPLOCK_GRANTED;
static BOOL get_lanman2_dir_entry(connection_struct *conn,
void *inbuf, void *outbuf,
- char *path_mask,int dirtype,int info_level,
+ char *path_mask,uint32 dirtype,int info_level,
int requires_resume_key,
BOOL dont_descend,char **ppdata,
char *base_data, int space_remaining,
char *p, *q, *pdata = *ppdata;
uint32 reskey=0;
long prev_dirpos=0;
- int mode=0;
+ uint32 mode=0;
SMB_OFF_T file_size = 0;
SMB_BIG_UINT allocation_size = 0;
uint32 len;
char *nameptr;
char *last_entry_ptr;
BOOL was_8_3;
- int nt_extmode; /* Used for NT connections instead of mode */
+ uint32 nt_extmode; /* Used for NT connections instead of mode */
BOOL needslash = ( conn->dirpath[strlen(conn->dirpath) -1] != '/');
BOOL check_mangled_names = lp_manglednames(SNUM(conn));
if(lp_host_msdfs() &&
lp_msdfs_root(SNUM(conn)) &&
- is_msdfs_link(conn, pathreal, NULL, NULL,
+ is_msdfs_link(NULL,conn, pathreal, NULL, NULL,
&sbuf)) {
DEBUG(5,("get_lanman2_dir_entry: Masquerading msdfs link %s as a directory\n", pathreal));
SIVAL(p,0,reskey);
p += 4;
}
- put_dos_date2(p,0,cdate);
- put_dos_date2(p,4,adate);
- put_dos_date2(p,8,mdate);
+ srv_put_dos_date2(p,0,cdate);
+ srv_put_dos_date2(p,4,adate);
+ srv_put_dos_date2(p,8,mdate);
SIVAL(p,12,(uint32)file_size);
SIVAL(p,16,(uint32)allocation_size);
SSVAL(p,20,mode);
SIVAL(p,0,reskey);
p += 4;
}
- put_dos_date2(p,0,cdate);
- put_dos_date2(p,4,adate);
- put_dos_date2(p,8,mdate);
+ srv_put_dos_date2(p,0,cdate);
+ srv_put_dos_date2(p,4,adate);
+ srv_put_dos_date2(p,8,mdate);
SIVAL(p,12,(uint32)file_size);
SIVAL(p,16,(uint32)allocation_size);
SSVAL(p,20,mode);
SIVAL(p,0,reskey);
p += 4;
}
- put_dos_date2(p,0,cdate);
- put_dos_date2(p,4,adate);
- put_dos_date2(p,8,mdate);
+ srv_put_dos_date2(p,0,cdate);
+ srv_put_dos_date2(p,4,adate);
+ srv_put_dos_date2(p,8,mdate);
SIVAL(p,12,(uint32)file_size);
SIVAL(p,16,(uint32)allocation_size);
SSVAL(p,20,mode);
p +=4;
}
SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
- SIVAL(p,0,sbuf.st_dev); p += 4;
- SIVAL(p,0,sbuf.st_ino); p += 4;
+ SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */
+ SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
SIVAL(q, 0, len);
p += len;
}
p += 26;
SSVAL(p,0,0); p += 2; /* Reserved ? */
- SIVAL(p,0,sbuf.st_dev); p += 4;
- SIVAL(p,0,sbuf.st_ino); p += 4;
+ SIVAL(p,0,sbuf.st_ino); p += 4; /* FileIndexLow */
+ SIVAL(p,0,sbuf.st_dev); p += 4; /* FileIndexHigh */
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
SIVAL(q,0,len);
p += len;
requested. */
char *params = *pparams;
char *pdata = *ppdata;
- int dirtype = SVAL(params,0);
+ uint32 dirtype = SVAL(params,0);
int maxentries = SVAL(params,2);
uint16 findfirst_flags = SVAL(params,4);
BOOL close_after_first = (findfirst_flags & FLAG_TRANS2_FIND_CLOSE);
BOOL out_of_space = False;
int space_remaining;
BOOL bad_path = False;
+ BOOL mask_contains_wcard = False;
SMB_STRUCT_STAT sbuf;
TALLOC_CTX *ea_ctx = NULL;
struct ea_list *ea_list = NULL;
*directory = *mask = 0;
- DEBUG(3,("call_trans2findfirst: dirtype = %d, maxentries = %d, close_after_first=%d, \
+ DEBUG(3,("call_trans2findfirst: dirtype = %x, maxentries = %d, close_after_first=%d, \
close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
- dirtype, maxentries, close_after_first, close_if_end, requires_resume_key,
+ (unsigned int)dirtype, maxentries, close_after_first, close_if_end, requires_resume_key,
info_level, max_data_bytes));
if (!maxentries) {
return(ERROR_DOS(ERRDOS,ERRunknownlevel));
}
- srvstr_get_path(inbuf, directory, params+12, sizeof(directory), -1, STR_TERMINATE, &ntstatus, True);
+ srvstr_get_path_wcard(inbuf, directory, params+12, sizeof(directory), -1, STR_TERMINATE, &ntstatus, &mask_contains_wcard);
if (!NT_STATUS_IS_OK(ntstatus)) {
return ERROR_NT(ntstatus);
}
p = strrchr_m(directory,'/');
if(p == NULL) {
/* Windows and OS/2 systems treat search on the root '\' as if it were '\*' */
- if((directory[0] == '.') && (directory[1] == '\0'))
+ if((directory[0] == '.') && (directory[1] == '\0')) {
pstrcpy(mask,"*");
- else
+ mask_contains_wcard = True;
+ } else {
pstrcpy(mask,directory);
+ }
pstrcpy(directory,"./");
} else {
pstrcpy(mask,p+1);
}
*pparams = params;
- dptr_num = dptr_create(conn,directory, False, True ,SVAL(inbuf,smb_pid));
- if (dptr_num < 0) {
- talloc_destroy(ea_ctx);
- return(UNIXERROR(ERRDOS,ERRbadfile));
- }
-
/* Save the wildcard match and attribs we are using on this directory -
needed as lanman2 assumes these are being saved between calls */
- if (!dptr_set_wcard_and_attributes(dptr_num, mask, dirtype)) {
- dptr_close(&dptr_num);
+ dptr_num = dptr_create(conn,directory, False, True ,SVAL(inbuf,smb_pid), mask, mask_contains_wcard, dirtype);
+ if (dptr_num < 0) {
talloc_destroy(ea_ctx);
- return ERROR_NT(NT_STATUS_NO_MEMORY);
+ return(UNIXERROR(ERRDOS,ERRbadfile));
}
DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n",dptr_num, mask, dirtype));
BOOL close_if_end = (findnext_flags & FLAG_TRANS2_FIND_CLOSE_IF_END);
BOOL requires_resume_key = (findnext_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME);
BOOL continue_bit = (findnext_flags & FLAG_TRANS2_FIND_CONTINUE);
+ BOOL mask_contains_wcard = False;
pstring resume_name;
pstring mask;
pstring directory;
*mask = *directory = *resume_name = 0;
- srvstr_get_path(inbuf, resume_name, params+12, sizeof(resume_name), -1, STR_TERMINATE, &ntstatus, True);
+ srvstr_get_path_wcard(inbuf, resume_name, params+12, sizeof(resume_name), -1, STR_TERMINATE, &ntstatus, &mask_contains_wcard);
if (!NT_STATUS_IS_OK(ntstatus)) {
/* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to
complain (it thinks we're asking for the directory above the shared
{
SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 18;
- if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+ if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
return(UNIXERROR(ERRHRD,ERRgeneral));
}
{
SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 24;
- if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+ if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
return(UNIXERROR(ERRHRD,ERRgeneral));
}
block_size = lp_block_size(snum);
{
SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 32;
- if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+ if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
return(UNIXERROR(ERRHRD,ERRgeneral));
}
block_size = lp_block_size(snum);
fsp.conn = conn;
fsp.fnum = -1;
- fsp.fd = -1;
/* access check */
if (current_user.uid != 0) {
CIFS_UNIX_POSIX_PATHNAMES_CAP))); /* We have POSIX ACLs and pathname capability. */
break;
+ case SMB_QUERY_POSIX_FS_INFO:
+ {
+ int rc;
+ vfs_statvfs_struct svfs;
+
+ if (!lp_unix_extensions())
+ return ERROR_DOS(ERRDOS,ERRunknownlevel);
+
+ rc = SMB_VFS_STATVFS(conn, ".", &svfs);
+
+ if (!rc) {
+ data_len = 56;
+ SIVAL(pdata,0,svfs.OptimalTransferSize);
+ SIVAL(pdata,4,svfs.BlockSize);
+ SBIG_UINT(pdata,8,svfs.TotalBlocks);
+ SBIG_UINT(pdata,16,svfs.BlocksAvail);
+ SBIG_UINT(pdata,24,svfs.UserBlocksAvail);
+ SBIG_UINT(pdata,32,svfs.TotalFileNodes);
+ SBIG_UINT(pdata,40,svfs.FreeFileNodes);
+ SBIG_UINT(pdata,48,svfs.FsIdentifier);
+ DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_POSIX_FS_INFO succsessful\n"));
+#ifdef EOPNOTSUPP
+ } else if (rc == EOPNOTSUPP) {
+ return ERROR_DOS(ERRDOS, ERRunknownlevel);
+#endif /* EOPNOTSUPP */
+ } else {
+ DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(SNUM(conn))));
+ return ERROR_DOS(ERRSRV,ERRerror);
+ }
+ break;
+ }
+
case SMB_MAC_QUERY_FS_INFO:
/*
* Thursby MAC extension... ONLY on NTFS filesystems
char *pdata = *ppdata;
uint16 info_level;
int mode=0;
+ int nlink;
SMB_OFF_T file_size=0;
SMB_BIG_UINT allocation_size=0;
unsigned int data_size = 0;
files_struct *fsp = NULL;
TALLOC_CTX *ea_ctx = NULL;
struct ea_list *ea_list = NULL;
- uint32 desired_access = 0x12019F; /* Default - GENERIC_EXECUTE mapping from Windows */
+ uint32 access_mask = 0x12019F; /* Default - GENERIC_EXECUTE mapping from Windows */
if (!params)
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
pstrcpy(fname, fsp->fsp_name);
/* We know this name is ok, it's already passed the checks. */
- } else if(fsp && (fsp->is_directory || fsp->fd == -1)) {
+ } else if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
/*
* This is actually a QFILEINFO on a directory
* handle (returned from an NT SMB). NT5.0 seems
return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
}
- delete_pending = fsp->is_directory ? fsp->directory_delete_on_close : 0;
+ delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
} else {
/*
* Original code - this is an open file.
CHECK_FSP(fsp,conn);
pstrcpy(fname, fsp->fsp_name);
- if (SMB_VFS_FSTAT(fsp,fsp->fd,&sbuf) != 0) {
+ if (SMB_VFS_FSTAT(fsp,fsp->fh->fd,&sbuf) != 0) {
DEBUG(3,("fstat of fnum %d failed (%s)\n", fsp->fnum, strerror(errno)));
return(UNIXERROR(ERRDOS,ERRbadfid));
}
- pos = fsp->position_information;
- delete_pending = fsp->delete_on_close;
- desired_access = fsp->desired_access;
+ pos = fsp->fh->position_information;
+ delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+ access_mask = fsp->access_mask;
}
} else {
NTSTATUS status = NT_STATUS_OK;
DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
- srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), -1, STR_TERMINATE, &status, False);
+ srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), -1, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
DEBUG(3,("call_trans2qfilepathinfo: SMB_VFS_STAT of %s failed (%s)\n",fname,strerror(errno)));
return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
}
+
+ delete_pending = get_delete_on_close_flag(sbuf.st_dev, sbuf.st_ino);
+ if (delete_pending) {
+ return ERROR_NT(NT_STATUS_DELETE_PENDING);
+ }
+ }
+
+ nlink = sbuf.st_nlink;
+
+ if ((nlink > 0) && S_ISDIR(sbuf.st_mode)) {
+ /* NTFS does not seem to count ".." */
+ nlink -= 1;
+ }
+
+ if ((nlink > 0) && delete_pending) {
+ nlink -= 1;
}
if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions())
case SMB_INFO_STANDARD:
DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_STANDARD\n"));
data_size = 22;
- put_dos_date2(pdata,l1_fdateCreation,c_time);
- put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime);
- put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */
+ srv_put_dos_date2(pdata,l1_fdateCreation,c_time);
+ srv_put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime);
+ srv_put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */
SIVAL(pdata,l1_cbFile,(uint32)file_size);
SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
SSVAL(pdata,l1_attrFile,mode);
unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
data_size = 26;
- put_dos_date2(pdata,0,c_time);
- put_dos_date2(pdata,4,sbuf.st_atime);
- put_dos_date2(pdata,8,sbuf.st_mtime); /* write time */
+ srv_put_dos_date2(pdata,0,c_time);
+ srv_put_dos_date2(pdata,4,sbuf.st_atime);
+ srv_put_dos_date2(pdata,8,sbuf.st_mtime); /* write time */
SIVAL(pdata,12,(uint32)file_size);
SIVAL(pdata,16,(uint32)allocation_size);
SSVAL(pdata,20,mode);
data_size = 24;
SOFF_T(pdata,0,allocation_size);
SOFF_T(pdata,8,file_size);
- if (delete_pending & sbuf.st_nlink)
- SIVAL(pdata,16,sbuf.st_nlink - 1);
- else
- SIVAL(pdata,16,sbuf.st_nlink);
- SCVAL(pdata,20,0);
+ SIVAL(pdata,16,nlink);
+ SCVAL(pdata,20,delete_pending?1:0);
SCVAL(pdata,21,(mode&aDIR)?1:0);
SSVAL(pdata,22,0); /* Padding. */
break;
pdata += 40;
SOFF_T(pdata,0,allocation_size);
SOFF_T(pdata,8,file_size);
- if (delete_pending && sbuf.st_nlink)
- SIVAL(pdata,16,sbuf.st_nlink - 1);
- else
- SIVAL(pdata,16,sbuf.st_nlink);
+ SIVAL(pdata,16,nlink);
SCVAL(pdata,20,delete_pending);
SCVAL(pdata,21,(mode&aDIR)?1:0);
SSVAL(pdata,22,0);
BasicFileInformationTest. -tpot */
DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
- SIVAL(pdata,0,sbuf.st_dev);
- SIVAL(pdata,4,sbuf.st_ino);
+ SIVAL(pdata,4,sbuf.st_ino); /* FileIndexLow */
+ SIVAL(pdata,0,sbuf.st_dev); /* FileIndexHigh */
data_size = 8;
break;
case SMB_FILE_ACCESS_INFORMATION:
DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
- SIVAL(pdata,0,desired_access);
+ SIVAL(pdata,0,access_mask);
data_size = 4;
break;
uint16 num_file_acls = 0;
uint16 num_def_acls = 0;
- if (fsp && !fsp->is_directory && (fsp->fd != -1)) {
- file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp, fsp->fd);
+ if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
+ file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp, fsp->fh->fd);
} else {
file_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_ACCESS);
}
return(-1);
}
-/****************************************************************************
- Deal with the internal needs of setting the delete on close flag. Note that
- as the tdb locking is recursive, it is safe to call this from within
- open_file_shared. JRA.
-****************************************************************************/
-
-NTSTATUS set_delete_on_close_internal(files_struct *fsp, BOOL delete_on_close, uint32 dosmode)
-{
- if (delete_on_close) {
- /*
- * Only allow delete on close for writable files.
- */
-
- if (!lp_delete_readonly(SNUM(fsp->conn))) {
- if (dosmode & aRONLY) {
- DEBUG(10,("set_delete_on_close_internal: file %s delete on close flag set but file attribute is readonly.\n",
- fsp->fsp_name ));
- return NT_STATUS_CANNOT_DELETE;
- }
- }
-
- /*
- * Only allow delete on close for writable shares.
- */
-
- if (!CAN_WRITE(fsp->conn)) {
- DEBUG(10,("set_delete_on_close_internal: file %s delete on close flag set but write access denied on share.\n",
- fsp->fsp_name ));
- return NT_STATUS_ACCESS_DENIED;
- }
-
- /*
- * Only allow delete on close for files/directories opened with delete intent.
- */
-
- if (!(fsp->desired_access & DELETE_ACCESS)) {
- DEBUG(10,("set_delete_on_close_internal: file %s delete on close flag set but delete access denied.\n",
- fsp->fsp_name ));
- return NT_STATUS_ACCESS_DENIED;
- }
- }
-
- if(fsp->is_directory) {
- fsp->directory_delete_on_close = delete_on_close;
- DEBUG(10, ("set_delete_on_close_internal: %s delete on close flag for fnum = %d, directory %s\n",
- delete_on_close ? "Added" : "Removed", fsp->fnum, fsp->fsp_name ));
- } else {
- fsp->delete_on_close = delete_on_close;
- DEBUG(10, ("set_delete_on_close_internal: %s delete on close flag for fnum = %d, file %s\n",
- delete_on_close ? "Added" : "Removed", fsp->fnum, fsp->fsp_name ));
- }
-
- return NT_STATUS_OK;
-}
-
-/****************************************************************************
- Sets the delete on close flag over all share modes on this file.
- Modify the share mode entry for all files open
- on this device and inode to tell other smbds we have
- changed the delete on close flag. This will be noticed
- in the close code, the last closer will delete the file
- if flag is set.
-****************************************************************************/
-
-NTSTATUS set_delete_on_close_over_all(files_struct *fsp, BOOL delete_on_close)
-{
- DEBUG(10,("set_delete_on_close_over_all: %s delete on close flag for fnum = %d, file %s\n",
- delete_on_close ? "Adding" : "Removing", fsp->fnum, fsp->fsp_name ));
-
- if (fsp->is_directory || fsp->is_stat)
- return NT_STATUS_OK;
-
- if (lock_share_entry_fsp(fsp) == False)
- return NT_STATUS_ACCESS_DENIED;
-
- if (!modify_delete_flag(fsp->dev, fsp->inode, delete_on_close)) {
- DEBUG(0,("set_delete_on_close_over_all: failed to change delete on close flag for file %s\n",
- fsp->fsp_name ));
- unlock_share_entry_fsp(fsp);
- return NT_STATUS_ACCESS_DENIED;
- }
-
- unlock_share_entry_fsp(fsp);
- return NT_STATUS_OK;
-}
-
/****************************************************************************
Set a hard link (called by UNIX extensions and by NT rename with HARD link
code.
fsp = file_fsp(params,0);
info_level = SVAL(params,2);
- if(fsp && (fsp->is_directory || fsp->fd == -1)) {
+ if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
/*
* This is actually a SETFILEINFO on a directory
* handle (returned from an NT SMB). NT5.0 seems
* Doing a DELETE_ON_CLOSE should cancel a print job.
*/
if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
- fsp->share_mode = FILE_DELETE_ON_CLOSE;
+ fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
CHECK_FSP(fsp,conn);
pstrcpy(fname, fsp->fsp_name);
- fd = fsp->fd;
+ fd = fsp->fh->fd;
if (SMB_VFS_FSTAT(fsp,fd,&sbuf) != 0) {
DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
}
info_level = SVAL(params,0);
- srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), -1, STR_TERMINATE, &status, False);
+ srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), -1, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
}
/* access time */
- tvs.actime = make_unix_date2(pdata+l1_fdateLastAccess);
+ tvs.actime = srv_make_unix_date2(pdata+l1_fdateLastAccess);
/* write time */
- tvs.modtime = make_unix_date2(pdata+l1_fdateLastWrite);
+ tvs.modtime = srv_make_unix_date2(pdata+l1_fdateLastWrite);
break;
}
TALLOC_CTX *ctx = NULL;
if (total_data < 10) {
+
+ /* OS/2 workplace shell seems to send SET_EA requests of "null"
+ length. They seem to have no effect. Bug #3212. JRA */
+
+ if ((total_data == 4) && (IVAL(pdata,0) == 4)) {
+ /* We're done. We only get EA info in this call. */
+ SSVAL(params,0,0);
+ send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
+ return(-1);
+ }
+
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
if (fd == -1) {
files_struct *new_fsp = NULL;
- int access_mode = 0;
- int action = 0;
-
- if(global_oplock_break) {
- /* Queue this file modify as we are the process of an oplock break. */
-
- DEBUG(2,("call_trans2setfilepathinfo: queueing message due to being "));
- DEBUGADD(2,( "in oplock break state.\n"));
- push_oplock_pending_smb_message(inbuf, length);
- return -1;
- }
-
- new_fsp = open_file_shared1(conn, fname, &sbuf,FILE_WRITE_DATA,
- SET_OPEN_MODE(DOS_OPEN_RDWR),
- (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),
+ new_fsp = open_file_ntcreate(conn, fname, &sbuf,
+ FILE_WRITE_DATA,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0,
FILE_ATTRIBUTE_NORMAL,
- INTERNAL_OPEN_ONLY, &access_mode, &action);
+ INTERNAL_OPEN_ONLY,
+ NULL);
- if (new_fsp == NULL)
+ if (new_fsp == NULL) {
return(UNIXERROR(ERRDOS,ERRbadpath));
+ }
ret = vfs_allocate_file_space(new_fsp, allocation_size);
- if (SMB_VFS_FSTAT(new_fsp,new_fsp->fd,&new_sbuf) != 0) {
+ if (SMB_VFS_FSTAT(new_fsp,new_fsp->fh->fd,&new_sbuf) != 0) {
DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",
new_fsp->fnum, strerror(errno)));
ret = -1;
if (fsp == NULL)
return(UNIXERROR(ERRDOS,ERRbadfid));
- status = set_delete_on_close_internal(fsp, delete_on_close, dosmode);
+ status = can_set_delete_on_close(fsp, delete_on_close,
+ dosmode);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
/* The set is across all open files on this dev/inode pair. */
- status =set_delete_on_close_over_all(fsp, delete_on_close);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
+ if (!set_delete_on_close(fsp, delete_on_close)) {
+ return ERROR_NT(NT_STATUS_ACCESS_DENIED);
}
SSVAL(params,0,0);
DEBUG(10,("call_trans2setfilepathinfo: Set file position information for file %s to %.0f\n",
fname, (double)position_information ));
if (fsp) {
- fsp->position_information = position_information;
+ fsp->fh->position_information = position_information;
}
/* We're done. We only get position info in this call. */
char *newname = fname;
/* Set a hard link. */
- srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), -1, STR_TERMINATE, &status, False);
+ srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), -1, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
overwrite = (CVAL(pdata,0) ? True : False);
root_fid = IVAL(pdata,4);
len = IVAL(pdata,8);
- srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status, False);
+ srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
} else {
DEBUG(10,("call_trans2setfilepathinfo: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
fname, newname ));
- status = rename_internals(conn, fname, base_name, 0, overwrite);
+ status = rename_internals(conn, fname, base_name, 0, overwrite, False);
}
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
if (fd == -1) {
files_struct *new_fsp = NULL;
- int access_mode = 0;
- int action = 0;
-
- if(global_oplock_break) {
- /* Queue this file modify as we are the process of an oplock break. */
-
- DEBUG(2,("call_trans2setfilepathinfo: queueing message due to being "));
- DEBUGADD(2,( "in oplock break state.\n"));
-
- push_oplock_pending_smb_message(inbuf, length);
- return -1;
- }
- new_fsp = open_file_shared(conn, fname, &sbuf,
- SET_OPEN_MODE(DOS_OPEN_RDWR),
- (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),
+ new_fsp = open_file_ntcreate(conn, fname, &sbuf,
+ FILE_WRITE_DATA,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0,
FILE_ATTRIBUTE_NORMAL,
- INTERNAL_OPEN_ONLY, &access_mode, &action);
+ INTERNAL_OPEN_ONLY,
+ NULL);
- if (new_fsp == NULL)
+ if (new_fsp == NULL) {
return(UNIXERROR(ERRDOS,ERRbadpath));
+ }
ret = vfs_set_filelen(new_fsp, size);
close_file(new_fsp,True);
} else {
ret = vfs_set_filelen(fsp, size);
}
- if (ret == -1)
+ if (ret == -1) {
return (UNIXERROR(ERRHRD,ERRdiskfull));
+ }
}
/*
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
- srvstr_get_path(inbuf, directory, ¶ms[4], sizeof(directory), -1, STR_TERMINATE, &status, False);
+ srvstr_get_path(inbuf, directory, ¶ms[4], sizeof(directory), -1, STR_TERMINATE, &status);
if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
}
}
/* Any data in this call is an EA list. */
- if (total_data && !lp_ea_support(SNUM(conn))) {
+ if (total_data && (total_data != 4) && !lp_ea_support(SNUM(conn))) {
return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
}
- if (total_data) {
+ /*
+ * OS/2 workplace shell seems to send SET_EA requests of "null"
+ * length (4 bytes containing IVAL 4).
+ * They seem to have no effect. Bug #3212. JRA.
+ */
+
+ if (total_data != 4) {
if (total_data < 10) {
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
talloc_destroy(ctx);
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
+ } else if (IVAL(pdata,0) != 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
if (check_name(directory,conn)) {
unsigned int num_params, num_params_sofar, num_data, num_data_sofar;
START_PROFILE(SMBtrans2);
- if(global_oplock_break && (tran_call == TRANSACT2_OPEN)) {
- /* Queue this open message as we are the process of an
- * oplock break. */
-
- DEBUG(2,("reply_trans2: queueing message trans2open due to being "));
- DEBUGADD(2,( "in oplock break state.\n"));
-
- push_oplock_pending_smb_message(inbuf, length);
- END_PROFILE(SMBtrans2);
- return -1;
- }
-
if (IS_IPC(conn) && (tran_call != TRANSACT2_OPEN)
&& (tran_call != TRANSACT2_GET_DFS_REFERRAL)) {
END_PROFILE(SMBtrans2);
of the parameter/data bytes */
outsize = set_message(outbuf,0,0,True);
srv_signing_trans_stop();
+ show_msg(outbuf);
if (!send_smb(smbd_server_fd(),outbuf))
exit_server("reply_trans2: send_smb failed.");