SMB transaction2 handling
Copyright (C) Jeremy Allison 1994-2003
Copyright (C) Stefan (metze) Metzmacher 2003
+ Copyright (C) Volker Lendecke 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);
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. */
}
}
- 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;
- memset((char *)params,'\0',30);
SSVAL(params,0,fsp->fnum);
- SSVAL(params,2,fmode);
+ SSVAL(params,2,open_attr);
put_dos_date2(params,4, mtime);
SIVAL(params,8, (uint32)size);
- SSVAL(params,12,rmode);
+ 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;
* WARNING - this may need to be changed if SMB_INO_T <> 4 bytes.
*/
SIVAL(params,20,inode);
+ SSVAL(params,24,0); /* Padding. */
if (flags & 8) {
uint32 ea_size = estimate_ea_size(conn, fsp, fname);
SIVAL(params, 26, ea_size);
+ } else {
+ SIVAL(params, 26, 0);
}
/* Send the required number of replies */
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,l1_fdateCreation,cdate);
- put_dos_date2(p,l1_fdateLastAccess,adate);
- put_dos_date2(p,l1_fdateLastWrite,mdate);
- SIVAL(p,l1_cbFile,(uint32)file_size);
- SIVAL(p,l1_cbFileAlloc,(uint32)allocation_size);
- SSVAL(p,l1_attrFile,mode);
- p += l1_achName;
+ put_dos_date2(p,0,cdate);
+ put_dos_date2(p,4,adate);
+ put_dos_date2(p,8,mdate);
+ SIVAL(p,12,(uint32)file_size);
+ SIVAL(p,16,(uint32)allocation_size);
+ SSVAL(p,20,mode);
+ p += 23;
nameptr = p;
p += align_string(outbuf, p, 0);
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE);
SIVAL(p,0,reskey);
p += 4;
}
- put_dos_date2(p,l2_fdateCreation,cdate);
- put_dos_date2(p,l2_fdateLastAccess,adate);
- put_dos_date2(p,l2_fdateLastWrite,mdate);
- SIVAL(p,l2_cbFile,(uint32)file_size);
- SIVAL(p,l2_cbFileAlloc,(uint32)allocation_size);
- SSVAL(p,l2_attrFile,mode);
+ put_dos_date2(p,0,cdate);
+ put_dos_date2(p,4,adate);
+ put_dos_date2(p,8,mdate);
+ SIVAL(p,12,(uint32)file_size);
+ SIVAL(p,16,(uint32)allocation_size);
+ SSVAL(p,20,mode);
{
unsigned int ea_size = estimate_ea_size(conn, NULL, pathreal);
- SIVAL(p,l2_cbList,ea_size); /* Extended attributes */
+ SIVAL(p,22,ea_size); /* Extended attributes */
}
- p += l2_achName;
+ p += 27;
nameptr = p - 1;
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE | STR_NOALIGN);
if (SVAL(outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS) {
SIVAL(p,0,reskey);
p += 4;
}
- put_dos_date2(p,l2_fdateCreation,cdate);
- put_dos_date2(p,l2_fdateLastAccess,adate);
- put_dos_date2(p,l2_fdateLastWrite,mdate);
- SIVAL(p,l2_cbFile,(uint32)file_size);
- SIVAL(p,l2_cbFileAlloc,(uint32)allocation_size);
- SSVAL(p,l2_attrFile,mode);
- p += l2_cbList; /* p now points to the EA area. */
+ put_dos_date2(p,0,cdate);
+ put_dos_date2(p,4,adate);
+ put_dos_date2(p,8,mdate);
+ SIVAL(p,12,(uint32)file_size);
+ SIVAL(p,16,(uint32)allocation_size);
+ SSVAL(p,20,mode);
+ p += 22; /* p now points to the EA area. */
file_list = get_ea_list_from_file(ea_ctx, conn, NULL, pathreal, &ea_len);
name_list = ea_list_union(name_list, file_list, &ea_len);
* IMPORTANT as not doing so will trigger
* a Win2k client bug. JRA.
*/
- memset(p,'\0',26);
- if (!was_8_3 && lp_manglednames(SNUM(conn))) {
+ if (!was_8_3 && check_mangled_names) {
pstring mangled_name;
pstrcpy(mangled_name, fname);
mangle_map(mangled_name,True,True,SNUM(conn));
mangled_name[12] = 0;
len = srvstr_push(outbuf, p+2, mangled_name, 24, STR_UPPER|STR_UNICODE);
+ if (len < 24) {
+ memset(p + 2 + len,'\0',24 - len);
+ }
SSVAL(p, 0, len);
} else {
- SSVAL(p,0,0);
- *(p+2) = 0;
+ memset(p,'\0',26);
}
p += 2 + 24;
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
SIVAL(q,0,len);
p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
SIVAL(pdata,0,len);
len = srvstr_push(outbuf, p + 4, fname, -1, STR_TERMINATE_ASCII);
SIVAL(p,0,len);
p += 4 + len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
SIVAL(pdata,0,len);
SIVAL(q, 0, len);
p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
SIVAL(pdata,0,len);
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
SIVAL(p, -4, len);
p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
SIVAL(pdata,0,len);
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
SIVAL(q, 0, len);
p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
SIVAL(pdata,0,len);
* IMPORTANT as not doing so will trigger
* a Win2k client bug. JRA.
*/
- memset(p,'\0',26);
- if (!was_8_3 && lp_manglednames(SNUM(conn))) {
+ if (!was_8_3 && check_mangled_names) {
pstring mangled_name;
pstrcpy(mangled_name, fname);
mangle_map(mangled_name,True,True,SNUM(conn));
mangled_name[12] = 0;
len = srvstr_push(outbuf, p+2, mangled_name, 24, STR_UPPER|STR_UNICODE);
SSVAL(p, 0, len);
+ if (len < 24) {
+ memset(p + 2 + len,'\0',24 - len);
+ }
+ SSVAL(p, 0, len);
} else {
- SSVAL(p,0,0);
- *(p+2) = 0;
+ memset(p,'\0',26);
}
p += 26;
SSVAL(p,0,0); p += 2; /* Reserved ? */
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE_ASCII);
SIVAL(q,0,len);
p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
SIVAL(pdata,0,len);
len = srvstr_push(outbuf, p, fname, -1, STR_TERMINATE);
p += len;
+ SIVAL(p,0,0); /* Ensure any padding is null. */
len = PTR_DIFF(p, pdata);
len = (len + 3) & ~3;
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);
*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) {
}
*ppdata = pdata;
- memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
/* Realloc the params space */
params = SMB_REALLOC(*pparams, 10);
}
*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, 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));
}
*ppdata = pdata;
- memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
/* Realloc the params space */
params = SMB_REALLOC(*pparams, 6*SIZEOFWORD);
fsp.conn = conn;
fsp.fnum = -1;
- fsp.fd = -1;
+ fsp.fh->fd = -1;
/* access check */
if (current_user.uid != 0) {
data_len = 12;
SSVAL(pdata,0,CIFS_UNIX_MAJOR_VERSION);
SSVAL(pdata,2,CIFS_UNIX_MINOR_VERSION);
- SBIG_UINT(pdata,4,((SMB_BIG_UINT)CIFS_UNIX_POSIX_ACLS_CAP)); /* We have POSIX ACLs. */
+ SBIG_UINT(pdata,4,((SMB_BIG_UINT)(CIFS_UNIX_POSIX_ACLS_CAP|
+ CIFS_UNIX_POSIX_PATHNAMES_CAP))); /* We have POSIX ACLs and pathname capability. */
break;
case SMB_MAC_QUERY_FS_INFO:
{
char *pdata = *ppdata;
char *params = *pparams;
- files_struct *fsp = NULL;
uint16 info_level;
int outsize;
- SMB_NTQUOTA_STRUCT quotas;
-
- ZERO_STRUCT(quotas);
-
- DEBUG(10,("call_trans2setfsinfo: SET_FS_QUOTA: for service [%s]\n",lp_servicename(SNUM(conn))));
- /* access check */
- if ((current_user.uid != 0)||!CAN_WRITE(conn)) {
- DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
- lp_servicename(SNUM(conn)),conn->user));
- return ERROR_DOS(ERRSRV,ERRaccess);
- }
+ DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",lp_servicename(SNUM(conn))));
/* */
if (total_params < 4) {
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
- fsp = file_fsp(params,0);
-
- if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
- DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
- return ERROR_NT(NT_STATUS_INVALID_HANDLE);
- }
-
info_level = SVAL(params,2);
switch(info_level) {
- case SMB_FS_QUOTA_INFORMATION:
- /* note: normaly there're 48 bytes,
- * but we didn't use the last 6 bytes for now
- * --metze
- */
- if (total_data < 42) {
- DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
- total_data));
- return ERROR_DOS(ERRDOS,ERRunknownlevel);
+ case SMB_SET_CIFS_UNIX_INFO:
+ {
+ uint16 client_unix_major;
+ uint16 client_unix_minor;
+ uint32 client_unix_cap_low;
+ uint32 client_unix_cap_high;
+
+ if (!lp_unix_extensions()) {
+ return ERROR_DOS(ERRDOS,ERRunknownlevel);
+ }
+
+ /* There should be 12 bytes of capabilities set. */
+ if (total_data < 8) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ client_unix_major = SVAL(pdata,0);
+ client_unix_minor = SVAL(pdata,2);
+ client_unix_cap_low = IVAL(pdata,4);
+ client_unix_cap_high = IVAL(pdata,8);
+ /* Just print these values for now. */
+ DEBUG(10,("call_trans2setfsinfo: set unix info. major = %u, minor = %u \
+cap_low = 0x%x, cap_high = 0x%x\n",
+ (unsigned int)client_unix_major,
+ (unsigned int)client_unix_minor,
+ (unsigned int)client_unix_cap_low,
+ (unsigned int)client_unix_cap_high ));
+
+ /* Here is where we must switch to posix pathname processing... */
+ lp_set_posix_pathnames();
+ mangle_change_to_posix();
+ break;
}
+ case SMB_FS_QUOTA_INFORMATION:
+ {
+ files_struct *fsp = NULL;
+ SMB_NTQUOTA_STRUCT quotas;
+
+ ZERO_STRUCT(quotas);
+
+ /* access check */
+ if ((current_user.uid != 0)||!CAN_WRITE(conn)) {
+ DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
+ lp_servicename(SNUM(conn)),conn->user));
+ return ERROR_DOS(ERRSRV,ERRaccess);
+ }
+
+ /* note: normaly there're 48 bytes,
+ * but we didn't use the last 6 bytes for now
+ * --metze
+ */
+ fsp = file_fsp(params,0);
+ if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
+ DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
+ return ERROR_NT(NT_STATUS_INVALID_HANDLE);
+ }
+
+ if (total_data < 42) {
+ DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
+ total_data));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
- /* unknown_1 24 NULL bytes in pdata*/
+ /* unknown_1 24 NULL bytes in pdata*/
- /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
- quotas.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
+ /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
+ quotas.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
#ifdef LARGE_SMB_OFF_T
- quotas.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
+ quotas.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
#else /* LARGE_SMB_OFF_T */
- if ((IVAL(pdata,28) != 0)&&
- ((quotas.softlim != 0xFFFFFFFF)||
- (IVAL(pdata,28)!=0xFFFFFFFF))) {
- /* more than 32 bits? */
- return ERROR_DOS(ERRDOS,ERRunknownlevel);
- }
+ if ((IVAL(pdata,28) != 0)&&
+ ((quotas.softlim != 0xFFFFFFFF)||
+ (IVAL(pdata,28)!=0xFFFFFFFF))) {
+ /* more than 32 bits? */
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
#endif /* LARGE_SMB_OFF_T */
- /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
- quotas.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
+ /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
+ quotas.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
#ifdef LARGE_SMB_OFF_T
- quotas.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
+ quotas.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
#else /* LARGE_SMB_OFF_T */
- if ((IVAL(pdata,36) != 0)&&
- ((quotas.hardlim != 0xFFFFFFFF)||
- (IVAL(pdata,36)!=0xFFFFFFFF))) {
- /* more than 32 bits? */
- return ERROR_DOS(ERRDOS,ERRunknownlevel);
- }
+ if ((IVAL(pdata,36) != 0)&&
+ ((quotas.hardlim != 0xFFFFFFFF)||
+ (IVAL(pdata,36)!=0xFFFFFFFF))) {
+ /* more than 32 bits? */
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
#endif /* LARGE_SMB_OFF_T */
- /* quota_flags 2 bytes **/
- quotas.qflags = SVAL(pdata,40);
+ /* quota_flags 2 bytes **/
+ quotas.qflags = SVAL(pdata,40);
- /* unknown_2 6 NULL bytes follow*/
+ /* unknown_2 6 NULL bytes follow*/
- /* now set the quotas */
- if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {
- DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
- return ERROR_DOS(ERRSRV,ERRerror);
- }
+ /* now set the quotas */
+ if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, "as)!=0) {
+ DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
+ return ERROR_DOS(ERRSRV,ERRerror);
+ }
- break;
+ break;
+ }
default:
DEBUG(3,("call_trans2setfsinfo: unknown level (0x%X) not implemented yet.\n",
info_level));
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,
+ fname);
} 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,
+ fname);
+ access_mask = fsp->access_mask;
}
} else {
NTSTATUS status = NT_STATUS_OK;
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,
+ fname);
+ 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())
return ERROR_NT(NT_STATUS_NO_MEMORY);
}
*pparams = params;
- memset((char *)params,'\0',2);
+ SSVAL(params,0,0);
data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
pdata = SMB_REALLOC(*ppdata, data_size);
if ( pdata == NULL ) {
}
*ppdata = pdata;
- memset((char *)pdata,'\0',data_size);
-
c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
allocation_size = get_allocation_size(conn,fsp,&sbuf);
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,l1_fdateCreation,c_time);
- put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime);
- 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);
- SIVAL(pdata,l1_attrFile+2,ea_size);
+ 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 */
+ SIVAL(pdata,12,(uint32)file_size);
+ SIVAL(pdata,16,(uint32)allocation_size);
+ SSVAL(pdata,20,mode);
+ SIVAL(pdata,22,ea_size);
break;
}
DEBUG(5,("write: %s ", ctime(&sbuf.st_mtime)));
DEBUG(5,("change: %s ", ctime(&sbuf.st_mtime)));
DEBUG(5,("mode: %x\n", mode));
-
break;
case SMB_FILE_STANDARD_INFORMATION:
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;
case SMB_FILE_EA_INFORMATION:
put_long_date(pdata+16,sbuf.st_mtime); /* write time */
put_long_date(pdata+24,sbuf.st_mtime); /* change time */
SIVAL(pdata,32,mode);
+ SIVAL(pdata,36,0); /* padding. */
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);
pdata += 24;
SIVAL(pdata,0,ea_size);
pdata += 4; /* EA info */
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)));
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. */
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));
+ }
}
/*
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.");