return False;
}
-struct ea_list {
- struct ea_list *next, *prev;
- struct ea_struct ea;
-};
-
/****************************************************************************
Get one EA value. Fill in a struct ea_struct.
****************************************************************************/
} else {
pea->name = ea_name;
}
- pea->value.data = val;
+ pea->value.data = (unsigned char *)val;
pea->value.length = (size_t)sizeret;
return True;
}
Return a linked list of the total EA's. Plus the total size
****************************************************************************/
-static struct ea_list *get_ea_list(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp, const char *fname, size_t *pea_total_len)
+static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp,
+ const char *fname, size_t *pea_total_len)
{
/* Get a list of all xattrs. Max namesize is 64k. */
size_t ea_namelist_size = 1024;
if (sizeret == -1)
return NULL;
- DEBUG(10,("get_ea_list: ea_namelist size = %d\n", sizeret ));
+ DEBUG(10,("get_ea_list_from_file: ea_namelist size = %d\n", sizeret ));
if (sizeret) {
for (p = ea_namelist; p - ea_namelist < sizeret; p += strlen(p) + 1) {
fstring dos_ea_name;
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: total_len = %u, %s, val len = %u\n",
+ DEBUG(10,("get_ea_list_from_file: total_len = %u, %s, val len = %u\n",
*pea_total_len, dos_ea_name,
(unsigned int)listp->ea.value.length ));
}
}
}
- DEBUG(10,("get_ea_list: total_len = %u\n", *pea_total_len));
+ DEBUG(10,("get_ea_list_from_file: total_len = %u\n", *pea_total_len));
return ea_list_head;
}
that was filled.
****************************************************************************/
-static unsigned int fill_ea_buffer(char *pdata, unsigned int total_data_size,
- connection_struct *conn, files_struct *fsp, const char *fname)
+static unsigned int fill_ea_buffer(TALLOC_CTX *mem_ctx, char *pdata, unsigned int total_data_size,
+ connection_struct *conn, struct ea_list *ea_list)
{
unsigned int ret_data_size = 4;
char *p = pdata;
- size_t total_ea_len;
- TALLOC_CTX *mem_ctx;
- struct ea_list *ea_list;
SMB_ASSERT(total_data_size >= 4);
- SIVAL(pdata,0,0);
if (!lp_ea_support(SNUM(conn))) {
- return 4;
- }
- mem_ctx = talloc_init("fill_ea_buffer");
- if (!mem_ctx) {
- return 4;
- }
-
- ea_list = get_ea_list(mem_ctx, conn, fsp, fname, &total_ea_len);
- if (!ea_list) {
- talloc_destroy(mem_ctx);
- return 4;
- }
-
- if (total_ea_len > total_data_size) {
- talloc_destroy(mem_ctx);
+ SIVAL(pdata,4,0);
return 4;
}
}
ret_data_size = PTR_DIFF(p, pdata);
- DEBUG(10,("fill_ea_buffer: data_size = %u, total_ea_len = %u\n",
- ret_data_size, total_ea_len ));
- talloc_destroy(mem_ctx);
+ DEBUG(10,("fill_ea_buffer: data_size = %u\n", ret_data_size ));
SIVAL(pdata,0,ret_data_size);
return ret_data_size;
}
return 0;
}
mem_ctx = talloc_init("estimate_ea_size");
- (void)get_ea_list(mem_ctx, conn, fsp, fname, &total_ea_len);
+ (void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
talloc_destroy(mem_ctx);
return total_ea_len;
}
{
size_t total_ea_len;
TALLOC_CTX *mem_ctx = talloc_init("canonicalize_ea_name");
- struct ea_list *ea_list = get_ea_list(mem_ctx, conn, fsp, fname, &total_ea_len);
+ struct ea_list *ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
for (; ea_list; ea_list = ea_list->next) {
if (strequal(&unix_ea_name[5], ea_list->ea.name)) {
Set or delete an extended attribute.
****************************************************************************/
-static NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname,
- char *pdata, int total_data)
+NTSTATUS set_ea(connection_struct *conn, files_struct *fsp, const char *fname, struct ea_list *ea_list)
{
- unsigned int namelen;
- unsigned int ealen;
- int ret;
- fstring unix_ea_name;
-
if (!lp_ea_support(SNUM(conn))) {
return NT_STATUS_EAS_NOT_SUPPORTED;
}
- if (total_data < 8) {
- return NT_STATUS_INVALID_PARAMETER;
+ for (;ea_list; ea_list = ea_list->next) {
+ int ret;
+ fstring unix_ea_name;
+
+ fstrcpy(unix_ea_name, "user."); /* All EA's must start with user. */
+ fstrcat(unix_ea_name, ea_list->ea.name);
+
+ 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));
+
+ if (samba_private_attr_name(unix_ea_name)) {
+ DEBUG(10,("set_ea: ea name %s is a private Samba name.\n", unix_ea_name));
+ return NT_STATUS_ACCESS_DENIED;
+ }
+
+ if (ea_list->ea.value.length == 0) {
+ /* Remove the attribute. */
+ if (fsp && (fsp->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);
+ } else {
+ DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
+ unix_ea_name, fname));
+ ret = SMB_VFS_REMOVEXATTR(conn, fname, unix_ea_name);
+ }
+#ifdef ENOATTR
+ /* Removing a non existent attribute always succeeds. */
+ if (ret == -1 && errno == ENOATTR) {
+ DEBUG(10,("set_ea: deleting ea name %s didn't exist - succeeding by default.\n",
+ unix_ea_name));
+ ret = 0;
+ }
+#endif
+ } else {
+ if (fsp && (fsp->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,
+ ea_list->ea.value.data, ea_list->ea.value.length, 0);
+ } else {
+ DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
+ unix_ea_name, fname));
+ ret = SMB_VFS_SETXATTR(conn, fname, unix_ea_name,
+ ea_list->ea.value.data, ea_list->ea.value.length, 0);
+ }
+ }
+
+ if (ret == -1) {
+#ifdef ENOTSUP
+ if (errno == ENOTSUP) {
+ return NT_STATUS_EAS_NOT_SUPPORTED;
+ }
+#endif
+ return map_nt_error_from_unix(errno);
+ }
+
}
+ return NT_STATUS_OK;
+}
+/****************************************************************************
+ Read a list of EA names from an incoming data buffer. Create an ea_list with them.
+****************************************************************************/
+
+static struct ea_list *read_ea_name_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
+{
+ struct ea_list *ea_list_head = NULL;
+ size_t offset = 0;
+
+ while (offset + 2 < data_size) {
+ struct ea_list *tmp;
+ struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);
+ unsigned int namelen = CVAL(pdata,offset);
+
+ offset++; /* Go past the namelen byte. */
- if (IVAL(pdata,0) > total_data) {
- DEBUG(10,("set_ea: bad total data size (%u) > %u\n", IVAL(pdata,0), (unsigned int)total_data));
- return NT_STATUS_INVALID_PARAMETER;
+ /* integer wrap paranioa. */
+ if ((offset + namelen < offset) || (offset + namelen < namelen) ||
+ (offset > data_size) || (namelen > data_size) ||
+ (offset + namelen >= data_size)) {
+ break;
+ }
+ /* Ensure the name is null terminated. */
+ if (pdata[offset + namelen] != '\0') {
+ return NULL;
+ }
+ pull_ascii_talloc(ctx, &eal->ea.name, &pdata[offset]);
+ if (!eal->ea.name) {
+ return NULL;
+ }
+
+ offset += (namelen + 1); /* Go past the name + terminating zero. */
+ DLIST_ADD_END(ea_list_head, eal, tmp);
+ DEBUG(10,("read_ea_name_list: read ea name %s\n", eal->ea.name));
}
- pdata += 4;
- namelen = CVAL(pdata,1);
- ealen = SVAL(pdata,2);
- pdata += 4;
- if (total_data < 8 + namelen + 1 + ealen) {
- DEBUG(10,("set_ea: bad total data size (%u) < 8 + namelen (%u) + 1 + ealen (%u)\n",
- (unsigned int)total_data, namelen, ealen));
- return NT_STATUS_INVALID_PARAMETER;
+ return ea_list_head;
+}
+
+/****************************************************************************
+ Read one EA list entry from the buffer.
+****************************************************************************/
+
+struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used)
+{
+ struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);
+ uint16 val_len;
+ unsigned int namelen;
+
+ if (!eal) {
+ return NULL;
}
- if (pdata[namelen] != '\0') {
- DEBUG(10,("set_ea: ea name not null terminated\n"));
- return NT_STATUS_INVALID_PARAMETER;
+ if (data_size < 6) {
+ return NULL;
}
- fstrcpy(unix_ea_name, "user."); /* All EA's must start with user. */
- pull_ascii(&unix_ea_name[5], pdata, sizeof(fstring) - 5, -1, STR_TERMINATE);
- pdata += (namelen + 1);
+ eal->ea.flags = CVAL(pdata,0);
+ namelen = CVAL(pdata,1);
+ val_len = SVAL(pdata,2);
- canonicalize_ea_name(conn, fsp, fname, unix_ea_name);
+ if (4 + namelen + 1 + val_len > data_size) {
+ return NULL;
+ }
- DEBUG(10,("set_ea: ea_name %s ealen = %u\n", unix_ea_name, ealen));
- if (ealen) {
- DEBUG(10,("set_ea: data :\n"));
- dump_data(10, pdata, ealen);
+ /* Ensure the name is null terminated. */
+ if (pdata[namelen + 4] != '\0') {
+ return NULL;
+ }
+ pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4);
+ if (!eal->ea.name) {
+ return NULL;
}
- if (samba_private_attr_name(unix_ea_name)) {
- DEBUG(10,("set_ea: ea name %s is a private Samba name.\n", unix_ea_name));
- return NT_STATUS_ACCESS_DENIED;
+ eal->ea.value = data_blob(NULL, (size_t)val_len + 1);
+ if (!eal->ea.value.data) {
+ return NULL;
}
- if (ealen == 0) {
- /* Remove the attribute. */
- if (fsp && (fsp->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);
- } else {
- DEBUG(10,("set_ea: deleting ea name %s on file %s.\n",
- unix_ea_name, fname));
- ret = SMB_VFS_REMOVEXATTR(conn, fname, unix_ea_name);
- }
-#ifdef ENOATTR
- /* Removing a non existent attribute always succeeds. */
- if (ret == -1 && errno == ENOATTR) {
- DEBUG(10,("set_ea: deleting ea name %s didn't exist - succeeding by default.\n", unix_ea_name));
- ret = 0;
- }
-#endif
- } else {
- if (fsp && (fsp->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, pdata, ealen, 0);
- } else {
- DEBUG(10,("set_ea: setting ea name %s on file %s.\n",
- unix_ea_name, fname));
- ret = SMB_VFS_SETXATTR(conn, fname, unix_ea_name, pdata, ealen, 0);
+ memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);
+
+ /* Ensure we're null terminated just in case we print the value. */
+ eal->ea.value.data[val_len] = '\0';
+ /* But don't count the null. */
+ eal->ea.value.length--;
+
+ if (pbytes_used) {
+ *pbytes_used = 4 + namelen + 1 + val_len;
+ }
+
+ 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);
+
+ return eal;
+}
+
+/****************************************************************************
+ Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
+****************************************************************************/
+
+static struct ea_list *read_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
+{
+ struct ea_list *ea_list_head = NULL;
+ size_t offset = 0;
+ size_t bytes_used = 0;
+
+ while (offset < data_size) {
+ struct ea_list *tmp;
+ struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset, data_size - offset, &bytes_used);
+
+ if (!eal) {
+ return NULL;
}
+
+ DLIST_ADD_END(ea_list_head, eal, tmp);
+ offset += bytes_used;
}
- if (ret == -1) {
-#ifdef ENOTSUP
- if (errno == ENOTSUP) {
- return NT_STATUS_EAS_NOT_SUPPORTED;
+ return ea_list_head;
+}
+
+/****************************************************************************
+ Count the total EA size needed.
+****************************************************************************/
+
+static size_t ea_list_size(struct ea_list *ealist)
+{
+ fstring dos_ea_name;
+ struct ea_list *listp;
+ size_t ret = 0;
+
+ for (listp = ealist; listp; listp = listp->next) {
+ push_ascii_fstring(dos_ea_name, listp->ea.name);
+ ret += 4 + strlen(dos_ea_name) + 1 + listp->ea.value.length;
+ }
+ /* Add on 4 for total length. */
+ if (ret) {
+ ret += 4;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ Return a union of EA's from a file list and a list of names.
+ The TALLOC context for the two lists *MUST* be identical as we steal
+ memory from one list to add to another. JRA.
+****************************************************************************/
+
+static struct ea_list *ea_list_union(struct ea_list *name_list, struct ea_list *file_list, size_t *total_ea_len)
+{
+ struct ea_list *nlistp, *flistp;
+
+ for (nlistp = name_list; nlistp; nlistp = nlistp->next) {
+ for (flistp = file_list; flistp; flistp = flistp->next) {
+ if (strequal(nlistp->ea.name, flistp->ea.name)) {
+ break;
+ }
+ }
+
+ if (flistp) {
+ /* Copy the data from this entry. */
+ nlistp->ea.flags = flistp->ea.flags;
+ nlistp->ea.value = flistp->ea.value;
+ } else {
+ /* Null entry. */
+ nlistp->ea.flags = 0;
+ ZERO_STRUCT(nlistp->ea.value);
}
-#endif
- return map_nt_error_from_unix(errno);
}
- return NT_STATUS_OK;
+ *total_ea_len = ea_list_size(name_list);
+ return name_list;
}
/****************************************************************************
unsigned int max_data_bytes)
{
char *params = *pparams;
+ char *pdata = *ppdata;
int16 open_mode;
int16 open_attr;
BOOL oplock_request;
int smb_action = 0;
BOOL bad_path = False;
files_struct *fsp;
+ TALLOC_CTX *ctx = NULL;
+ struct ea_list *ea_list = NULL;
NTSTATUS status;
/*
* Ensure we have enough parameters to perform the operation.
*/
- if (total_params < 29)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 29) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
open_mode = SVAL(params, 2);
open_attr = SVAL(params,6);
return ERROR_NT(status);
}
- DEBUG(3,("trans2open %s mode=%d attr=%d ofun=%d size=%d\n",
+ DEBUG(3,("call_trans2open %s mode=%d attr=%d ofun=%d size=%d\n",
fname,open_mode, open_attr, 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);
}
+ /* Any data in this call is an EA list. */
+ if (total_data && !lp_ea_support(SNUM(conn))) {
+ return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
+ }
+
+ if (total_data) {
+ if (total_data < 10) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (IVAL(pdata,0) > total_data) {
+ DEBUG(10,("call_trans2open: bad total data size (%u) > %u\n",
+ IVAL(pdata,0), (unsigned int)total_data));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ ctx = talloc_init("TRANS2_OPEN_SET_EA");
+ if (!ctx) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+ ea_list = read_ea_list(ctx, pdata + 4, total_data - 4);
+ if (!ea_list) {
+ talloc_destroy(ctx);
+ 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);
if (!fsp) {
+ talloc_destroy(ctx);
if (open_was_deferred(SVAL(inbuf,smb_mid))) {
/* We have re-scheduled this call. */
clear_cached_errors();
mtime = sbuf.st_mtime;
inode = sbuf.st_ino;
if (fmode & aDIR) {
+ talloc_destroy(ctx);
close_file(fsp,False);
return(ERROR_DOS(ERRDOS,ERRnoaccess));
}
+ if (total_data && smb_action == FILE_WAS_CREATED) {
+ status = set_ea(conn, fsp, fname, ea_list);
+ talloc_destroy(ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ close_file(fsp,False);
+ return ERROR_NT(status);
+ }
+ }
+
/* Realloc the size of parameters and data we will return */
params = SMB_REALLOC(*pparams, 28);
- if( params == NULL )
- return(ERROR_DOS(ERRDOS,ERRnomem));
+ if( params == NULL ) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
memset((char *)params,'\0',28);
BOOL dont_descend,char **ppdata,
char *base_data, int space_remaining,
BOOL *out_of_space, BOOL *got_exact_match,
- int *last_entry_off)
+ int *last_entry_off, struct ea_list *name_list, TALLOC_CTX *ea_ctx)
{
const char *dname;
BOOL found = False;
nt_extmode = mode ? mode : FILE_ATTRIBUTE_NORMAL;
switch (info_level) {
- case SMB_INFO_STANDARD:
- DEBUG(10,("get_lanman2_dir_entry: SMB_INFO_STANDARD\n"));
+ case SMB_FIND_INFO_STANDARD:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_INFO_STANDARD\n"));
if(requires_resume_key) {
SIVAL(p,0,reskey);
p += 4;
p += len;
break;
- case SMB_INFO_QUERY_EA_SIZE:
- DEBUG(10,("get_lanman2_dir_entry: SMB_INFO_QUERY_EA_SIZE\n"));
+ case SMB_FIND_EA_SIZE:
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_SIZE\n"));
if(requires_resume_key) {
SIVAL(p,0,reskey);
p += 4;
SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
break;
+ case SMB_FIND_EA_LIST:
+ {
+ struct ea_list *file_list = NULL;
+ size_t ea_len = 0;
+
+ DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_EA_LIST\n"));
+ if (!name_list) {
+ return False;
+ }
+ if(requires_resume_key) {
+ 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. */
+
+ 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);
+
+ /* We need to determine if this entry will fit in the space available. */
+ /* Max string size is 255 bytes. */
+ if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
+ /* Move the dirptr back to prev_dirpos */
+ dptr_SeekDir(conn->dirptr, prev_dirpos);
+ *out_of_space = True;
+ DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
+ return False; /* Not finished - just out of space */
+ }
+
+ /* Push the ea_data followed by the name. */
+ p += fill_ea_buffer(ea_ctx, p, space_remaining, conn, name_list);
+ nameptr = p;
+ len = srvstr_push(outbuf, p + 1, fname, -1, STR_TERMINATE | STR_NOALIGN);
+ if (SVAL(outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS) {
+ if (len > 2) {
+ len -= 2;
+ } else {
+ len = 0;
+ }
+ } else {
+ if (len > 1) {
+ len -= 1;
+ } else {
+ len = 0;
+ }
+ }
+ SCVAL(nameptr,0,len);
+ p += len + 1;
+ SCVAL(p,0,0); p += 1; /* Extra zero byte ? - why.. */
+ break;
+ }
+
case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
DEBUG(10,("get_lanman2_dir_entry: SMB_FIND_FILE_BOTH_DIRECTORY_INFO\n"));
was_8_3 = mangle_is_8_3(fname, True);
int space_remaining;
BOOL bad_path = False;
SMB_STRUCT_STAT sbuf;
+ TALLOC_CTX *ea_ctx = NULL;
+ struct ea_list *ea_list = NULL;
NTSTATUS ntstatus = NT_STATUS_OK;
- if (total_params < 12)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 12) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
*directory = *mask = 0;
}
switch (info_level) {
- case SMB_INFO_STANDARD:
- case SMB_INFO_QUERY_EA_SIZE:
+ case SMB_FIND_INFO_STANDARD:
+ case SMB_FIND_EA_SIZE:
+ case SMB_FIND_EA_LIST:
case SMB_FIND_FILE_DIRECTORY_INFO:
case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
case SMB_FIND_FILE_NAMES_INFO:
return ERROR_NT(ntstatus);
}
- RESOLVE_FINDFIRST_DFSPATH(directory, conn, inbuf, outbuf);
+ RESOLVE_DFSPATH_WCARD(directory, conn, inbuf, outbuf);
unix_convert(directory,conn,0,&bad_path,&sbuf);
if (bad_path) {
DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
+ if (info_level == SMB_FIND_EA_LIST) {
+ uint32 ea_size;
+
+ if (total_data < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ ea_size = IVAL(pdata,0);
+ if (ea_size != total_data) {
+ DEBUG(4,("call_trans2findfirst: Rejecting EA request with incorrect \
+total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (!lp_ea_support(SNUM(conn))) {
+ return ERROR_DOS(ERRDOS,ERReasnotsupported);
+ }
+
+ if ((ea_ctx = talloc_init("findnext_ea_list")) == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+
+ /* Pull out the list of names. */
+ ea_list = read_ea_name_list(ea_ctx, pdata + 4, ea_size - 4);
+ if (!ea_list) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ }
+
pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
- if( pdata == NULL )
- return(ERROR_DOS(ERRDOS,ERRnomem));
+ if( pdata == NULL ) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*ppdata = pdata;
memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
/* Realloc the params space */
params = SMB_REALLOC(*pparams, 10);
- if (params == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if (params == NULL) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
dptr_num = dptr_create(conn,directory, False, True ,SVAL(inbuf,smb_pid));
- if (dptr_num < 0)
+ 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);
- return ERROR_DOS(ERRDOS,ERRnomem);
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
}
DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n",dptr_num, mask, dirtype));
mask,dirtype,info_level,
requires_resume_key,dont_descend,
&p,pdata,space_remaining, &out_of_space, &got_exact_match,
- &last_entry_off);
+ &last_entry_off, ea_list, ea_ctx);
}
if (finished && out_of_space)
space_remaining = max_data_bytes - PTR_DIFF(p,pdata);
}
+ talloc_destroy(ea_ctx);
+
/* Check if we can close the dirptr */
if(close_after_first || (finished && close_if_end)) {
DEBUG(5,("call_trans2findfirst - (2) closing dptr_num %d\n", dptr_num));
/*
* If there are no matching entries we must return ERRDOS/ERRbadfile -
- * from observation of NT.
+ * from observation of NT. NB. This changes to ERRDOS,ERRnofiles if
+ * the protocol level is less than NT1. Tested with smbclient. JRA.
+ * This should fix the OS/2 client bug #2335.
*/
if(numentries == 0) {
dptr_close(&dptr_num);
- return ERROR_DOS(ERRDOS,ERRbadfile);
+ if (Protocol < PROTOCOL_NT1) {
+ return ERROR_DOS(ERRDOS,ERRnofiles);
+ } else {
+ return ERROR_BOTH(NT_STATUS_NO_SUCH_FILE,ERRDOS,ERRbadfile);
+ }
}
/* At this point pdata points to numentries directory entries. */
BOOL dont_descend = False;
BOOL out_of_space = False;
int space_remaining;
+ TALLOC_CTX *ea_ctx = NULL;
+ struct ea_list *ea_list = NULL;
NTSTATUS ntstatus = NT_STATUS_OK;
- if (total_params < 12)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 12) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
*mask = *directory = *resume_name = 0;
srvstr_get_path(inbuf, resume_name, params+12, sizeof(resume_name), -1, STR_TERMINATE, &ntstatus, True);
if (!NT_STATUS_IS_OK(ntstatus)) {
- return ERROR_NT(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
+ path or an invalid name). Catch this as the resume name is only compared, never used in
+ a file access. JRA. */
+ if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_OBJECT_PATH_SYNTAX_BAD)) {
+ pstrcpy(resume_name, "..");
+ } else if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_OBJECT_NAME_INVALID)) {
+ pstrcpy(resume_name, ".");
+ } else {
+ return ERROR_NT(ntstatus);
+ }
}
DEBUG(3,("call_trans2findnext: dirhandle = %d, max_data_bytes = %d, maxentries = %d, \
}
switch (info_level) {
- case SMB_INFO_STANDARD:
- case SMB_INFO_QUERY_EA_SIZE:
+ case SMB_FIND_INFO_STANDARD:
+ case SMB_FIND_EA_SIZE:
+ case SMB_FIND_EA_LIST:
case SMB_FIND_FILE_DIRECTORY_INFO:
case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
case SMB_FIND_FILE_NAMES_INFO:
return ERROR_DOS(ERRDOS,ERRunknownlevel);
}
+ if (info_level == SMB_FIND_EA_LIST) {
+ uint32 ea_size;
+
+ if (total_data < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ ea_size = IVAL(pdata,0);
+ if (ea_size != total_data) {
+ DEBUG(4,("call_trans2findnext: Rejecting EA request with incorrect \
+total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (!lp_ea_support(SNUM(conn))) {
+ return ERROR_DOS(ERRDOS,ERReasnotsupported);
+ }
+
+ if ((ea_ctx = talloc_init("findnext_ea_list")) == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+
+ /* Pull out the list of names. */
+ ea_list = read_ea_name_list(ea_ctx, pdata + 4, ea_size - 4);
+ if (!ea_list) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ }
+
pdata = SMB_REALLOC( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
- if(pdata == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if(pdata == NULL) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*ppdata = pdata;
memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
/* Realloc the params space */
params = SMB_REALLOC(*pparams, 6*SIZEOFWORD);
- if( params == NULL )
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if( params == NULL ) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
/* Check that the dptr is valid */
- if(!(conn->dirptr = dptr_fetch_lanman2(dptr_num)))
+ if(!(conn->dirptr = dptr_fetch_lanman2(dptr_num))) {
+ talloc_destroy(ea_ctx);
return ERROR_DOS(ERRDOS,ERRnofiles);
+ }
string_set(&conn->dirpath,dptr_path(dptr_num));
/* Get the wildcard mask from the dptr */
if((p = dptr_wcard(dptr_num))== NULL) {
DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num));
+ talloc_destroy(ea_ctx);
return ERROR_DOS(ERRDOS,ERRnofiles);
}
mask,dirtype,info_level,
requires_resume_key,dont_descend,
&p,pdata,space_remaining, &out_of_space, &got_exact_match,
- &last_entry_off);
+ &last_entry_off, ea_list, ea_ctx);
}
if (finished && out_of_space)
space_remaining = max_data_bytes - PTR_DIFF(p,pdata);
}
+ talloc_destroy(ea_ctx);
+
/* Check if we can close the dirptr */
if(close_after_request || (finished && close_if_end)) {
DEBUG(5,("call_trans2findnext: closing dptr_num = %d\n", dptr_num));
}
pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
- if ( pdata == NULL )
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if ( pdata == NULL ) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*ppdata = pdata;
memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
{
SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 18;
- SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize);
+ if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+ return(UNIXERROR(ERRHRD,ERRgeneral));
+ }
+
block_size = lp_block_size(snum);
if (bsize < block_size) {
SMB_BIG_UINT factor = block_size/bsize;
* the called hostname and the service name.
*/
SIVAL(pdata,0,str_checksum(lp_servicename(snum)) ^ (str_checksum(get_local_machine_name())<<16) );
- len = srvstr_push(outbuf, pdata+l2_vol_szVolLabel, vname, -1, STR_NOALIGN);
+ /*
+ * Win2k3 and previous mess this up by sending a name length
+ * one byte short. I believe only older clients (OS/2 Win9x) use
+ * this call so try fixing this by adding a terminating null to
+ * the pushed string. The change here was adding the STR_TERMINATE. JRA.
+ */
+ len = srvstr_push(outbuf, pdata+l2_vol_szVolLabel, vname, -1, STR_NOALIGN|STR_TERMINATE);
SCVAL(pdata,l2_vol_cch,len);
data_len = l2_vol_szVolLabel + len;
DEBUG(5,("call_trans2qfsinfo : time = %x, namelen = %d, name = %s\n",
{
SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 24;
- SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize);
+ if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+ return(UNIXERROR(ERRHRD,ERRgeneral));
+ }
block_size = lp_block_size(snum);
if (bsize < block_size) {
SMB_BIG_UINT factor = block_size/bsize;
{
SMB_BIG_UINT dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 32;
- SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize);
+ if (SMB_VFS_DISK_FREE(conn,".",False,&bsize,&dfree,&dsize) == (SMB_BIG_UINT)-1) {
+ return(UNIXERROR(ERRHRD,ERRgeneral));
+ }
block_size = lp_block_size(snum);
if (bsize < block_size) {
SMB_BIG_UINT factor = block_size/bsize;
if (total_params < 4) {
DEBUG(0,("call_trans2setfsinfo: requires total_params(%d) >= 4 bytes!\n",
total_params));
- return ERROR_DOS(ERRDOS,ERRinvalidparam);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
fsp = file_fsp(params,0);
int mode=0;
SMB_OFF_T file_size=0;
SMB_BIG_UINT allocation_size=0;
- unsigned int data_size;
+ unsigned int data_size = 0;
unsigned int param_size = 2;
SMB_STRUCT_STAT sbuf;
pstring fname, dos_fname;
int len;
time_t c_time;
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 */
if (!params)
ZERO_STRUCT(sbuf);
if (tran_call == TRANSACT2_QFILEINFO) {
- if (total_params < 4)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
fsp = file_fsp(params,0);
info_level = SVAL(params,2);
NTSTATUS status = NT_STATUS_OK;
/* qpathinfo */
- if (total_params < 6)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 6) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
info_level = SVAL(params,0);
file_size = 0;
}
+ /* Pull any EA list from the data portion. */
+ if (info_level == SMB_INFO_QUERY_EAS_FROM_LIST) {
+ uint32 ea_size;
+
+ if (total_data < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ ea_size = IVAL(pdata,0);
+
+ if (total_data > 0 && ea_size != total_data) {
+ DEBUG(4,("call_trans2qfilepathinfo: Rejecting EA request with incorrect \
+total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pdata,0) ));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (!lp_ea_support(SNUM(conn))) {
+ return ERROR_DOS(ERRDOS,ERReasnotsupported);
+ }
+
+ if ((ea_ctx = talloc_init("ea_list")) == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+
+ /* Pull out the list of names. */
+ ea_list = read_ea_name_list(ea_ctx, pdata + 4, ea_size - 4);
+ if (!ea_list) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ }
+
params = SMB_REALLOC(*pparams,2);
- if (params == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if (params == NULL) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
memset((char *)params,'\0',2);
data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
pdata = SMB_REALLOC(*ppdata, data_size);
- if ( pdata == NULL )
- return ERROR_DOS(ERRDOS,ERRnomem);
- *ppdata = pdata;
-
- if (total_data > 0 && IVAL(pdata,0) == total_data) {
- /* uggh, EAs for OS2 */
- DEBUG(4,("Rejecting EA request with total_data=%d\n",total_data));
- return ERROR_DOS(ERRDOS,ERReasnotsupported);
+ if ( pdata == NULL ) {
+ talloc_destroy(ea_ctx);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
}
+ *ppdata = pdata;
memset((char *)pdata,'\0',data_size);
c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
- if (fsp && fsp->pending_modtime) {
- /* the pending modtime overrides the current modtime */
- sbuf.st_mtime = fsp->pending_modtime;
+ if (fsp) {
+ if (fsp->pending_modtime) {
+ /* the pending modtime overrides the current modtime */
+ sbuf.st_mtime = fsp->pending_modtime;
+ }
+ } else {
+ /* Do we have this path open ? */
+ files_struct *fsp1 = file_find_di_first(sbuf.st_dev, sbuf.st_ino);
+ if (fsp1 && fsp1->pending_modtime) {
+ /* the pending modtime overrides the current modtime */
+ sbuf.st_mtime = fsp1->pending_modtime;
+ }
}
if (lp_dos_filetime_resolution(SNUM(conn))) {
break;
case SMB_INFO_QUERY_EAS_FROM_LIST:
+ {
+ size_t total_ea_len = 0;
+ struct ea_list *ea_file_list = NULL;
+
DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
- data_size = 24;
- put_dos_date2(pdata,0,c_time);
- put_dos_date2(pdata,4,sbuf.st_atime);
- put_dos_date2(pdata,8,sbuf.st_mtime);
- SIVAL(pdata,12,(uint32)file_size);
- SIVAL(pdata,16,(uint32)allocation_size);
- SIVAL(pdata,20,mode);
+
+ ea_file_list = get_ea_list_from_file(ea_ctx, conn, fsp, fname, &total_ea_len);
+ ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len);
+
+ if (!ea_list || (total_ea_len > data_size)) {
+ talloc_destroy(ea_ctx);
+ data_size = 4;
+ SIVAL(pdata,0,4); /* EA List Length must be set to 4 if no EA's. */
+ break;
+ }
+
+ data_size = fill_ea_buffer(ea_ctx, pdata, data_size, conn, ea_list);
+ talloc_destroy(ea_ctx);
break;
+ }
case SMB_INFO_QUERY_ALL_EAS:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
+ {
/* We have data_size bytes to put EA's into. */
- data_size = fill_ea_buffer(pdata, data_size, conn, fsp, fname);
+ size_t total_ea_len = 0;
+
+ DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
+
+ ea_ctx = talloc_init("ea_ctx");
+ if (!ea_ctx) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+
+ ea_list = get_ea_list_from_file(ea_ctx, conn, fsp, fname, &total_ea_len);
+ if (!ea_list || (total_ea_len > data_size)) {
+ talloc_destroy(ea_ctx);
+ data_size = 4;
+ SIVAL(pdata,0,4); /* EA List Length must be set to 4 if no EA's. */
+ break;
+ }
+
+ data_size = fill_ea_buffer(ea_ctx, pdata, data_size, conn, ea_list);
+ talloc_destroy(ea_ctx);
break;
+ }
case SMB_FILE_BASIC_INFORMATION:
case SMB_QUERY_FILE_BASIC_INFO:
ZERO_STRUCT(sbuf);
if (tran_call == TRANSACT2_SETFILEINFO) {
- if (total_params < 4)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
fsp = file_fsp(params,0);
info_level = SVAL(params,2);
}
} else {
/* set path info */
- if (total_params < 6)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 6) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
info_level = SVAL(params,0);
srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), -1, STR_TERMINATE, &status, False);
DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d totdata=%d\n",
tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
- /* Realloc the parameter and data sizes */
+ /* Realloc the parameter size */
params = SMB_REALLOC(*pparams,2);
- if(params == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if(params == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
SSVAL(params,0,0);
switch (info_level) {
case SMB_INFO_STANDARD:
{
- if (total_data < 12)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 12) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
/* access time */
tvs.actime = make_unix_date2(pdata+l1_fdateLastAccess);
}
case SMB_INFO_SET_EA:
- status = set_ea(conn, fsp, fname, pdata, total_data);
- if (NT_STATUS_V(status) != NT_STATUS_V(NT_STATUS_OK))
+ {
+ struct ea_list *ea_list = NULL;
+ TALLOC_CTX *ctx = NULL;
+
+ if (total_data < 10) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (IVAL(pdata,0) > total_data) {
+ DEBUG(10,("call_trans2setfilepathinfo: bad total data size (%u) > %u\n",
+ IVAL(pdata,0), (unsigned int)total_data));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ ctx = talloc_init("SMB_INFO_SET_EA");
+ if (!ctx) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+ ea_list = read_ea_list(ctx, pdata + 4, total_data - 4);
+ if (!ea_list) {
+ talloc_destroy(ctx);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ status = set_ea(conn, fsp, fname, ea_list);
+ talloc_destroy(ctx);
+
+ if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
+ }
break;
+ }
+#if 0
+ /* The following 2 info levels are only valid on query, not set. Remove them. JRA. */
/* XXXX um, i don't think this is right.
it's also not in the cifs6.txt spec.
*/
case SMB_INFO_QUERY_EAS_FROM_LIST:
if (total_data < 28)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
tvs.actime = make_unix_date2(pdata+8);
tvs.modtime = make_unix_date2(pdata+12);
/* XXXX nor this. not in cifs6.txt, either. */
case SMB_INFO_QUERY_ALL_EAS:
if (total_data < 28)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
tvs.actime = make_unix_date2(pdata+8);
tvs.modtime = make_unix_date2(pdata+12);
size = IVAL(pdata,16);
dosmode = IVAL(pdata,24);
break;
+#endif
case SMB_SET_FILE_BASIC_INFO:
case SMB_FILE_BASIC_INFORMATION:
time_t write_time;
time_t changed_time;
- if (total_data < 36)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 36) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
/* Ignore create time at offset pdata. */
tvs.modtime = write_time;
}
/* Prefer a defined time to an undefined one. */
- if (tvs.modtime == (time_t)0 || tvs.modtime == (time_t)-1)
- tvs.modtime = (write_time == (time_t)0 || write_time == (time_t)-1
- ? changed_time : write_time);
+ if (null_mtime(tvs.modtime)) {
+ tvs.modtime = null_mtime(write_time) ? changed_time : write_time;
+ }
/* attributes */
dosmode = IVAL(pdata,32);
int ret = -1;
SMB_BIG_UINT allocation_size;
- if (total_data < 8)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 8) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
allocation_size = (SMB_BIG_UINT)IVAL(pdata,0);
#ifdef LARGE_SMB_OFF_T
case SMB_FILE_END_OF_FILE_INFORMATION:
case SMB_SET_FILE_END_OF_FILE_INFO:
{
- if (total_data < 8)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 8) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
size = IVAL(pdata,0);
#ifdef LARGE_SMB_OFF_T
{
BOOL delete_on_close;
- if (total_data < 1)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 1) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
delete_on_close = (CVAL(pdata,0) ? True : False);
status = set_delete_on_close_internal(fsp, delete_on_close, dosmode);
- if (NT_STATUS_V(status) != NT_STATUS_V(NT_STATUS_OK))
+ 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_V(status) != NT_STATUS_V(NT_STATUS_OK))
+ if (!NT_STATUS_IS_OK(status)) {
return ERROR_NT(status);
+ }
break;
}
{
SMB_BIG_UINT position_information;
- if (total_data < 8)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 8) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
position_information = (SMB_BIG_UINT)IVAL(pdata,0);
#ifdef LARGE_SMB_OFF_T
break;
}
+ /* From tridge Samba4 :
+ * MODE_INFORMATION in setfileinfo (I have no
+ * idea what "mode information" on a file is - it takes a value of 0,
+ * 2, 4 or 6. What could it be?).
+ */
+
+ case SMB_FILE_MODE_INFORMATION:
+ {
+ uint32 mode;
+
+ if (total_data < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ mode = IVAL(pdata,0);
+ if (mode != 0 && mode != 2 && mode != 4 && mode != 6) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ break;
+ }
+
/*
* CIFS UNIX extensions.
*/
{
uint32 raw_unixmode;
- if (total_data < 100)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 100) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
if(IVAL(pdata, 0) != SMB_SIZE_NO_CHANGE_LO &&
IVAL(pdata, 4) != SMB_SIZE_NO_CHANGE_HI) {
if (tran_call == TRANSACT2_SETFILEINFO)
return(ERROR_DOS(ERRDOS,ERRnoaccess));
- if (raw_unixmode == SMB_MODE_NO_CHANGE)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (raw_unixmode == SMB_MODE_NO_CHANGE) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
#if defined(HAVE_MAKEDEV)
dev = makedev(dev_major, dev_minor);
pstring base_name;
char *p;
- if (total_data < 12)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_data < 12) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
overwrite = (CVAL(pdata,0) ? True : False);
root_fid = IVAL(pdata,4);
BOOL valid_def_acls = True;
if (total_data < SMB_POSIX_ACL_HEADER_SIZE) {
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
posix_acl_version = SVAL(pdata,0);
num_file_acls = SVAL(pdata,2);
}
if (posix_acl_version != SMB_POSIX_ACL_VERSION) {
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
if (total_data < SMB_POSIX_ACL_HEADER_SIZE +
(num_file_acls+num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE) {
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
if (valid_file_acls && !set_unix_posix_acl(conn, fsp, fname, num_file_acls,
}
/* get some defaults (no modifications) if any info is zero or -1. */
- if (tvs.actime == (time_t)0 || tvs.actime == (time_t)-1)
+ if (null_mtime(tvs.actime)) {
tvs.actime = sbuf.st_atime;
+ }
- if (tvs.modtime == (time_t)0 || tvs.modtime == (time_t)-1)
+ if (null_mtime(tvs.modtime)) {
tvs.modtime = sbuf.st_mtime;
+ }
DEBUG(6,("actime: %s " , ctime(&tvs.actime)));
DEBUG(6,("modtime: %s ", ctime(&tvs.modtime)));
* Try and set the times, size and mode of this file -
* if they are different from the current values
*/
- if (sbuf.st_mtime != tvs.modtime || sbuf.st_atime != tvs.actime) {
- if(fsp != NULL) {
- /*
- * This was a setfileinfo on an open file.
- * NT does this a lot. We also need to
- * set the time here, as it can be read by
- * FindFirst/FindNext and with the patch for bug #2045
- * in smbd/fileio.c it ensures that this timestamp is
- * kept sticky even after a write. We save the request
- * away and will set it on file close and after a write. JRA.
- */
-
- if (tvs.modtime != (time_t)0 && tvs.modtime != (time_t)-1) {
- DEBUG(10,("call_trans2setfilepathinfo: setting pending modtime to %s\n", ctime(&tvs.modtime) ));
- fsp->pending_modtime = tvs.modtime;
- }
-
- DEBUG(10,("call_trans2setfilepathinfo: setting utimes to modified values.\n"));
-
- if(file_utime(conn, fname, &tvs)!=0) {
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
- }
- }
/* check the mode isn't different, before changing it */
if ((dosmode != 0) && (dosmode != dos_mode(conn, fname, &sbuf))) {
}
}
+ /* Now the size. */
if (size != get_file_size(sbuf)) {
int ret;
return (UNIXERROR(ERRHRD,ERRdiskfull));
}
+ /*
+ * Finally the times.
+ */
+ if (sbuf.st_mtime != tvs.modtime || sbuf.st_atime != tvs.actime) {
+ if(fsp != NULL) {
+ /*
+ * This was a setfileinfo on an open file.
+ * NT does this a lot. We also need to
+ * set the time here, as it can be read by
+ * FindFirst/FindNext and with the patch for bug #2045
+ * in smbd/fileio.c it ensures that this timestamp is
+ * kept sticky even after a write. We save the request
+ * away and will set it on file close and after a write. JRA.
+ */
+
+ if (tvs.modtime != (time_t)0 && tvs.modtime != (time_t)-1) {
+ DEBUG(10,("call_trans2setfilepathinfo: setting pending modtime to %s\n", ctime(&tvs.modtime) ));
+ fsp_set_pending_modtime(fsp, tvs.modtime);
+ }
+
+ }
+ DEBUG(10,("call_trans2setfilepathinfo: setting utimes to modified values.\n"));
+
+ if(file_utime(conn, fname, &tvs)!=0) {
+ return(UNIXERROR(ERRDOS,ERRnoaccess));
+ }
+ }
+
SSVAL(params,0,0);
send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0);
unsigned int max_data_bytes)
{
char *params = *pparams;
+ char *pdata = *ppdata;
pstring directory;
int ret = -1;
SMB_STRUCT_STAT sbuf;
BOOL bad_path = False;
NTSTATUS status = NT_STATUS_OK;
+ TALLOC_CTX *ctx = NULL;
+ struct ea_list *ea_list = NULL;
if (!CAN_WRITE(conn))
return ERROR_DOS(ERRSRV,ERRaccess);
- if (total_params < 4)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
srvstr_get_path(inbuf, directory, ¶ms[4], sizeof(directory), -1, STR_TERMINATE, &status, False);
if (!NT_STATUS_IS_OK(status)) {
if (bad_path) {
return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
}
- if (check_name(directory,conn))
+
+ /* Any data in this call is an EA list. */
+ if (total_data && !lp_ea_support(SNUM(conn))) {
+ return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
+ }
+
+ if (total_data) {
+ if (total_data < 10) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ if (IVAL(pdata,0) > total_data) {
+ DEBUG(10,("call_trans2mkdir: bad total data size (%u) > %u\n",
+ IVAL(pdata,0), (unsigned int)total_data));
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+
+ ctx = talloc_init("TRANS2_MKDIR_SET_EA");
+ if (!ctx) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+ ea_list = read_ea_list(ctx, pdata + 4, total_data - 4);
+ if (!ea_list) {
+ talloc_destroy(ctx);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+ }
+
+ if (check_name(directory,conn)) {
ret = vfs_MkDir(conn,directory,unix_mode(conn,aDIR,directory,True));
+ }
if(ret < 0) {
+ talloc_destroy(ctx);
DEBUG(5,("call_trans2mkdir error (%s)\n", strerror(errno)));
return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
}
+ /* Try and set any given EA. */
+ if (total_data) {
+ status = set_ea(conn, NULL, directory, ea_list);
+ talloc_destroy(ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ERROR_NT(status);
+ }
+ }
+
/* Realloc the parameter and data sizes */
params = SMB_REALLOC(*pparams,2);
- if(params == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if(params == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
SSVAL(params,0,0);
char *params = *pparams;
uint16 info_level;
- if (total_params < 6)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 6) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
info_level = SVAL(params,4);
DEBUG(3,("call_trans2findnotifyfirst - info_level %d\n", info_level));
/* Realloc the parameter and data sizes */
params = SMB_REALLOC(*pparams,6);
- if(params == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if(params == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
SSVAL(params,0,fnf_handle);
/* Realloc the parameter and data sizes */
params = SMB_REALLOC(*pparams,4);
- if(params == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if(params == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*pparams = params;
SSVAL(params,0,0); /* No changes */
DEBUG(10,("call_trans2getdfsreferral\n"));
- if (total_params < 2)
- return(ERROR_DOS(ERRDOS,ERRinvalidparam));
+ if (total_params < 2) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
max_referral_level = SVAL(params,0);
if ((SVAL(inbuf,(smb_setup+4)) == LMCAT_SPL) &&
(SVAL(inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
pdata = SMB_REALLOC(*ppdata, 32);
- if(pdata == NULL)
- return ERROR_DOS(ERRDOS,ERRnomem);
+ if(pdata == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
*ppdata = pdata;
/* NOTE - THIS IS ASCII ONLY AT THE MOMENT - NOT SURE IF OS/2
DEBUG(2,("Invalid smb_sucnt in trans2 call(%u)\n",suwcnt));
DEBUG(2,("Transaction is %d\n",tran_call));
END_PROFILE(SMBtrans2);
- ERROR_DOS(ERRDOS,ERRinvalidparam);
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
}
}
SAFE_FREE(params);
SAFE_FREE(data);
END_PROFILE(SMBtrans2);
- return ERROR_DOS(ERRDOS,ERRnomem);
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
}
/* Copy the param and data bytes sent with this request into