if(params_to_send == 0 && data_to_send == 0) {
reply_outbuf(req, 10, 0);
show_msg((char *)req->outbuf);
+ if (!srv_send_smb(smbd_server_fd(),
+ (char *)req->outbuf,
+ true, req->seqnum+1,
+ IS_CONN_ENCRYPTED(conn),
+ &req->pcd)) {
+ exit_server_cleanly("send_trans2_replies: srv_send_smb failed.");
+ }
+ TALLOC_FREE(req->outbuf);
return;
}
req->flags2 & FLAGS2_DFS_PATHNAMES,
fname,
&smb_fname,
- &fname);
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
reply_botherror(req,
goto out;
}
- if (!map_open_params_to_ntcreate(fname, deny_mode, open_ofun,
+ if (!map_open_params_to_ntcreate(smb_fname->base_name, deny_mode,
+ open_ofun,
&access_mask,
&share_mode,
&create_disposition,
}
size = get_file_size_stat(&smb_fname->st);
- fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
+ fattr = dos_mode(conn, smb_fname);
mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
inode = smb_fname->st.st_ex_ino;
if (fattr & aDIR) {
enum perm_type { PERM_NEW_FILE, PERM_NEW_DIR, PERM_EXISTING_FILE, PERM_EXISTING_DIR};
static NTSTATUS unix_perms_from_wire( connection_struct *conn,
- SMB_STRUCT_STAT *psbuf,
+ const SMB_STRUCT_STAT *psbuf,
uint32 perms,
enum perm_type ptype,
mode_t *ret_perms)
if (got_match) {
bool isdots = (ISDOT(dname) || ISDOTDOT(dname));
+ struct smb_filename *smb_fname = NULL;
+ NTSTATUS status;
if (dont_descend && !isdots) {
TALLOC_FREE(fname);
return False;
}
+ /* A dirent from dptr_ReadDirName isn't a stream. */
+ status = create_synthetic_smb_fname(ctx, pathreal,
+ NULL, &sbuf,
+ &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(fname);
+ return false;
+ }
+
if (INFO_LEVEL_IS_UNIX(info_level)) {
- if (vfs_lstat_smb_fname(conn, pathreal,
- &sbuf) != 0) {
- DEBUG(5,("get_lanman2_dir_entry:Couldn't lstat [%s] (%s)\n",
- pathreal,strerror(errno)));
+ if (SMB_VFS_LSTAT(conn, smb_fname) != 0) {
+ DEBUG(5,("get_lanman2_dir_entry: "
+ "Couldn't lstat [%s] (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ TALLOC_FREE(smb_fname);
TALLOC_FREE(pathreal);
TALLOC_FREE(fname);
continue;
}
- } else if (!VALID_STAT(sbuf) &&
- vfs_stat_smb_fname(conn, pathreal,
- &sbuf) != 0) {
+ } else if (!VALID_STAT(smb_fname->st) &&
+ SMB_VFS_STAT(conn, smb_fname) != 0) {
/* Needed to show the msdfs symlinks as
* directories */
- ms_dfs_link = check_msdfs_link(conn, pathreal, &sbuf);
+ ms_dfs_link =
+ check_msdfs_link(conn,
+ smb_fname->base_name,
+ &smb_fname->st);
if (!ms_dfs_link) {
- DEBUG(5,("get_lanman2_dir_entry:Couldn't stat [%s] (%s)\n",
- pathreal,strerror(errno)));
+ DEBUG(5,("get_lanman2_dir_entry: "
+ "Couldn't stat [%s] (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ TALLOC_FREE(smb_fname);
TALLOC_FREE(pathreal);
TALLOC_FREE(fname);
continue;
}
if (ms_dfs_link) {
- mode = dos_mode_msdfs(conn,pathreal,&sbuf);
+ mode = dos_mode_msdfs(conn, smb_fname);
} else {
- mode = dos_mode(conn,pathreal,&sbuf);
+ mode = dos_mode(conn, smb_fname);
}
if (!dir_check_ftype(conn,mode,dirtype)) {
DEBUG(5,("get_lanman2_dir_entry: [%s] attribs didn't match %x\n",fname,dirtype));
+ TALLOC_FREE(smb_fname);
TALLOC_FREE(pathreal);
TALLOC_FREE(fname);
continue;
}
if (!(mode & aDIR)) {
- file_size = get_file_size_stat(&sbuf);
+ file_size = get_file_size_stat(&smb_fname->st);
}
- allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,NULL,&sbuf);
-
- mdate_ts = sbuf.st_ex_mtime;
- adate_ts = sbuf.st_ex_atime;
- create_date_ts = sbuf.st_ex_btime;
+ allocation_size =
+ SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
if (ask_sharemode) {
struct timespec write_time_ts;
struct file_id fileid;
- fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+ ZERO_STRUCT(write_time_ts);
+ fileid = vfs_file_id_from_sbuf(conn,
+ &smb_fname->st);
get_file_infos(fileid, NULL, &write_time_ts);
if (!null_timespec(write_time_ts)) {
- mdate_ts = write_time_ts;
+ update_stat_ex_mtime(&smb_fname->st,
+ write_time_ts);
}
}
+ mdate_ts = smb_fname->st.st_ex_mtime;
+ adate_ts = smb_fname->st.st_ex_atime;
+ create_date_ts = smb_fname->st.st_ex_btime;
+
if (lp_dos_filetime_resolution(SNUM(conn))) {
dos_filetime_timespec(&create_date_ts);
dos_filetime_timespec(&mdate_ts);
adate = convert_timespec_to_time_t(adate_ts);
DEBUG(5,("get_lanman2_dir_entry: found %s fname=%s\n",
- pathreal,fname));
+ smb_fname_str_dbg(smb_fname), fname));
found = True;
dptr_DirCacheAdd(conn->dirptr, dname, curr_dirpos);
+ sbuf = smb_fname->st;
+
+ TALLOC_FREE(smb_fname);
}
if (!found)
uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 18;
if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
- reply_unixerror(req, ERRHRD, ERRgeneral);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 24;
if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
- reply_unixerror(req, ERRHRD, ERRgeneral);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
block_size = lp_block_size(snum);
uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
data_len = 32;
if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
- reply_unixerror(req, ERRHRD, ERRgeneral);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
block_size = lp_block_size(snum);
return;
}
-/****************************************************************************
- Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
- file name or file id).
-****************************************************************************/
-
-static void call_trans2qfilepathinfo(connection_struct *conn,
- struct smb_request *req,
- unsigned int tran_call,
- char **pparams, int total_params,
- char **ppdata, int total_data,
- unsigned int max_data_bytes)
+static NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
+ TALLOC_CTX *mem_ctx,
+ uint16_t info_level,
+ files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ bool delete_pending,
+ struct timespec write_time_ts,
+ bool ms_dfs_link,
+ struct ea_list *ea_list,
+ int lock_data_count,
+ char *lock_data,
+ uint16_t flags2,
+ unsigned int max_data_bytes,
+ char **ppdata,
+ unsigned int *pdata_size)
{
- char *params = *pparams;
char *pdata = *ppdata;
char *dstart, *dend;
- uint16 info_level;
- int mode=0;
- int nlink;
- SMB_OFF_T file_size=0;
- uint64_t allocation_size=0;
- unsigned int data_size = 0;
- unsigned int param_size = 2;
+ unsigned int data_size;
+ struct timespec create_time_ts, mtime_ts, atime_ts;
+ time_t create_time, mtime, atime;
SMB_STRUCT_STAT sbuf;
- char *dos_fname = NULL;
- char *fname = NULL;
- struct smb_filename *smb_fname = NULL;
- char *fullpathname;
- char *base_name;
char *p;
- SMB_OFF_T pos = 0;
- bool delete_pending = False;
- int len;
- time_t create_time, mtime, atime;
- struct timespec create_time_ts, mtime_ts, atime_ts;
- struct timespec write_time_ts;
- files_struct *fsp = NULL;
- struct file_id fileid;
- struct ea_list *ea_list = NULL;
- char *lock_data = NULL;
- bool ms_dfs_link = false;
- TALLOC_CTX *ctx = talloc_tos();
- NTSTATUS status = NT_STATUS_OK;
+ char *fname;
+ char *base_name;
+ char *dos_fname;
+ int mode;
+ int nlink;
+ NTSTATUS status;
+ uint64_t file_size = 0;
+ uint64_t pos = 0;
+ uint64_t allocation_size = 0;
- if (!params) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
+ sbuf = smb_fname->st;
+
+ if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+ return NT_STATUS_INVALID_LEVEL;
}
- ZERO_STRUCT(write_time_ts);
+ status = get_full_smb_filename(mem_ctx, smb_fname, &fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if (tran_call == TRANSACT2_QFILEINFO) {
- if (total_params < 4) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
+ DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n",
+ fname, fsp ? fsp->fnum : -1, info_level, max_data_bytes));
- if (IS_IPC(conn)) {
- call_trans2qpipeinfo(conn, req, tran_call,
- pparams, total_params,
- ppdata, total_data,
- max_data_bytes);
- return;
- }
+ if (ms_dfs_link) {
+ mode = dos_mode_msdfs(conn, smb_fname);
+ } else {
+ mode = dos_mode(conn, smb_fname);
+ }
+ if (!mode)
+ mode = FILE_ATTRIBUTE_NORMAL;
- fsp = file_fsp(req, SVAL(params,0));
- info_level = SVAL(params,2);
+ nlink = sbuf.st_ex_nlink;
- DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
+ if (nlink && (mode&aDIR)) {
+ nlink = 1;
+ }
- if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
- }
+ if ((nlink > 0) && delete_pending) {
+ nlink -= 1;
+ }
- /* Initial check for valid fsp ptr. */
- if (!check_fsp_open(conn, req, fsp)) {
- return;
- }
+ data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
+ *ppdata = (char *)SMB_REALLOC(*ppdata, data_size);
+ if (*ppdata == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ pdata = *ppdata;
+ dstart = pdata;
+ dend = dstart + data_size - 1;
- fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
- if (!fname) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
+ if (!null_timespec(write_time_ts) && !INFO_LEVEL_IS_UNIX(info_level)) {
+ update_stat_ex_mtime(&sbuf, write_time_ts);
+ }
+
+ create_time_ts = sbuf.st_ex_btime;
+ mtime_ts = sbuf.st_ex_mtime;
+ atime_ts = sbuf.st_ex_atime;
+
+ if (lp_dos_filetime_resolution(SNUM(conn))) {
+ dos_filetime_timespec(&create_time_ts);
+ dos_filetime_timespec(&mtime_ts);
+ dos_filetime_timespec(&atime_ts);
+ }
+
+ create_time = convert_timespec_to_time_t(create_time_ts);
+ mtime = convert_timespec_to_time_t(mtime_ts);
+ atime = convert_timespec_to_time_t(atime_ts);
+
+ p = strrchr_m(smb_fname->base_name,'/');
+ if (!p)
+ base_name = smb_fname->base_name;
+ else
+ base_name = p+1;
+
+ /* NT expects the name to be in an exact form of the *full*
+ filename. See the trans2 torture test */
+ if (ISDOT(base_name)) {
+ dos_fname = talloc_strdup(mem_ctx, "\\");
+ if (!dos_fname) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ } else {
+ dos_fname = talloc_asprintf(mem_ctx,
+ "\\%s",
+ fname);
+ if (!dos_fname) {
+ return NT_STATUS_NO_MEMORY;
}
+ string_replace(dos_fname, '/', '\\');
+ }
- status = create_synthetic_smb_fname_split(talloc_tos(), fname,
- NULL, &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
+ allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &sbuf);
+
+ if (!fsp) {
+ /* Do we have this path open ? */
+ files_struct *fsp1;
+ struct file_id fileid = vfs_file_id_from_sbuf(conn, &sbuf);
+ fsp1 = file_find_di_first(fileid);
+ if (fsp1 && fsp1->initial_allocation_size) {
+ allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, &sbuf);
}
+ }
- if(fsp->fake_file_handle) {
- /*
- * This is actually for the QUOTA_FAKE_FILE --metze
- */
+ if (!(mode & aDIR)) {
+ file_size = get_file_size_stat(&sbuf);
+ }
- /* We know this name is ok, it's already passed the checks. */
+ if (fsp && fsp->fh) {
+ pos = fsp->fh->position_information;
+ }
- } 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
- * to do this call. JRA.
- */
+ switch (info_level) {
+ case SMB_INFO_STANDARD:
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_STANDARD\n"));
+ data_size = 22;
+ srv_put_dos_date2(pdata,l1_fdateCreation,create_time);
+ srv_put_dos_date2(pdata,l1_fdateLastAccess,atime);
+ srv_put_dos_date2(pdata,l1_fdateLastWrite,mtime); /* write time */
+ SIVAL(pdata,l1_cbFile,(uint32)file_size);
+ SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
+ SSVAL(pdata,l1_attrFile,mode);
+ break;
- if (INFO_LEVEL_IS_UNIX(info_level)) {
- /* Always do lstat for UNIX calls. */
- if (SMB_VFS_LSTAT(conn, smb_fname)) {
- DEBUG(3,("call_trans2qfilepathinfo: "
- "SMB_VFS_LSTAT of %s failed "
- "(%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_unixerror(req,ERRDOS,ERRbadpath);
- return;
- }
- } else if (SMB_VFS_STAT(conn, smb_fname)) {
- DEBUG(3,("call_trans2qfilepathinfo: "
- "SMB_VFS_STAT of %s failed (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_unixerror(req, ERRDOS, ERRbadpath);
- return;
- }
+ case SMB_INFO_QUERY_EA_SIZE:
+ {
+ unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
+ data_size = 26;
+ srv_put_dos_date2(pdata,0,create_time);
+ srv_put_dos_date2(pdata,4,atime);
+ srv_put_dos_date2(pdata,8,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;
+ }
- fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
- get_file_infos(fileid, &delete_pending, &write_time_ts);
- } else {
- /*
- * Original code - this is an open file.
- */
- if (!check_fsp(conn, req, fsp)) {
- return;
+ case SMB_INFO_IS_NAME_VALID:
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_IS_NAME_VALID\n"));
+ if (fsp) {
+ /* os/2 needs this ? really ?*/
+ return NT_STATUS_DOS(ERRDOS, ERRbadfunc);
}
+ /* This is only reached for qpathinfo */
+ data_size = 0;
+ break;
- if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
- DEBUG(3, ("fstat of fnum %d failed (%s)\n",
- fsp->fnum, strerror(errno)));
- reply_unixerror(req, ERRDOS, ERRbadfid);
- return;
- }
- pos = fsp->fh->position_information;
- fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
- get_file_infos(fileid, &delete_pending, &write_time_ts);
- }
+ case SMB_INFO_QUERY_EAS_FROM_LIST:
+ {
+ size_t total_ea_len = 0;
+ struct ea_list *ea_file_list = NULL;
- } else {
- /* qpathinfo */
- if (total_params < 7) {
- reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
- info_level = SVAL(params,0);
+ ea_file_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
+ ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len);
- DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
+ if (!ea_list || (total_ea_len > data_size)) {
+ data_size = 4;
+ SIVAL(pdata,0,4); /* EA List Length must be set to 4 if no EA's. */
+ break;
+ }
- if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
- }
-
- srvstr_get_path(ctx, params, req->flags2, &fname, ¶ms[6],
- total_params - 6,
- STR_TERMINATE, &status);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
- status = filename_convert(ctx,
- conn,
- req->flags2 & FLAGS2_DFS_PATHNAMES,
- fname,
- &smb_fname,
- &fname);
- if (!NT_STATUS_IS_OK(status)) {
- if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
- reply_botherror(req,
- NT_STATUS_PATH_NOT_COVERED,
- ERRSRV, ERRbadpath);
- return;
- }
- reply_nterror(req, status);
- return;
- }
-
- /* If this is a stream, check if there is a delete_pending. */
- if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
- && is_ntfs_stream_smb_fname(smb_fname)) {
- struct smb_filename *smb_fname_base = NULL;
-
- /* Create an smb_filename with stream_name == NULL. */
- status =
- create_synthetic_smb_fname(talloc_tos(),
- smb_fname->base_name,
- NULL, NULL,
- &smb_fname_base);
- if (!NT_STATUS_IS_OK(status)) {
- reply_nterror(req, status);
- return;
- }
-
- if (INFO_LEVEL_IS_UNIX(info_level)) {
- /* Always do lstat for UNIX calls. */
- if (SMB_VFS_LSTAT(conn, smb_fname_base) != 0) {
- DEBUG(3,("call_trans2qfilepathinfo: "
- "SMB_VFS_LSTAT of %s failed "
- "(%s)\n",
- smb_fname_str_dbg(smb_fname_base),
- strerror(errno)));
- TALLOC_FREE(smb_fname_base);
- reply_unixerror(req,ERRDOS,ERRbadpath);
- return;
- }
- } else {
- if (SMB_VFS_STAT(conn, smb_fname_base) != 0) {
- DEBUG(3,("call_trans2qfilepathinfo: "
- "fileinfo of %s failed "
- "(%s)\n",
- smb_fname_str_dbg(smb_fname_base),
- strerror(errno)));
- TALLOC_FREE(smb_fname_base);
- reply_unixerror(req,ERRDOS,ERRbadpath);
- return;
- }
- }
-
- fileid = vfs_file_id_from_sbuf(conn,
- &smb_fname_base->st);
- TALLOC_FREE(smb_fname_base);
- get_file_infos(fileid, &delete_pending, NULL);
- if (delete_pending) {
- reply_nterror(req, NT_STATUS_DELETE_PENDING);
- return;
- }
- }
-
- if (INFO_LEVEL_IS_UNIX(info_level)) {
- /* Always do lstat for UNIX calls. */
- if (SMB_VFS_LSTAT(conn, smb_fname)) {
- DEBUG(3,("call_trans2qfilepathinfo: "
- "SMB_VFS_LSTAT of %s failed (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_unixerror(req, ERRDOS, ERRbadpath);
- return;
- }
-
- } else if (!VALID_STAT(smb_fname->st) &&
- SMB_VFS_STAT(conn, smb_fname) &&
- (info_level != SMB_INFO_IS_NAME_VALID)) {
- ms_dfs_link = check_msdfs_link(conn, fname,
- &smb_fname->st);
-
- if (!ms_dfs_link) {
- DEBUG(3,("call_trans2qfilepathinfo: "
- "SMB_VFS_STAT of %s failed (%s)\n",
- smb_fname_str_dbg(smb_fname),
- strerror(errno)));
- reply_unixerror(req, ERRDOS, ERRbadpath);
- return;
- }
- }
-
- fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
- get_file_infos(fileid, &delete_pending, &write_time_ts);
- if (delete_pending) {
- reply_nterror(req, NT_STATUS_DELETE_PENDING);
- return;
- }
- }
-
- /* Set sbuf for use below. */
- sbuf = smb_fname->st;
-
- if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
- }
-
- DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d total_data=%d\n",
- fname,fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
-
- p = strrchr_m(fname,'/');
- if (!p)
- base_name = fname;
- else
- base_name = p+1;
-
- if (ms_dfs_link) {
- mode = dos_mode_msdfs(conn,fname,&sbuf);
- } else {
- mode = dos_mode(conn,fname,&sbuf);
- }
- if (!mode)
- mode = FILE_ATTRIBUTE_NORMAL;
-
- nlink = sbuf.st_ex_nlink;
-
- if (nlink && (mode&aDIR)) {
- nlink = 1;
- }
-
- if ((nlink > 0) && delete_pending) {
- nlink -= 1;
- }
-
- fullpathname = fname;
- if (!(mode & aDIR))
- file_size = get_file_size_stat(&sbuf);
-
- /* Pull out any data sent here before we realloc. */
- switch (info_level) {
- case SMB_INFO_QUERY_EAS_FROM_LIST:
- {
- /* Pull any EA list from the data portion. */
- uint32 ea_size;
-
- if (total_data < 4) {
- reply_nterror(
- req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
- 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) ));
- reply_nterror(
- req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
-
- if (!lp_ea_support(SNUM(conn))) {
- reply_doserror(req, ERRDOS,
- ERReasnotsupported);
- return;
- }
-
- /* Pull out the list of names. */
- ea_list = read_ea_name_list(ctx, pdata + 4, ea_size - 4);
- if (!ea_list) {
- reply_nterror(
- req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
- break;
- }
-
- case SMB_QUERY_POSIX_LOCK:
- {
- if (fsp == NULL || fsp->fh->fd == -1) {
- reply_nterror(req, NT_STATUS_INVALID_HANDLE);
- return;
- }
-
- if (total_data != POSIX_LOCK_DATA_SIZE) {
- reply_nterror(
- req, NT_STATUS_INVALID_PARAMETER);
- return;
- }
-
- /* Copy the lock range data. */
- lock_data = (char *)TALLOC_MEMDUP(
- ctx, pdata, total_data);
- if (!lock_data) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
- }
- default:
- break;
- }
-
- *pparams = (char *)SMB_REALLOC(*pparams,2);
- if (*pparams == NULL) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
- params = *pparams;
- SSVAL(params,0,0);
- data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
- *ppdata = (char *)SMB_REALLOC(*ppdata, data_size);
- if (*ppdata == NULL ) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
- pdata = *ppdata;
- dstart = pdata;
- dend = dstart + data_size - 1;
-
- create_time_ts = sbuf.st_ex_btime;
- mtime_ts = sbuf.st_ex_mtime;
- atime_ts = sbuf.st_ex_atime;
-
- allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf);
-
- if (!fsp) {
- /* Do we have this path open ? */
- files_struct *fsp1;
- fileid = vfs_file_id_from_sbuf(conn, &sbuf);
- fsp1 = file_find_di_first(fileid);
- if (fsp1 && fsp1->initial_allocation_size) {
- allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, fsp1, &sbuf);
- }
- }
-
- if (!null_timespec(write_time_ts) && !INFO_LEVEL_IS_UNIX(info_level)) {
- mtime_ts = write_time_ts;
- }
-
- if (lp_dos_filetime_resolution(SNUM(conn))) {
- dos_filetime_timespec(&create_time_ts);
- dos_filetime_timespec(&mtime_ts);
- dos_filetime_timespec(&atime_ts);
- }
-
- create_time = convert_timespec_to_time_t(create_time_ts);
- mtime = convert_timespec_to_time_t(mtime_ts);
- atime = convert_timespec_to_time_t(atime_ts);
-
- /* NT expects the name to be in an exact form of the *full*
- filename. See the trans2 torture test */
- if (ISDOT(base_name)) {
- dos_fname = talloc_strdup(ctx, "\\");
- if (!dos_fname) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
- } else {
- dos_fname = talloc_asprintf(ctx,
- "\\%s",
- fname);
- if (!dos_fname) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
- return;
- }
- string_replace(dos_fname, '/', '\\');
- }
-
- switch (info_level) {
- case SMB_INFO_STANDARD:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_STANDARD\n"));
- data_size = 22;
- srv_put_dos_date2(pdata,l1_fdateCreation,create_time);
- srv_put_dos_date2(pdata,l1_fdateLastAccess,atime);
- srv_put_dos_date2(pdata,l1_fdateLastWrite,mtime); /* write time */
- SIVAL(pdata,l1_cbFile,(uint32)file_size);
- SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
- SSVAL(pdata,l1_attrFile,mode);
- break;
-
- case SMB_INFO_QUERY_EA_SIZE:
- {
- unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
- DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
- data_size = 26;
- srv_put_dos_date2(pdata,0,create_time);
- srv_put_dos_date2(pdata,4,atime);
- srv_put_dos_date2(pdata,8,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;
- }
-
- case SMB_INFO_IS_NAME_VALID:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_IS_NAME_VALID\n"));
- if (tran_call == TRANSACT2_QFILEINFO) {
- /* os/2 needs this ? really ?*/
- reply_doserror(req, ERRDOS, ERRbadfunc);
- return;
- }
- data_size = 0;
- param_size = 0;
- 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"));
-
- ea_file_list = get_ea_list_from_file(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)) {
- 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(ctx, pdata, data_size, conn, ea_list);
- break;
+ data_size = fill_ea_buffer(mem_ctx, pdata, data_size, conn, ea_list);
+ break;
}
case SMB_INFO_QUERY_ALL_EAS:
/* We have data_size bytes to put EA's into. */
size_t total_ea_len = 0;
- DEBUG(10,("call_trans2qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
- ea_list = get_ea_list_from_file(ctx, conn, fsp, fname, &total_ea_len);
+ ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
if (!ea_list || (total_ea_len > data_size)) {
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(ctx, pdata, data_size, conn, ea_list);
+ data_size = fill_ea_buffer(mem_ctx, pdata, data_size, conn, ea_list);
break;
}
case SMB_QUERY_FILE_BASIC_INFO:
if (info_level == SMB_QUERY_FILE_BASIC_INFO) {
- DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_BASIC_INFO\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_BASIC_INFO\n"));
data_size = 36; /* w95 returns 40 bytes not 36 - why ?. */
} else {
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_BASIC_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_BASIC_INFORMATION\n"));
data_size = 40;
SIVAL(pdata,36,0);
}
case SMB_FILE_STANDARD_INFORMATION:
case SMB_QUERY_FILE_STANDARD_INFO:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_STANDARD_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_STANDARD_INFORMATION\n"));
data_size = 24;
SOFF_T(pdata,0,allocation_size);
SOFF_T(pdata,8,file_size);
case SMB_QUERY_FILE_EA_INFO:
{
unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
data_size = 4;
SIVAL(pdata,0,ea_size);
break;
case SMB_QUERY_FILE_ALT_NAME_INFO:
case SMB_FILE_ALTERNATE_NAME_INFORMATION:
{
+ int len;
char mangled_name[13];
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
if (!name_to_8_3(base_name,mangled_name,
True,conn->params)) {
- reply_nterror(
- req,
- NT_STATUS_NO_MEMORY);
+ return NT_STATUS_NO_MEMORY;
}
- len = srvstr_push(dstart, req->flags2,
+ len = srvstr_push(dstart, flags2,
pdata+4, mangled_name,
PTR_DIFF(dend, pdata+4),
STR_UNICODE);
}
case SMB_QUERY_FILE_NAME_INFO:
+ {
+ int len;
/*
this must be *exactly* right for ACLs on mapped drives to work
*/
- len = srvstr_push(dstart, req->flags2,
+ len = srvstr_push(dstart, flags2,
pdata+4, dos_fname,
PTR_DIFF(dend, pdata+4),
STR_UNICODE);
- DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
data_size = 4 + len;
SIVAL(pdata,0,len);
break;
+ }
case SMB_FILE_ALLOCATION_INFORMATION:
case SMB_QUERY_FILE_ALLOCATION_INFO:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALLOCATION_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALLOCATION_INFORMATION\n"));
data_size = 8;
SOFF_T(pdata,0,allocation_size);
break;
case SMB_FILE_END_OF_FILE_INFORMATION:
case SMB_QUERY_FILE_END_OF_FILEINFO:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_END_OF_FILE_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_END_OF_FILE_INFORMATION\n"));
data_size = 8;
SOFF_T(pdata,0,file_size);
break;
case SMB_QUERY_FILE_ALL_INFO:
case SMB_FILE_ALL_INFORMATION:
{
+ int len;
unsigned int ea_size = estimate_ea_size(conn, fsp, fname);
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
put_long_date_timespec(pdata,create_time_ts);
put_long_date_timespec(pdata+8,atime_ts);
put_long_date_timespec(pdata+16,mtime_ts); /* write time */
pdata += 24;
SIVAL(pdata,0,ea_size);
pdata += 4; /* EA info */
- len = srvstr_push(dstart, req->flags2,
+ len = srvstr_push(dstart, flags2,
pdata+4, dos_fname,
PTR_DIFF(dend, pdata+4),
STR_UNICODE);
I think this causes us to fail the IFSKIT
BasicFileInformationTest. -tpot */
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_INTERNAL_INFORMATION\n"));
SIVAL(pdata,0,sbuf.st_ex_ino); /* FileIndexLow */
SIVAL(pdata,4,sbuf.st_ex_dev); /* FileIndexHigh */
data_size = 8;
break;
case SMB_FILE_ACCESS_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ACCESS_INFORMATION\n"));
if (fsp) {
SIVAL(pdata,0,fsp->access_mask);
} else {
{
size_t byte_len;
byte_len = dos_PutUniCode(pdata+4,dos_fname,(size_t)max_data_bytes,False);
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_NAME_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NAME_INFORMATION\n"));
SIVAL(pdata,0,byte_len);
data_size = 4 + byte_len;
break;
}
case SMB_FILE_DISPOSITION_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_DISPOSITION_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_DISPOSITION_INFORMATION\n"));
data_size = 1;
SCVAL(pdata,0,delete_pending);
break;
case SMB_FILE_POSITION_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_POSITION_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_POSITION_INFORMATION\n"));
data_size = 8;
SOFF_T(pdata,0,pos);
break;
case SMB_FILE_MODE_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_MODE_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_MODE_INFORMATION\n"));
SIVAL(pdata,0,mode);
data_size = 4;
break;
case SMB_FILE_ALIGNMENT_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ALIGNMENT_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALIGNMENT_INFORMATION\n"));
SIVAL(pdata,0,0); /* No alignment needed. */
data_size = 4;
break;
unsigned int num_streams;
struct stream_struct *streams;
- DEBUG(10,("call_trans2qfilepathinfo: "
+ DEBUG(10,("smbd_do_qfilepathinfo: "
"SMB_FILE_STREAM_INFORMATION\n"));
status = SMB_VFS_STREAMINFO(
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("could not get stream info: %s\n",
nt_errstr(status)));
- reply_nterror(req, status);
- return;
+ return status;
}
status = marshall_stream_info(num_streams, streams,
if (!NT_STATUS_IS_OK(status)) {
DEBUG(10, ("marshall_stream_info failed: %s\n",
nt_errstr(status)));
- reply_nterror(req, status);
- return;
+ return status;
}
TALLOC_FREE(streams);
}
case SMB_QUERY_COMPRESSION_INFO:
case SMB_FILE_COMPRESSION_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_COMPRESSION_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_COMPRESSION_INFORMATION\n"));
SOFF_T(pdata,0,file_size);
SIVAL(pdata,8,0); /* ??? */
SIVAL(pdata,12,0); /* ??? */
break;
case SMB_FILE_NETWORK_OPEN_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_NETWORK_OPEN_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_NETWORK_OPEN_INFORMATION\n"));
put_long_date_timespec(pdata,create_time_ts);
put_long_date_timespec(pdata+8,atime_ts);
put_long_date_timespec(pdata+16,mtime_ts); /* write time */
break;
case SMB_FILE_ATTRIBUTE_TAG_INFORMATION:
- DEBUG(10,("call_trans2qfilepathinfo: SMB_FILE_ATTRIBUTE_TAG_INFORMATION\n"));
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ATTRIBUTE_TAG_INFORMATION\n"));
SIVAL(pdata,0,mode);
SIVAL(pdata,4,0);
data_size = 8;
{
int i;
- DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
+ DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_BASIC "));
for (i=0; i<100; i++)
DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
pdata = store_file_unix_basic_info2(conn, pdata, fsp, &sbuf);
data_size = PTR_DIFF(pdata,(*ppdata));
- {
- int i;
- DEBUG(4,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
+ {
+ int i;
+ DEBUG(4,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_INFO2 "));
+
+ for (i=0; i<100; i++)
+ DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
+ DEBUG(4,("\n"));
+ }
+
+ break;
+
+ case SMB_QUERY_FILE_UNIX_LINK:
+ {
+ int len;
+ char *buffer = TALLOC_ARRAY(mem_ctx, char, PATH_MAX+1);
+
+ if (!buffer) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
+#ifdef S_ISLNK
+ if(!S_ISLNK(sbuf.st_ex_mode)) {
+ return NT_STATUS_DOS(ERRSRV, ERRbadlink);
+ }
+#else
+ return NT_STATUS_DOS(ERRDOS, ERRbadlink);
+#endif
+ len = SMB_VFS_READLINK(conn,fname,
+ buffer, PATH_MAX);
+ if (len == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+ buffer[len] = 0;
+ len = srvstr_push(dstart, flags2,
+ pdata, buffer,
+ PTR_DIFF(dend, pdata),
+ STR_TERMINATE);
+ pdata += len;
+ data_size = PTR_DIFF(pdata,(*ppdata));
+
+ break;
+ }
+
+#if defined(HAVE_POSIX_ACLS)
+ case SMB_QUERY_POSIX_ACL:
+ {
+ SMB_ACL_T file_acl = NULL;
+ SMB_ACL_T def_acl = NULL;
+ uint16 num_file_acls = 0;
+ uint16 num_def_acls = 0;
+
+ if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
+ file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
+ } else {
+ file_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_ACCESS);
+ }
+
+ if (file_acl == NULL && no_acl_syscall_error(errno)) {
+ DEBUG(5,("smbd_do_qfilepathinfo: ACLs not implemented on filesystem containing %s\n",
+ fname ));
+ return NT_STATUS_NOT_IMPLEMENTED;
+ }
+
+ if (S_ISDIR(sbuf.st_ex_mode)) {
+ if (fsp && fsp->is_directory) {
+ def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fsp->fsp_name, SMB_ACL_TYPE_DEFAULT);
+ } else {
+ def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_DEFAULT);
+ }
+ def_acl = free_empty_sys_acl(conn, def_acl);
+ }
+
+ num_file_acls = count_acl_entries(conn, file_acl);
+ num_def_acls = count_acl_entries(conn, def_acl);
+
+ if ( data_size < (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE) {
+ DEBUG(5,("smbd_do_qfilepathinfo: data_size too small (%u) need %u\n",
+ data_size,
+ (unsigned int)((num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE +
+ SMB_POSIX_ACL_HEADER_SIZE) ));
+ if (file_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
+ }
+ if (def_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
+ }
+ return NT_STATUS_BUFFER_TOO_SMALL;
+ }
+
+ SSVAL(pdata,0,SMB_POSIX_ACL_VERSION);
+ SSVAL(pdata,2,num_file_acls);
+ SSVAL(pdata,4,num_def_acls);
+ if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE, &sbuf, file_acl)) {
+ if (file_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
+ }
+ if (def_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
+ }
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+ if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE + (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE), &sbuf, def_acl)) {
+ if (file_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
+ }
+ if (def_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
+ }
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ if (file_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
+ }
+ if (def_acl) {
+ SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
+ }
+ data_size = (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE;
+ break;
+ }
+#endif
+
+
+ case SMB_QUERY_POSIX_LOCK:
+ {
+ uint64_t count;
+ uint64_t offset;
+ uint32 lock_pid;
+ enum brl_type lock_type;
+
+ if (lock_data_count != POSIX_LOCK_DATA_SIZE) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
+ case POSIX_LOCK_TYPE_READ:
+ lock_type = READ_LOCK;
+ break;
+ case POSIX_LOCK_TYPE_WRITE:
+ lock_type = WRITE_LOCK;
+ break;
+ case POSIX_LOCK_TYPE_UNLOCK:
+ default:
+ /* There's no point in asking for an unlock... */
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
+#if defined(HAVE_LONGLONG)
+ offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
+ ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
+ count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
+ ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
+#else /* HAVE_LONGLONG */
+ offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);
+ count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
+#endif /* HAVE_LONGLONG */
+
+ status = query_lock(fsp,
+ &lock_pid,
+ &count,
+ &offset,
+ &lock_type,
+ POSIX_LOCK);
+
+ if (ERROR_WAS_LOCK_DENIED(status)) {
+ /* Here we need to report who has it locked... */
+ data_size = POSIX_LOCK_DATA_SIZE;
+
+ SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, lock_type);
+ SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0);
+ SIVAL(pdata, POSIX_LOCK_PID_OFFSET, lock_pid);
+#if defined(HAVE_LONGLONG)
+ SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF));
+ SIVAL(pdata, POSIX_LOCK_START_OFFSET + 4, (uint32)((offset >> 32) & 0xFFFFFFFF));
+ SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, (uint32)(count & 0xFFFFFFFF));
+ SIVAL(pdata, POSIX_LOCK_LEN_OFFSET + 4, (uint32)((count >> 32) & 0xFFFFFFFF));
+#else /* HAVE_LONGLONG */
+ SIVAL(pdata, POSIX_LOCK_START_OFFSET, offset);
+ SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, count);
+#endif /* HAVE_LONGLONG */
+
+ } else if (NT_STATUS_IS_OK(status)) {
+ /* For success we just return a copy of what we sent
+ with the lock type set to POSIX_LOCK_TYPE_UNLOCK. */
+ data_size = POSIX_LOCK_DATA_SIZE;
+ memcpy(pdata, lock_data, POSIX_LOCK_DATA_SIZE);
+ SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_UNLOCK);
+ } else {
+ return status;
+ }
+ break;
+ }
+
+ default:
+ return NT_STATUS_INVALID_LEVEL;
+ }
+
+ *pdata_size = data_size;
+ return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
+ file name or file id).
+****************************************************************************/
+
+static void call_trans2qfilepathinfo(connection_struct *conn,
+ struct smb_request *req,
+ unsigned int tran_call,
+ char **pparams, int total_params,
+ char **ppdata, int total_data,
+ unsigned int max_data_bytes)
+{
+ char *params = *pparams;
+ char *pdata = *ppdata;
+ uint16 info_level;
+ unsigned int data_size = 0;
+ unsigned int param_size = 2;
+ char *fname = NULL;
+ struct smb_filename *smb_fname = NULL;
+ bool delete_pending = False;
+ struct timespec write_time_ts;
+ files_struct *fsp = NULL;
+ struct file_id fileid;
+ struct ea_list *ea_list = NULL;
+ int lock_data_count = 0;
+ char *lock_data = NULL;
+ bool ms_dfs_link = false;
+ NTSTATUS status = NT_STATUS_OK;
+
+ if (!params) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+
+ ZERO_STRUCT(write_time_ts);
+
+ if (tran_call == TRANSACT2_QFILEINFO) {
+ if (total_params < 4) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+
+ if (IS_IPC(conn)) {
+ call_trans2qpipeinfo(conn, req, tran_call,
+ pparams, total_params,
+ ppdata, total_data,
+ max_data_bytes);
+ return;
+ }
+
+ fsp = file_fsp(req, SVAL(params,0));
+ info_level = SVAL(params,2);
+
+ DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QFILEINFO: level = %d\n", info_level));
+
+ if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+ reply_nterror(req, NT_STATUS_INVALID_LEVEL);
+ return;
+ }
+
+ /* Initial check for valid fsp ptr. */
+ if (!check_fsp_open(conn, req, fsp)) {
+ return;
+ }
+
+ fname = talloc_strdup(talloc_tos(),fsp->fsp_name);
+ if (!fname) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
+ return;
+ }
+
+ status = create_synthetic_smb_fname_split(talloc_tos(), fname,
+ NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
+ }
- for (i=0; i<100; i++)
- DEBUG(4,("%d=%x, ",i, (*ppdata)[i]));
- DEBUG(4,("\n"));
- }
+ if(fsp->fake_file_handle) {
+ /*
+ * This is actually for the QUOTA_FAKE_FILE --metze
+ */
- break;
+ /* We know this name is ok, it's already passed the checks. */
- case SMB_QUERY_FILE_UNIX_LINK:
- {
- char *buffer = TALLOC_ARRAY(ctx, char, PATH_MAX+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
+ * to do this call. JRA.
+ */
- if (!buffer) {
- reply_nterror(req, NT_STATUS_NO_MEMORY);
+ if (INFO_LEVEL_IS_UNIX(info_level)) {
+ /* Always do lstat for UNIX calls. */
+ if (SMB_VFS_LSTAT(conn, smb_fname)) {
+ DEBUG(3,("call_trans2qfilepathinfo: "
+ "SMB_VFS_LSTAT of %s failed "
+ "(%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
return;
}
+ } else if (SMB_VFS_STAT(conn, smb_fname)) {
+ DEBUG(3,("call_trans2qfilepathinfo: "
+ "SMB_VFS_STAT of %s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
+ return;
+ }
- DEBUG(10,("call_trans2qfilepathinfo: SMB_QUERY_FILE_UNIX_LINK\n"));
-#ifdef S_ISLNK
- if(!S_ISLNK(sbuf.st_ex_mode)) {
- reply_unixerror(req, ERRSRV,
- ERRbadlink);
- return;
- }
-#else
- reply_unixerror(req, ERRDOS, ERRbadlink);
+ fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
+ get_file_infos(fileid, &delete_pending, &write_time_ts);
+ } else {
+ /*
+ * Original code - this is an open file.
+ */
+ if (!check_fsp(conn, req, fsp)) {
return;
-#endif
- len = SMB_VFS_READLINK(conn,fullpathname,
- buffer, PATH_MAX);
- if (len == -1) {
- reply_unixerror(req, ERRDOS,
- ERRnoaccess);
- return;
- }
- buffer[len] = 0;
- len = srvstr_push(dstart, req->flags2,
- pdata, buffer,
- PTR_DIFF(dend, pdata),
- STR_TERMINATE);
- pdata += len;
- data_size = PTR_DIFF(pdata,(*ppdata));
+ }
- break;
+ if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
+ DEBUG(3, ("fstat of fnum %d failed (%s)\n",
+ fsp->fnum, strerror(errno)));
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
+ return;
}
+ fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
+ get_file_infos(fileid, &delete_pending, &write_time_ts);
+ }
-#if defined(HAVE_POSIX_ACLS)
- case SMB_QUERY_POSIX_ACL:
- {
- SMB_ACL_T file_acl = NULL;
- SMB_ACL_T def_acl = NULL;
- uint16 num_file_acls = 0;
- uint16 num_def_acls = 0;
+ } else {
+ /* qpathinfo */
+ if (total_params < 7) {
+ reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
- if (fsp && !fsp->is_directory && (fsp->fh->fd != -1)) {
- file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
- } else {
- file_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_ACCESS);
- }
+ info_level = SVAL(params,0);
- if (file_acl == NULL && no_acl_syscall_error(errno)) {
- DEBUG(5,("call_trans2qfilepathinfo: ACLs not implemented on filesystem containing %s\n",
- fname ));
- reply_nterror(
- req,
- NT_STATUS_NOT_IMPLEMENTED);
- return;
- }
+ DEBUG(3,("call_trans2qfilepathinfo: TRANSACT2_QPATHINFO: level = %d\n", info_level));
- if (S_ISDIR(sbuf.st_ex_mode)) {
- if (fsp && fsp->is_directory) {
- def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fsp->fsp_name, SMB_ACL_TYPE_DEFAULT);
- } else {
- def_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, fname, SMB_ACL_TYPE_DEFAULT);
- }
- def_acl = free_empty_sys_acl(conn, def_acl);
- }
+ if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+ reply_nterror(req, NT_STATUS_INVALID_LEVEL);
+ return;
+ }
- num_file_acls = count_acl_entries(conn, file_acl);
- num_def_acls = count_acl_entries(conn, def_acl);
+ srvstr_get_path(req, params, req->flags2, &fname, ¶ms[6],
+ total_params - 6,
+ STR_TERMINATE, &status);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
+ }
- if ( data_size < (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE) {
- DEBUG(5,("call_trans2qfilepathinfo: data_size too small (%u) need %u\n",
- data_size,
- (unsigned int)((num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE +
- SMB_POSIX_ACL_HEADER_SIZE) ));
- if (file_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
- }
- if (def_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
- }
- reply_nterror(
- req,
- NT_STATUS_BUFFER_TOO_SMALL);
- return;
- }
+ status = filename_convert(req,
+ conn,
+ req->flags2 & FLAGS2_DFS_PATHNAMES,
+ fname,
+ &smb_fname,
+ &fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ reply_botherror(req,
+ NT_STATUS_PATH_NOT_COVERED,
+ ERRSRV, ERRbadpath);
+ return;
+ }
+ reply_nterror(req, status);
+ return;
+ }
- SSVAL(pdata,0,SMB_POSIX_ACL_VERSION);
- SSVAL(pdata,2,num_file_acls);
- SSVAL(pdata,4,num_def_acls);
- if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE, &sbuf, file_acl)) {
- if (file_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
- }
- if (def_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
- }
- reply_nterror(
- req, NT_STATUS_INTERNAL_ERROR);
+ /* If this is a stream, check if there is a delete_pending. */
+ if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
+ && is_ntfs_stream_smb_fname(smb_fname)) {
+ struct smb_filename *smb_fname_base = NULL;
+
+ /* Create an smb_filename with stream_name == NULL. */
+ status =
+ create_synthetic_smb_fname(talloc_tos(),
+ smb_fname->base_name,
+ NULL, NULL,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
+ }
+
+ if (INFO_LEVEL_IS_UNIX(info_level)) {
+ /* Always do lstat for UNIX calls. */
+ if (SMB_VFS_LSTAT(conn, smb_fname_base) != 0) {
+ DEBUG(3,("call_trans2qfilepathinfo: "
+ "SMB_VFS_LSTAT of %s failed "
+ "(%s)\n",
+ smb_fname_str_dbg(smb_fname_base),
+ strerror(errno)));
+ TALLOC_FREE(smb_fname_base);
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
return;
}
- if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE + (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE), &sbuf, def_acl)) {
- if (file_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
- }
- if (def_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
- }
- reply_nterror(
- req,
- NT_STATUS_INTERNAL_ERROR);
+ } else {
+ if (SMB_VFS_STAT(conn, smb_fname_base) != 0) {
+ DEBUG(3,("call_trans2qfilepathinfo: "
+ "fileinfo of %s failed "
+ "(%s)\n",
+ smb_fname_str_dbg(smb_fname_base),
+ strerror(errno)));
+ TALLOC_FREE(smb_fname_base);
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
return;
}
+ }
- if (file_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
- }
- if (def_acl) {
- SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
- }
- data_size = (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE;
- break;
+ fileid = vfs_file_id_from_sbuf(conn,
+ &smb_fname_base->st);
+ TALLOC_FREE(smb_fname_base);
+ get_file_infos(fileid, &delete_pending, NULL);
+ if (delete_pending) {
+ reply_nterror(req, NT_STATUS_DELETE_PENDING);
+ return;
}
-#endif
+ }
+
+ if (INFO_LEVEL_IS_UNIX(info_level)) {
+ /* Always do lstat for UNIX calls. */
+ if (SMB_VFS_LSTAT(conn, smb_fname)) {
+ DEBUG(3,("call_trans2qfilepathinfo: "
+ "SMB_VFS_LSTAT of %s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
+ return;
+ }
+
+ } else if (!VALID_STAT(smb_fname->st) &&
+ SMB_VFS_STAT(conn, smb_fname) &&
+ (info_level != SMB_INFO_IS_NAME_VALID)) {
+ ms_dfs_link = check_msdfs_link(conn, fname,
+ &smb_fname->st);
+
+ if (!ms_dfs_link) {
+ DEBUG(3,("call_trans2qfilepathinfo: "
+ "SMB_VFS_STAT of %s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname),
+ strerror(errno)));
+ reply_nterror(req,
+ map_nt_error_from_unix(errno));
+ return;
+ }
+ }
+
+ fileid = vfs_file_id_from_sbuf(conn, &smb_fname->st);
+ get_file_infos(fileid, &delete_pending, &write_time_ts);
+ if (delete_pending) {
+ reply_nterror(req, NT_STATUS_DELETE_PENDING);
+ return;
+ }
+ }
+ DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d total_data=%d\n",
+ fname,fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
- case SMB_QUERY_POSIX_LOCK:
+ /* Pull out any data sent here before we realloc. */
+ switch (info_level) {
+ case SMB_INFO_QUERY_EAS_FROM_LIST:
{
- uint64_t count;
- uint64_t offset;
- uint32 lock_pid;
- enum brl_type lock_type;
+ /* Pull any EA list from the data portion. */
+ uint32 ea_size;
- if (total_data != POSIX_LOCK_DATA_SIZE) {
+ if (total_data < 4) {
reply_nterror(
req, NT_STATUS_INVALID_PARAMETER);
return;
}
+ ea_size = IVAL(pdata,0);
- switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
- case POSIX_LOCK_TYPE_READ:
- lock_type = READ_LOCK;
- break;
- case POSIX_LOCK_TYPE_WRITE:
- lock_type = WRITE_LOCK;
- break;
- case POSIX_LOCK_TYPE_UNLOCK:
- default:
- /* There's no point in asking for an unlock... */
- reply_nterror(
- req,
- NT_STATUS_INVALID_PARAMETER);
- return;
+ 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) ));
+ reply_nterror(
+ req, NT_STATUS_INVALID_PARAMETER);
+ return;
}
- lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
-#if defined(HAVE_LONGLONG)
- offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
- ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
- count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
- ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
-#else /* HAVE_LONGLONG */
- offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);
- count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
-#endif /* HAVE_LONGLONG */
+ if (!lp_ea_support(SNUM(conn))) {
+ reply_doserror(req, ERRDOS,
+ ERReasnotsupported);
+ return;
+ }
- status = query_lock(fsp,
- &lock_pid,
- &count,
- &offset,
- &lock_type,
- POSIX_LOCK);
+ /* Pull out the list of names. */
+ ea_list = read_ea_name_list(req, pdata + 4, ea_size - 4);
+ if (!ea_list) {
+ reply_nterror(
+ req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
+ break;
+ }
- if (ERROR_WAS_LOCK_DENIED(status)) {
- /* Here we need to report who has it locked... */
- data_size = POSIX_LOCK_DATA_SIZE;
+ case SMB_QUERY_POSIX_LOCK:
+ {
+ if (fsp == NULL || fsp->fh->fd == -1) {
+ reply_nterror(req, NT_STATUS_INVALID_HANDLE);
+ return;
+ }
- SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, lock_type);
- SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0);
- SIVAL(pdata, POSIX_LOCK_PID_OFFSET, lock_pid);
-#if defined(HAVE_LONGLONG)
- SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF));
- SIVAL(pdata, POSIX_LOCK_START_OFFSET + 4, (uint32)((offset >> 32) & 0xFFFFFFFF));
- SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, (uint32)(count & 0xFFFFFFFF));
- SIVAL(pdata, POSIX_LOCK_LEN_OFFSET + 4, (uint32)((count >> 32) & 0xFFFFFFFF));
-#else /* HAVE_LONGLONG */
- SIVAL(pdata, POSIX_LOCK_START_OFFSET, offset);
- SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, count);
-#endif /* HAVE_LONGLONG */
+ if (total_data != POSIX_LOCK_DATA_SIZE) {
+ reply_nterror(
+ req, NT_STATUS_INVALID_PARAMETER);
+ return;
+ }
- } else if (NT_STATUS_IS_OK(status)) {
- /* For success we just return a copy of what we sent
- with the lock type set to POSIX_LOCK_TYPE_UNLOCK. */
- data_size = POSIX_LOCK_DATA_SIZE;
- memcpy(pdata, lock_data, POSIX_LOCK_DATA_SIZE);
- SSVAL(pdata, POSIX_LOCK_TYPE_OFFSET, POSIX_LOCK_TYPE_UNLOCK);
- } else {
- reply_nterror(req, status);
+ /* Copy the lock range data. */
+ lock_data = (char *)TALLOC_MEMDUP(
+ req, pdata, total_data);
+ if (!lock_data) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
return;
}
- break;
+ lock_data_count = total_data;
}
-
default:
- reply_nterror(req, NT_STATUS_INVALID_LEVEL);
- return;
+ break;
+ }
+
+ *pparams = (char *)SMB_REALLOC(*pparams,2);
+ if (*pparams == NULL) {
+ reply_nterror(req, NT_STATUS_NO_MEMORY);
+ return;
+ }
+ params = *pparams;
+ SSVAL(params,0,0);
+
+ /*
+ * draft-leach-cifs-v1-spec-02.txt
+ * 4.2.14 TRANS2_QUERY_PATH_INFORMATION: Get File Attributes given Path
+ * says:
+ *
+ * The requested information is placed in the Data portion of the
+ * transaction response. For the information levels greater than 0x100,
+ * the transaction response has 1 parameter word which should be
+ * ignored by the client.
+ *
+ * However Windows only follows this rule for the IS_NAME_VALID call.
+ */
+ switch (info_level) {
+ case SMB_INFO_IS_NAME_VALID:
+ param_size = 0;
+ break;
+ }
+
+ status = smbd_do_qfilepathinfo(conn, req, info_level,
+ fsp, smb_fname,
+ delete_pending, write_time_ts,
+ ms_dfs_link, ea_list,
+ lock_data_count, lock_data,
+ req->flags2, max_data_bytes,
+ ppdata, &data_size);
+ if (!NT_STATUS_IS_OK(status)) {
+ reply_nterror(req, status);
+ return;
}
send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,
NTSTATUS smb_set_file_time(connection_struct *conn,
files_struct *fsp,
- const char *fname,
- const SMB_STRUCT_STAT *psbuf,
+ const struct smb_filename *smb_fname,
struct smb_file_time *ft,
bool setting_write_time)
{
+ struct smb_filename *smb_fname_base = NULL;
uint32 action =
FILE_NOTIFY_CHANGE_LAST_ACCESS
|FILE_NOTIFY_CHANGE_LAST_WRITE;
+ NTSTATUS status;
- if (!VALID_STAT(*psbuf)) {
+ if (!VALID_STAT(smb_fname->st)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
/* get some defaults (no modifications) if any info is zero or -1. */
if (null_timespec(ft->atime)) {
- ft->atime= psbuf->st_ex_atime;
+ ft->atime= smb_fname->st.st_ex_atime;
action &= ~FILE_NOTIFY_CHANGE_LAST_ACCESS;
}
if (null_timespec(ft->mtime)) {
- ft->mtime = psbuf->st_ex_mtime;
+ ft->mtime = smb_fname->st.st_ex_mtime;
action &= ~FILE_NOTIFY_CHANGE_LAST_WRITE;
}
*/
{
- struct timespec mts = psbuf->st_ex_mtime;
- struct timespec ats = psbuf->st_ex_atime;
+ struct timespec mts = smb_fname->st.st_ex_mtime;
+ struct timespec ats = smb_fname->st.st_ex_atime;
if ((timespec_compare(&ft->atime, &ats) == 0) &&
(timespec_compare(&ft->mtime, &mts) == 0)) {
return NT_STATUS_OK;
set_sticky_write_time_fsp(fsp, ft->mtime);
}
} else {
- set_sticky_write_time_path(conn, fname,
- vfs_file_id_from_sbuf(conn, psbuf),
- ft->mtime);
+ set_sticky_write_time_path(
+ vfs_file_id_from_sbuf(conn, &smb_fname->st),
+ ft->mtime);
}
}
DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
- if (fsp && fsp->base_fsp) {
- fname = fsp->base_fsp->fsp_name;
+ /* Always call ntimes on the base, even if a stream was passed in. */
+ status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
+ NULL, &smb_fname->st,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
- if(file_ntimes(conn, fname, ft, psbuf)!=0) {
+ if(file_ntimes(conn, smb_fname_base, ft)!=0) {
+ TALLOC_FREE(smb_fname_base);
return map_nt_error_from_unix(errno);
}
- notify_fname(conn, NOTIFY_ACTION_MODIFIED, action, fname);
+ TALLOC_FREE(smb_fname_base);
+ notify_fname(conn, NOTIFY_ACTION_MODIFIED, action,
+ smb_fname->base_name);
return NT_STATUS_OK;
}
****************************************************************************/
static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
- files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf,
- uint32 dosmode)
+ const struct smb_filename *smb_fname,
+ uint32 dosmode)
{
- if (!VALID_STAT(*psbuf)) {
+ struct smb_filename *smb_fname_base = NULL;
+ NTSTATUS status;
+
+ if (!VALID_STAT(smb_fname->st)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
- if (fsp) {
- if (fsp->base_fsp) {
- fname = fsp->base_fsp->fsp_name;
- } else {
- fname = fsp->fsp_name;
- }
+ /* Always operate on the base_name, even if a stream was passed in. */
+ status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
+ NULL, &smb_fname->st,
+ &smb_fname_base);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
}
if (dosmode) {
- if (S_ISDIR(psbuf->st_ex_mode)) {
+ if (S_ISDIR(smb_fname_base->st.st_ex_mode)) {
dosmode |= aDIR;
} else {
dosmode &= ~aDIR;
DEBUG(6,("smb_set_file_dosmode: dosmode: 0x%x\n", (unsigned int)dosmode));
/* check the mode isn't different, before changing it */
- if ((dosmode != 0) && (dosmode != dos_mode(conn, fname, psbuf))) {
-
- DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode 0x%x\n",
- fname, (unsigned int)dosmode ));
-
- if(file_set_dosmode(conn, fname, dosmode, psbuf, NULL, false)) {
- DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of %s failed (%s)\n",
- fname, strerror(errno)));
- return map_nt_error_from_unix(errno);
+ if ((dosmode != 0) && (dosmode != dos_mode(conn, smb_fname_base))) {
+ DEBUG(10,("smb_set_file_dosmode: file %s : setting dos mode "
+ "0x%x\n", smb_fname_str_dbg(smb_fname_base),
+ (unsigned int)dosmode));
+
+ if(file_set_dosmode(conn, smb_fname_base, dosmode, NULL,
+ false)) {
+ DEBUG(2,("smb_set_file_dosmode: file_set_dosmode of "
+ "%s failed (%s)\n",
+ smb_fname_str_dbg(smb_fname_base),
+ strerror(errno)));
+ status = map_nt_error_from_unix(errno);
+ goto out;
}
}
- return NT_STATUS_OK;
+ status = NT_STATUS_OK;
+ out:
+ TALLOC_FREE(smb_fname_base);
+ return status;
}
/****************************************************************************
static NTSTATUS smb_set_file_size(connection_struct *conn,
struct smb_request *req,
- files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf,
- SMB_OFF_T size)
+ files_struct *fsp,
+ const struct smb_filename *smb_fname,
+ const SMB_STRUCT_STAT *psbuf,
+ SMB_OFF_T size)
{
- struct smb_filename *smb_fname = NULL;
NTSTATUS status = NT_STATUS_OK;
+ struct smb_filename *smb_fname_tmp = NULL;
files_struct *new_fsp = NULL;
if (!VALID_STAT(*psbuf)) {
}
DEBUG(10,("smb_set_file_size: file %s : setting new size to %.0f\n",
- fname, (double)size ));
+ smb_fname_str_dbg(smb_fname), (double)size));
if (fsp && fsp->fh->fd != -1) {
/* Handle based call. */
return NT_STATUS_OK;
}
- status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
- &smb_fname);
+ status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
+ smb_fname_tmp->st = *psbuf;
+
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
- smb_fname, /* fname */
+ smb_fname_tmp, /* fname */
FILE_WRITE_ATTRIBUTES, /* access_mask */
(FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
FILE_SHARE_DELETE),
&new_fsp, /* result */
NULL); /* pinfo */
- *psbuf = smb_fname->st;
- TALLOC_FREE(smb_fname);
+ TALLOC_FREE(smb_fname_tmp);
if (!NT_STATUS_IS_OK(status)) {
/* NB. We check for open_was_deferred in the caller. */
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
NTSTATUS status = NT_STATUS_OK;
bool delete_on_close;
}
delete_on_close = (CVAL(pdata,0) ? True : False);
- dosmode = dos_mode(conn, fname, psbuf);
+ dosmode = dos_mode(conn, smb_fname);
DEBUG(10,("smb_set_file_disposition_info: file %s, dosmode = %u, "
"delete_on_close = %u\n",
- fsp->fsp_name,
+ smb_fname_str_dbg(smb_fname),
(unsigned int)dosmode,
(unsigned int)delete_on_close ));
req->flags2 & FLAGS2_DFS_PATHNAMES,
oldname,
&smb_fname_old,
- &oldname);
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
if (newname[0] != ':') {
return NT_STATUS_NOT_SUPPORTED;
}
+
+ /* Create an smb_fname to call rename_internals_fsp() with. */
+ status = create_synthetic_smb_fname(talloc_tos(),
+ fsp->base_fsp->fsp_name,
+ newname, NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /*
+ * Set the original last component, since
+ * rename_internals_fsp() requires it.
+ */
+ smb_fname->original_lcomp = talloc_strdup(smb_fname, newname);
+ if (smb_fname->original_lcomp == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
+ }
+
+ /* Create a char * to call rename_internals() with. */
base_name = talloc_asprintf(ctx, "%s%s",
fsp->base_fsp->fsp_name,
newname);
if (!base_name) {
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto out;
}
} else {
/* newname must *not* be a stream name. */
- if (is_ntfs_stream_name(newname)) {
+ if (newname[0] == ':') {
return NT_STATUS_NOT_SUPPORTED;
}
return NT_STATUS_NO_MEMORY;
}
- status = unix_convert(ctx, conn, newname, &smb_fname,
+ status = unix_convert(ctx, conn, base_name, &smb_fname,
UCF_SAVE_LCOMP);
/* If an error we expect this to be
* NT_STATUS_OBJECT_PATH_NOT_FOUND */
- if (!NT_STATUS_IS_OK(status)
- && !NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
- status)) {
- goto out;
+ if (!NT_STATUS_IS_OK(status)) {
+ if(!NT_STATUS_EQUAL(NT_STATUS_OBJECT_PATH_NOT_FOUND,
+ status)) {
+ goto out;
+ }
+ /* Create an smb_fname to call rename_internals_fsp() */
+ status = create_synthetic_smb_fname(talloc_tos(),
+ base_name, NULL,
+ NULL, &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
}
+
}
if (fsp) {
DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
fsp->fnum, fsp->fsp_name, base_name ));
- status = rename_internals_fsp(conn, fsp, base_name,
- smb_fname ?
- smb_fname->original_lcomp : NULL,
- 0, overwrite);
+ status = rename_internals_fsp(conn, fsp, smb_fname, 0,
+ overwrite);
} else {
DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
fname, base_name ));
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- const SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
struct smb_file_time ft;
ZERO_STRUCT(ft);
ft.mtime = interpret_long_date(pdata + 16);
DEBUG(10,("smb_set_info_standard: file %s\n",
- fname ? fname : fsp->fsp_name ));
+ smb_fname_str_dbg(smb_fname)));
- return smb_set_file_time(conn,
- fsp,
- fname,
- psbuf,
- &ft,
- true);
+ return smb_set_file_time(conn, fsp, smb_fname, &ft, true);
}
/****************************************************************************
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
/* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
struct timespec write_time;
/* Set the attributes */
dosmode = IVAL(pdata,32);
- status = smb_set_file_dosmode(conn, fsp, fname, psbuf, dosmode);
+ status = smb_set_file_dosmode(conn, smb_fname, dosmode);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
}
}
- DEBUG(10,("smb_set_file_basic_info: file %s\n",
- fname ? fname : fsp->fsp_name ));
+ DEBUG(10, ("smb_set_file_basic_info: file %s\n",
+ smb_fname_str_dbg(smb_fname)));
- return smb_set_file_time(conn,
- fsp,
- fname,
- psbuf,
- &ft,
- setting_write_time);
+ return smb_set_file_time(conn, fsp, smb_fname, &ft,
+ setting_write_time);
}
/****************************************************************************
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ struct smb_filename *smb_fname)
{
- struct smb_filename *smb_fname = NULL;
uint64_t allocation_size = 0;
NTSTATUS status = NT_STATUS_OK;
files_struct *new_fsp = NULL;
- if (!VALID_STAT(*psbuf)) {
+ if (!VALID_STAT(smb_fname->st)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
}
#endif /* LARGE_SMB_OFF_T */
- DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for file %s to %.0f\n",
- fname, (double)allocation_size ));
+ DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for "
+ "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
+ (double)allocation_size));
if (allocation_size) {
allocation_size = smb_roundup(conn, allocation_size);
}
- DEBUG(10,("smb_set_file_allocation_info: file %s : setting new allocation size to %.0f\n",
- fname, (double)allocation_size ));
+ DEBUG(10,("smb_set_file_allocation_info: file %s : setting new "
+ "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname),
+ (double)allocation_size));
if (fsp && fsp->fh->fd != -1) {
/* Open file handle. */
/* Only change if needed. */
- if (allocation_size != get_file_size_stat(psbuf)) {
+ if (allocation_size != get_file_size_stat(&smb_fname->st)) {
if (vfs_allocate_file_space(fsp, allocation_size) == -1) {
return map_nt_error_from_unix(errno);
}
}
/* Pathname or stat or directory file. */
-
- status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
- &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
- status = SMB_VFS_CREATE_FILE(
+ status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
0, /* root_dir_fid */
&new_fsp, /* result */
NULL); /* pinfo */
- *psbuf = smb_fname->st;
- TALLOC_FREE(smb_fname);
-
if (!NT_STATUS_IS_OK(status)) {
/* NB. We check for open_was_deferred in the caller. */
return status;
}
/* Only change if needed. */
- if (allocation_size != get_file_size_stat(psbuf)) {
+ if (allocation_size != get_file_size_stat(&smb_fname->st)) {
if (vfs_allocate_file_space(new_fsp, allocation_size) == -1) {
status = map_nt_error_from_unix(errno);
close_file(req, new_fsp, NORMAL_CLOSE);
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
SMB_OFF_T size;
}
#endif /* LARGE_SMB_OFF_T */
DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for "
- "file %s to %.0f\n", fname, (double)size ));
+ "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
+ (double)size));
return smb_set_file_size(conn, req,
fsp,
- fname,
- psbuf,
+ smb_fname,
+ &smb_fname->st,
size);
}
static NTSTATUS smb_unix_mknod(connection_struct *conn,
const char *pdata,
int total_data,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
uint32 file_type = IVAL(pdata,56);
#if defined(HAVE_MAKEDEV)
return NT_STATUS_INVALID_PARAMETER;
}
- status = unix_perms_from_wire(conn, psbuf, raw_unixmode, PERM_NEW_FILE, &unixmode);
+ status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
+ PERM_NEW_FILE, &unixmode);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
return NT_STATUS_INVALID_PARAMETER;
}
- DEBUG(10,("smb_unix_mknod: SMB_SET_FILE_UNIX_BASIC doing mknod dev %.0f mode \
-0%o for file %s\n", (double)dev, (unsigned int)unixmode, fname ));
+ DEBUG(10,("smb_unix_mknod: SMB_SET_FILE_UNIX_BASIC doing mknod dev "
+ "%.0f mode 0%o for file %s\n", (double)dev,
+ (unsigned int)unixmode, smb_fname_str_dbg(smb_fname)));
/* Ok - do the mknod. */
- if (SMB_VFS_MKNOD(conn, fname, unixmode, dev) != 0) {
+ if (SMB_VFS_MKNOD(conn, smb_fname->base_name, unixmode, dev) != 0) {
return map_nt_error_from_unix(errno);
}
if (lp_inherit_perms(SNUM(conn))) {
char *parent;
- if (!parent_dirname(talloc_tos(), fname, &parent, NULL)) {
+ if (!parent_dirname(talloc_tos(), smb_fname->base_name,
+ &parent, NULL)) {
return NT_STATUS_NO_MEMORY;
}
- inherit_access_posix_acl(conn, parent, fname, unixmode);
+ inherit_access_posix_acl(conn, parent, smb_fname->base_name,
+ unixmode);
TALLOC_FREE(parent);
}
- if (vfs_stat_smb_fname(conn, fname, psbuf) != 0) {
- status = map_nt_error_from_unix(errno);
- SMB_VFS_UNLINK(conn,fname);
- return status;
- }
return NT_STATUS_OK;
}
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
struct smb_file_time ft;
uint32 raw_unixmode;
files_struct *all_fsps = NULL;
bool modify_mtime = true;
struct file_id id;
+ SMB_STRUCT_STAT sbuf;
ZERO_STRUCT(ft);
set_grp = (gid_t)IVAL(pdata,48);
raw_unixmode = IVAL(pdata,84);
- if (VALID_STAT(*psbuf)) {
- if (S_ISDIR(psbuf->st_ex_mode)) {
+ if (VALID_STAT(smb_fname->st)) {
+ if (S_ISDIR(smb_fname->st.st_ex_mode)) {
ptype = PERM_EXISTING_DIR;
} else {
ptype = PERM_EXISTING_FILE;
ptype = PERM_NEW_FILE;
}
- status = unix_perms_from_wire(conn, psbuf, raw_unixmode, ptype, &unixmode);
+ status = unix_perms_from_wire(conn, &smb_fname->st, raw_unixmode,
+ ptype, &unixmode);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
- DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC: name = %s \
-size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
- fname, (double)size, (unsigned int)set_owner, (unsigned int)set_grp, (int)raw_unixmode));
+ DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC: name = "
+ "%s size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
+ smb_fname_str_dbg(smb_fname), (double)size,
+ (unsigned int)set_owner, (unsigned int)set_grp,
+ (int)raw_unixmode));
- if (!VALID_STAT(*psbuf)) {
+ sbuf = smb_fname->st;
+
+ if (!VALID_STAT(sbuf)) {
+ struct smb_filename *smb_fname_tmp = NULL;
/*
* The only valid use of this is to create character and block
* devices, and named pipes. This is deprecated (IMHO) and
status = smb_unix_mknod(conn,
pdata,
total_data,
- fname,
- psbuf);
+ smb_fname);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
+ status = copy_smb_filename(talloc_tos(), smb_fname,
+ &smb_fname_tmp);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
+
+ if (SMB_VFS_STAT(conn, smb_fname_tmp) != 0) {
+ status = map_nt_error_from_unix(errno);
+ TALLOC_FREE(smb_fname_tmp);
+ SMB_VFS_UNLINK(conn, smb_fname);
+ return status;
+ }
+
+ sbuf = smb_fname_tmp->st;
+ TALLOC_FREE(smb_fname_tmp);
+
/* Ensure we don't try and change anything else. */
raw_unixmode = SMB_MODE_NO_CHANGE;
- size = get_file_size_stat(psbuf);
- ft.atime = psbuf->st_ex_atime;
- ft.mtime = psbuf->st_ex_mtime;
+ size = get_file_size_stat(&sbuf);
+ ft.atime = sbuf.st_ex_atime;
+ ft.mtime = sbuf.st_ex_mtime;
/*
* We continue here as we might want to change the
* owner uid/gid.
* */
if (!size) {
- size = get_file_size_stat(psbuf);
+ size = get_file_size_stat(&sbuf);
}
#endif
*/
if (raw_unixmode != SMB_MODE_NO_CHANGE) {
- DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC setting mode 0%o for file %s\n",
- (unsigned int)unixmode, fname ));
- if (SMB_VFS_CHMOD(conn, fname, unixmode) != 0) {
+ DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
+ "setting mode 0%o for file %s\n",
+ (unsigned int)unixmode,
+ smb_fname_str_dbg(smb_fname)));
+ if (SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode) != 0) {
return map_nt_error_from_unix(errno);
}
}
* Deal with the UNIX specific uid set.
*/
- if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) && (psbuf->st_ex_uid != set_owner)) {
+ if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) &&
+ (sbuf.st_ex_uid != set_owner)) {
int ret;
- DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC changing owner %u for path %s\n",
- (unsigned int)set_owner, fname ));
+ DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
+ "changing owner %u for path %s\n",
+ (unsigned int)set_owner,
+ smb_fname_str_dbg(smb_fname)));
- if (S_ISLNK(psbuf->st_ex_mode)) {
- ret = SMB_VFS_LCHOWN(conn, fname, set_owner, (gid_t)-1);
+ if (S_ISLNK(sbuf.st_ex_mode)) {
+ ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name,
+ set_owner, (gid_t)-1);
} else {
- ret = SMB_VFS_CHOWN(conn, fname, set_owner, (gid_t)-1);
+ ret = SMB_VFS_CHOWN(conn, smb_fname->base_name,
+ set_owner, (gid_t)-1);
}
if (ret != 0) {
status = map_nt_error_from_unix(errno);
if (delete_on_fail) {
- SMB_VFS_UNLINK(conn,fname);
+ SMB_VFS_UNLINK(conn, smb_fname);
}
return status;
}
* Deal with the UNIX specific gid set.
*/
- if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) && (psbuf->st_ex_gid != set_grp)) {
- DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC changing group %u for file %s\n",
- (unsigned int)set_owner, fname ));
- if (SMB_VFS_CHOWN(conn, fname, (uid_t)-1, set_grp) != 0) {
+ if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) &&
+ (sbuf.st_ex_gid != set_grp)) {
+ DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
+ "changing group %u for file %s\n",
+ (unsigned int)set_owner,
+ smb_fname_str_dbg(smb_fname)));
+ if (SMB_VFS_CHOWN(conn, smb_fname->base_name, (uid_t)-1,
+ set_grp) != 0) {
status = map_nt_error_from_unix(errno);
if (delete_on_fail) {
- SMB_VFS_UNLINK(conn,fname);
+ SMB_VFS_UNLINK(conn, smb_fname);
}
return status;
}
/* Deal with any size changes. */
status = smb_set_file_size(conn, req,
- fsp,
- fname,
- psbuf,
- size);
+ fsp,
+ smb_fname,
+ &sbuf,
+ size);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/* Deal with any time changes. */
- id = vfs_file_id_from_sbuf(conn, psbuf);
+ if (null_timespec(ft.mtime) && null_timespec(ft.atime)) {
+ /* No change, don't cancel anything. */
+ return status;
+ }
+
+ id = vfs_file_id_from_sbuf(conn, &sbuf);
for(all_fsps = file_find_di_first(id); all_fsps;
all_fsps = file_find_di_next(all_fsps)) {
/*
status = smb_set_file_time(conn,
fsp,
- fname,
- psbuf,
+ smb_fname,
&ft,
false);
if (modify_mtime) {
notify_fname(conn, NOTIFY_ACTION_MODIFIED,
- FILE_NOTIFY_CHANGE_LAST_WRITE, fname);
+ FILE_NOTIFY_CHANGE_LAST_WRITE, smb_fname->base_name);
}
return status;
}
const char *pdata,
int total_data,
files_struct *fsp,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ const struct smb_filename *smb_fname)
{
NTSTATUS status;
uint32 smb_fflags;
* and UNIX_INFO2.
*/
status = smb_set_file_unix_basic(conn, req, pdata, total_data,
- fsp, fname, psbuf);
+ fsp, smb_fname);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
if (smb_fmask != 0) {
int stat_fflags = 0;
- if (!map_info2_flags_to_sbuf(psbuf, smb_fflags, smb_fmask,
- &stat_fflags)) {
+ if (!map_info2_flags_to_sbuf(&smb_fname->st, smb_fflags,
+ smb_fmask, &stat_fflags)) {
/* Client asked to alter a flag we don't understand. */
return NT_STATUS_INVALID_PARAMETER;
}
/* XXX: we should be using SMB_VFS_FCHFLAGS here. */
return NT_STATUS_NOT_SUPPORTED;
} else {
- if (SMB_VFS_CHFLAGS(conn, fname, stat_fflags) != 0) {
+ if (SMB_VFS_CHFLAGS(conn, smb_fname->base_name,
+ stat_fflags) != 0) {
return map_nt_error_from_unix(errno);
}
}
struct smb_request *req,
const char *pdata,
int total_data,
- const char *fname,
- SMB_STRUCT_STAT *psbuf)
+ struct smb_filename *smb_fname)
{
- struct smb_filename *smb_fname = NULL;
NTSTATUS status = NT_STATUS_OK;
files_struct *fsp = NULL;
uint16 flags = 0;
flags = SVAL(pdata,0);
- if (!VALID_STAT(*psbuf)) {
+ if (!VALID_STAT(smb_fname->st)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
if ((flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) &&
- !VALID_STAT_OF_DIR(*psbuf)) {
+ !VALID_STAT_OF_DIR(smb_fname->st)) {
return NT_STATUS_NOT_A_DIRECTORY;
}
DEBUG(10,("smb_posix_unlink: %s %s\n",
(flags == SMB_POSIX_UNLINK_DIRECTORY_TARGET) ? "directory" : "file",
- fname));
+ smb_fname_str_dbg(smb_fname)));
- if (VALID_STAT_OF_DIR(*psbuf)) {
+ if (VALID_STAT_OF_DIR(smb_fname->st)) {
create_options |= FILE_DIRECTORY_FILE;
}
- status = create_synthetic_smb_fname_split(talloc_tos(), fname, psbuf,
- &smb_fname);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
-
status = SMB_VFS_CREATE_FILE(
conn, /* conn */
req, /* req */
&fsp, /* result */
&info); /* pinfo */
- *psbuf = smb_fname->st;
- TALLOC_FREE(smb_fname);
-
if (!NT_STATUS_IS_OK(status)) {
return status;
}
&del,
1,
fsp,
- fname,
- psbuf);
+ smb_fname);
if (!NT_STATUS_IS_OK(status)) {
close_file(req, fsp, NORMAL_CLOSE);
"(%s)\n",
smb_fname_str_dbg(smb_fname),
strerror(errno)));
- reply_unixerror(req,ERRDOS,ERRbadpath);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
} else {
"fileinfo of %s failed (%s)\n",
smb_fname_str_dbg(smb_fname),
strerror(errno)));
- reply_unixerror(req,ERRDOS,ERRbadpath);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
}
max_data_bytes);
return;
} else {
- reply_unixerror(req, ERRDOS, ERRbadpath);
+ reply_doserror(req, ERRDOS, ERRbadpath);
return;
}
} else {
DEBUG(3,("call_trans2setfilepathinfo: fstat "
"of fnum %d failed (%s)\n", fsp->fnum,
strerror(errno)));
- reply_unixerror(req, ERRDOS, ERRbadfid);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
}
"%s failed (%s)\n",
smb_fname_str_dbg(smb_fname),
strerror(errno)));
- reply_unixerror(req, ERRDOS, ERRbadpath);
+ reply_nterror(req, map_nt_error_from_unix(errno));
return;
}
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
pdata,
total_data,
fsp,
- fname,
- &sbuf);
+ smb_fname);
break;
}
status = smb_posix_unlink(conn, req,
pdata,
total_data,
- fname,
- &sbuf);
+ smb_fname);
break;
}
req->flags2 & FLAGS2_DFS_PATHNAMES,
directory,
&smb_dname,
- &directory);
+ NULL);
if (!NT_STATUS_IS_OK(status)) {
if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {