/*
Unix SMB/CIFS implementation.
SMB transaction2 handling
- Copyright (C) Jeremy Allison 1994-2003
+ Copyright (C) Jeremy Allison 1994-2007
Copyright (C) Stefan (metze) Metzmacher 2003
Copyright (C) Volker Lendecke 2005
Copyright (C) Steve French 2005
int send_trans2_replies(char *outbuf,
int bufsize,
- char *params,
+ const char *params,
int paramsize,
- char *pdata,
+ const char *pdata,
int datasize,
int max_data_bytes)
{
int data_to_send = datasize;
int params_to_send = paramsize;
int useable_space;
- char *pp = params;
- char *pd = pdata;
+ const char *pp = params;
+ const char *pd = pdata;
int params_sent_thistime, data_sent_thistime, total_sent_thistime;
int alignment_offset = 1; /* JRA. This used to be 3. Set to 1 to make netmon parse ok. */
int data_alignment_offset = 0;
Map wire perms onto standard UNIX permissions. Obey share restrictions.
****************************************************************************/
-static mode_t unix_perms_from_wire( connection_struct *conn, SMB_STRUCT_STAT *pst, uint32 perms)
+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,
+ uint32 perms,
+ enum perm_type ptype,
+ mode_t *ret_perms)
{
mode_t ret = 0;
- if (perms == SMB_MODE_NO_CHANGE)
- return pst->st_mode;
+ if (perms == SMB_MODE_NO_CHANGE) {
+ if (!VALID_STAT(*psbuf)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ } else {
+ *ret_perms = psbuf->st_mode;
+ return NT_STATUS_OK;
+ }
+ }
ret |= ((perms & UNIX_X_OTH ) ? S_IXOTH : 0);
ret |= ((perms & UNIX_W_OTH ) ? S_IWOTH : 0);
ret |= ((perms & UNIX_SET_UID ) ? S_ISUID : 0);
#endif
- if (VALID_STAT(*pst) && S_ISDIR(pst->st_mode)) {
+ switch (ptype) {
+ case PERM_NEW_FILE:
+ /* Apply mode mask */
+ ret &= lp_create_mask(SNUM(conn));
+ /* Add in force bits */
+ ret |= lp_force_create_mode(SNUM(conn));
+ break;
+ case PERM_NEW_DIR:
ret &= lp_dir_mask(SNUM(conn));
/* Add in force bits */
ret |= lp_force_dir_mode(SNUM(conn));
- } else {
+ break;
+ case PERM_EXISTING_FILE:
/* Apply mode mask */
- ret &= lp_create_mask(SNUM(conn));
+ ret &= lp_security_mask(SNUM(conn));
/* Add in force bits */
- ret |= lp_force_create_mode(SNUM(conn));
+ ret |= lp_force_security_mode(SNUM(conn));
+ break;
+ case PERM_EXISTING_DIR:
+ /* Apply mode mask */
+ ret &= lp_dir_security_mask(SNUM(conn));
+ /* Add in force bits */
+ ret |= lp_force_dir_security_mode(SNUM(conn));
+ break;
}
- return ret;
+ *ret_perms = ret;
+ return NT_STATUS_OK;
}
/****************************************************************************
code.
****************************************************************************/
-NTSTATUS hardlink_internals(connection_struct *conn, char *oldname, char *newname)
+NTSTATUS hardlink_internals(connection_struct *conn, pstring oldname, pstring newname)
{
SMB_STRUCT_STAT sbuf1, sbuf2;
pstring last_component_oldname;
return status;
}
+/****************************************************************************
+ Deal with setting the time from any of the setfilepathinfo functions.
+****************************************************************************/
+
+static NTSTATUS smb_set_file_time(connection_struct *conn,
+ files_struct *fsp,
+ const char *fname,
+ const SMB_STRUCT_STAT *psbuf,
+ struct utimbuf tvs)
+{
+ if (!VALID_STAT(*psbuf)) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
+
+ /* get some defaults (no modifications) if any info is zero or -1. */
+ if (null_mtime(tvs.actime)) {
+ tvs.actime = psbuf->st_atime;
+ }
+
+ if (null_mtime(tvs.modtime)) {
+ tvs.modtime = psbuf->st_mtime;
+ }
+
+ DEBUG(6,("smb_set_file_time: actime: %s " , ctime(&tvs.actime)));
+ DEBUG(6,("smb_set_file_time: modtime: %s ", ctime(&tvs.modtime)));
+
+ /*
+ * Try and set the times of this file if
+ * they are different from the current values.
+ */
+
+ if (psbuf->st_mtime == tvs.modtime && psbuf->st_atime == tvs.actime) {
+ return NT_STATUS_OK;
+ }
+
+ 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,("smb_set_file_time: setting pending modtime to %s\n", ctime(&tvs.modtime) ));
+ fsp_set_pending_modtime(fsp, tvs.modtime);
+ }
+
+ }
+ DEBUG(10,("smb_set_file_time: setting utimes to modified values.\n"));
+
+ if(file_utime(conn, fname, &tvs)!=0) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Deal with setting the dosmode from any of the setfilepathinfo functions.
+****************************************************************************/
+
+static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf,
+ uint32 dosmode)
+{
+ if (!VALID_STAT(*psbuf)) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
+
+ if (dosmode) {
+ if (S_ISDIR(psbuf->st_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, 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);
+ }
+ }
+ return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Deal with setting the size from any of the setfilepathinfo functions.
+****************************************************************************/
+
+static NTSTATUS smb_set_file_size(connection_struct *conn,
+ files_struct *fsp,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf,
+ SMB_OFF_T size)
+{
+ NTSTATUS status = NT_STATUS_OK;
+ files_struct *new_fsp = NULL;
+
+ if (!VALID_STAT(*psbuf)) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
+
+ DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size));
+
+ if (size == get_file_size(*psbuf)) {
+ return NT_STATUS_OK;
+ }
+
+ DEBUG(10,("call_trans2setfilepathinfo: file %s : setting new size to %.0f\n",
+ fname, (double)size ));
+
+ if (fsp && fsp->fh->fd != -1) {
+ /* Handle based call. */
+ if (vfs_set_filelen(fsp, size) == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_OK;
+ }
+
+ status = open_file_ntcreate(conn, fname, psbuf,
+ FILE_WRITE_DATA,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN,
+ 0,
+ FILE_ATTRIBUTE_NORMAL,
+ FORCE_OPLOCK_BREAK_TO_NONE,
+ NULL, &new_fsp);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ /* NB. We check for open_was_deferred in the caller. */
+ return status;
+ }
+
+ if (vfs_set_filelen(new_fsp, size) == -1) {
+ status = map_nt_error_from_unix(errno);
+ close_file(new_fsp,NORMAL_CLOSE);
+ return status;
+ }
+
+ close_file(new_fsp,NORMAL_CLOSE);
+ return NT_STATUS_OK;
+}
+
/****************************************************************************
Deal with SMB_INFO_SET_EA.
****************************************************************************/
-static int smb_info_set_ea(
- connection_struct *conn,
- char *outbuf,
- int bufsize,
- char *params,
- int total_params,
- char *pdata,
+static NTSTATUS smb_info_set_ea(connection_struct *conn,
+ const char *pdata,
int total_data,
- unsigned int max_data_bytes,
files_struct *fsp,
const char *fname)
{
if ((total_data == 4) && (IVAL(pdata,0) == 4)) {
/* We're done. We only get EA info in this call. */
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, pdata, 0, max_data_bytes);
- return -1;
+ return NT_STATUS_OK;
}
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ return NT_STATUS_INVALID_PARAMETER;
}
if (IVAL(pdata,0) > total_data) {
DEBUG(10,("smb_info_set_ea: bad total data size (%u) > %u\n",
IVAL(pdata,0), (unsigned int)total_data));
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ return NT_STATUS_INVALID_PARAMETER;
}
ctx = talloc_init("SMB_INFO_SET_EA");
if (!ctx) {
- return ERROR_NT(NT_STATUS_NO_MEMORY);
+ return 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);
+ return 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);
- }
-
- /* We're done. We only get EA info in this call. */
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, pdata, 0, max_data_bytes);
- return -1;
+ return status;
}
/****************************************************************************
Deal with SMB_SET_FILE_DISPOSITION_INFO.
****************************************************************************/
-static int smb_set_file_disposition_info(connection_struct *conn,
- char *outbuf,
- int bufsize,
- char *params,
- int total_params,
- char *pdata,
+static NTSTATUS smb_set_file_disposition_info(connection_struct *conn,
+ const char *pdata,
int total_data,
- unsigned int max_data_bytes,
files_struct *fsp,
- int dosmode)
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
{
NTSTATUS status = NT_STATUS_OK;
BOOL delete_on_close;
+ uint32 dosmode = 0;
if (total_data < 1) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ return NT_STATUS_INVALID_PARAMETER;
}
- delete_on_close = (CVAL(pdata,0) ? True : False);
-
if (fsp == NULL) {
- return(UNIXERROR(ERRDOS,ERRbadfid));
+ return NT_STATUS_INVALID_HANDLE;
}
+ delete_on_close = (CVAL(pdata,0) ? True : False);
+ dosmode = dos_mode(conn, fname, psbuf);
+
status = can_set_delete_on_close(fsp, delete_on_close, dosmode);
if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
+ return status;
}
/* The set is across all open files on this dev/inode pair. */
if (!set_delete_on_close(fsp, delete_on_close, ¤t_user.ut)) {
- return ERROR_NT(NT_STATUS_ACCESS_DENIED);
+ return NT_STATUS_ACCESS_DENIED;
}
-
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, pdata, 0, max_data_bytes);
- return -1;
+ return NT_STATUS_OK;
}
/****************************************************************************
- Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
+ Deal with SMB_FILE_POSITION_INFORMATION.
****************************************************************************/
-static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
- unsigned int tran_call,
- char **pparams, int total_params, char **ppdata, int total_data,
- unsigned int max_data_bytes)
+static NTSTATUS smb_file_position_information(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp)
{
- char *params = *pparams;
- char *pdata = *ppdata;
- uint16 info_level;
- int dosmode=0;
- SMB_OFF_T size=0;
- struct utimbuf tvs;
- SMB_STRUCT_STAT sbuf;
- pstring fname;
- int fd = -1;
- files_struct *fsp = NULL;
- uid_t set_owner = (uid_t)SMB_UID_NO_CHANGE;
- gid_t set_grp = (uid_t)SMB_GID_NO_CHANGE;
- mode_t unixmode = 0;
- NTSTATUS status = NT_STATUS_OK;
+ SMB_BIG_UINT position_information;
- if (!params)
+ if (total_data < 8) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (fsp == NULL) {
+ /* Ignore on pathname based set. */
+ return NT_STATUS_OK;
+ }
+
+ position_information = (SMB_BIG_UINT)IVAL(pdata,0);
+#ifdef LARGE_SMB_OFF_T
+ position_information |= (((SMB_BIG_UINT)IVAL(pdata,4)) << 32);
+#else /* LARGE_SMB_OFF_T */
+ if (IVAL(pdata,4) != 0) {
+ /* more than 32 bits? */
return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
+#endif /* LARGE_SMB_OFF_T */
- ZERO_STRUCT(sbuf);
- ZERO_STRUCT(tvs);
+ DEBUG(10,("smb_file_position_information: Set file position information for file %s to %.0f\n",
+ fsp->fsp_name, (double)position_information ));
+ fsp->fh->position_information = position_information;
+ return NT_STATUS_OK;
+}
- if (tran_call == TRANSACT2_SETFILEINFO) {
- if (total_params < 4) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+/****************************************************************************
+ Deal with SMB_FILE_MODE_INFORMATION.
+****************************************************************************/
- fsp = file_fsp(params,0);
- info_level = SVAL(params,2);
+static NTSTATUS smb_file_mode_information(connection_struct *conn,
+ const char *pdata,
+ int total_data)
+{
+ uint32 mode;
- if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
- /*
- * This is actually a SETFILEINFO on a directory
- * handle (returned from an NT SMB). NT5.0 seems
- * to do this call. JRA.
- */
- pstrcpy(fname, fsp->fsp_name);
- if (SMB_VFS_STAT(conn,fname,&sbuf) != 0) {
- DEBUG(3,("call_trans2setfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
- return UNIXERROR(ERRDOS,ERRbadpath);
- }
- } else if (fsp && fsp->print_file) {
- /*
- * Doing a DELETE_ON_CLOSE should cancel a print job.
- */
- if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
- fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
+ if (total_data < 4) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ mode = IVAL(pdata,0);
+ if (mode != 0 && mode != 2 && mode != 4 && mode != 6) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ return NT_STATUS_OK;
+}
- DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
-
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
- } else
- return (UNIXERROR(ERRDOS,ERRbadpath));
- } else {
- /*
- * Original code - this is an open file.
- */
- CHECK_FSP(fsp,conn);
+/****************************************************************************
+ Deal with SMB_SET_FILE_UNIX_LINK (create a UNIX symlink).
+****************************************************************************/
- pstrcpy(fname, fsp->fsp_name);
- fd = fsp->fh->fd;
+static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
+ char *inbuf,
+ const char *pdata,
+ int total_data,
+ const char *fname)
+{
+ pstring link_target;
+ const char *newname = fname;
+ NTSTATUS status = NT_STATUS_OK;
- if (SMB_VFS_FSTAT(fsp,fd,&sbuf) != 0) {
- DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
- return(UNIXERROR(ERRDOS,ERRbadfid));
- }
- }
- } else {
- /* set path info */
- if (total_params < 7) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ /* Set a symbolic link. */
+ /* Don't allow this if follow links is false. */
- info_level = SVAL(params,0);
- srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), total_params - 6, STR_TERMINATE, &status);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
- }
- status = unix_convert(conn, fname, False, NULL, &sbuf);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
- }
+ if (total_data == 0) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- /*
- * For CIFS UNIX extensions the target name may not exist.
- */
+ if (!lp_symlinks(SNUM(conn))) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
- if(!VALID_STAT(sbuf) && !INFO_LEVEL_IS_UNIX(info_level)) {
- DEBUG(3,("call_trans2setfilepathinfo: stat of %s failed (%s)\n", fname, strerror(errno)));
- return UNIXERROR(ERRDOS,ERRbadpath);
- }
+ srvstr_pull(inbuf, link_target, pdata, sizeof(link_target), total_data, STR_TERMINATE);
- status = check_name(conn, fname);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
+ /* !widelinks forces the target path to be within the share. */
+ /* This means we can interpret the target as a pathname. */
+ if (!lp_widelinks(SNUM(conn))) {
+ pstring rel_name;
+ char *last_dirp = NULL;
+
+ unix_format(link_target);
+ if (*link_target == '/') {
+ /* No absolute paths allowed. */
+ return NT_STATUS_ACCESS_DENIED;
}
+ pstrcpy(rel_name, newname);
+ last_dirp = strrchr_m(rel_name, '/');
+ if (last_dirp) {
+ last_dirp[1] = '\0';
+ } else {
+ pstrcpy(rel_name, "./");
+ }
+ pstrcat(rel_name, link_target);
+ status = check_name(conn, rel_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
}
- if (!CAN_WRITE(conn))
- return ERROR_DOS(ERRSRV,ERRaccess);
+ DEBUG(10,("smb_set_file_unix_link: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
+ newname, link_target ));
- if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
- return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+ if (SMB_VFS_SYMLINK(conn,link_target,newname) != 0) {
+ return map_nt_error_from_unix(errno);
}
- if (VALID_STAT(sbuf))
- unixmode = sbuf.st_mode;
+ return NT_STATUS_OK;
+}
- 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 size */
- *pparams = (char *)SMB_REALLOC(*pparams,2);
- if (*pparams == NULL) {
- return ERROR_NT(NT_STATUS_NO_MEMORY);
- }
- params = *pparams;
+/****************************************************************************
+ Deal with SMB_SET_FILE_UNIX_HLINK (create a UNIX hard link).
+****************************************************************************/
- SSVAL(params,0,0);
+static NTSTATUS smb_set_file_unix_hlink(connection_struct *conn,
+ char *inbuf,
+ const char *pdata,
+ int total_data,
+ pstring fname)
+{
+ pstring oldname;
+ NTSTATUS status = NT_STATUS_OK;
- if (fsp && fsp->pending_modtime) {
- /* the pending modtime overrides the current modtime */
- sbuf.st_mtime = fsp->pending_modtime;
+ /* Set a hard link. */
+ if (total_data == 0) {
+ return NT_STATUS_INVALID_PARAMETER;
}
- size = get_file_size(sbuf);
- tvs.modtime = sbuf.st_mtime;
- tvs.actime = sbuf.st_atime;
- dosmode = dos_mode(conn,fname,&sbuf);
- unixmode = sbuf.st_mode;
+ srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), total_data, STR_TERMINATE, &status);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- set_owner = VALID_STAT(sbuf) ? sbuf.st_uid : (uid_t)SMB_UID_NO_CHANGE;
- set_grp = VALID_STAT(sbuf) ? sbuf.st_gid : (gid_t)SMB_GID_NO_CHANGE;
+ DEBUG(10,("smb_set_file_unix_hlink: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
+ fname, oldname));
- switch (info_level) {
- case SMB_INFO_STANDARD:
- {
- if (total_data < 12) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ return hardlink_internals(conn, oldname, fname);
+}
- /* access time */
- tvs.actime = srv_make_unix_date2(pdata+l1_fdateLastAccess);
- /* write time */
- tvs.modtime = srv_make_unix_date2(pdata+l1_fdateLastWrite);
- break;
- }
+/****************************************************************************
+ Deal with SMB_FILE_RENAME_INFORMATION.
+****************************************************************************/
- case SMB_INFO_SET_EA:
- return smb_info_set_ea(conn,
- outbuf,
- bufsize,
- params,
- total_params,
- *ppdata,
- total_data,
- max_data_bytes,
- fsp,
- fname);
+static NTSTATUS smb_file_rename_information(connection_struct *conn,
+ char *inbuf,
+ char *outbuf,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ pstring fname)
+{
+ BOOL overwrite;
+ /* uint32 root_fid; */ /* Not used */
+ uint32 len;
+ pstring newname;
+ pstring base_name;
+ NTSTATUS status = NT_STATUS_OK;
+ char *p;
- case SMB_SET_FILE_BASIC_INFO:
- case SMB_FILE_BASIC_INFORMATION:
- {
- /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
- time_t write_time;
- time_t changed_time;
+ if (total_data < 13) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- if (total_data < 36) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ overwrite = (CVAL(pdata,0) ? True : False);
+ /* root_fid = IVAL(pdata,4); */
+ len = IVAL(pdata,8);
- /* Ignore create time at offset pdata. */
+ if (len > (total_data - 12) || (len == 0)) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- /* access time */
- tvs.actime = convert_timespec_to_time_t(interpret_long_date(pdata+8));
+ srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- write_time = convert_timespec_to_time_t(interpret_long_date(pdata+16));
- changed_time = convert_timespec_to_time_t(interpret_long_date(pdata+24));
+ /* Check the new name has no '/' characters. */
+ if (strchr_m(newname, '/')) {
+ return NT_STATUS_NOT_SUPPORTED;
+ }
- tvs.modtime = MIN(write_time, changed_time);
+ RESOLVE_DFSPATH_STATUS(newname, conn, inbuf, outbuf);
- if (write_time > tvs.modtime && write_time != (time_t)-1) {
- tvs.modtime = write_time;
- }
- /* Prefer a defined time to an undefined one. */
- if (null_mtime(tvs.modtime)) {
- tvs.modtime = null_mtime(write_time) ? changed_time : write_time;
- }
+ /* Create the base directory. */
+ pstrcpy(base_name, fname);
+ p = strrchr_m(base_name, '/');
+ if (p) {
+ *p = '\0';
+ }
+ /* Append the new name. */
+ pstrcat(base_name, "/");
+ pstrcat(base_name, newname);
- /* attributes */
- dosmode = IVAL(pdata,32);
- break;
- }
+ 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, 0, overwrite);
+ } else {
+ DEBUG(10,("smb_file_rename_information: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
+ fname, newname ));
+ status = rename_internals(conn, fname, base_name, 0, overwrite, False);
+ }
- case SMB_FILE_ALLOCATION_INFORMATION:
- case SMB_SET_FILE_ALLOCATION_INFO:
- {
- int ret = -1;
- SMB_BIG_UINT allocation_size;
+ return status;
+}
- if (total_data < 8) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+/****************************************************************************
+ Deal with SMB_SET_POSIX_ACL.
+****************************************************************************/
- allocation_size = (SMB_BIG_UINT)IVAL(pdata,0);
-#ifdef LARGE_SMB_OFF_T
- allocation_size |= (((SMB_BIG_UINT)IVAL(pdata,4)) << 32);
-#else /* LARGE_SMB_OFF_T */
- if (IVAL(pdata,4) != 0) {
- /* more than 32 bits? */
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
-#endif /* LARGE_SMB_OFF_T */
- DEBUG(10,("call_trans2setfilepathinfo: Set file allocation info for file %s to %.0f\n",
- fname, (double)allocation_size ));
+#if defined(HAVE_POSIX_ACLS)
+static NTSTATUS smb_set_posix_acl(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
+{
+ uint16 posix_acl_version;
+ uint16 num_file_acls;
+ uint16 num_def_acls;
+ BOOL valid_file_acls = True;
+ BOOL valid_def_acls = True;
- if (allocation_size) {
- allocation_size = smb_roundup(conn, allocation_size);
- }
+ if (total_data < SMB_POSIX_ACL_HEADER_SIZE) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ posix_acl_version = SVAL(pdata,0);
+ num_file_acls = SVAL(pdata,2);
+ num_def_acls = SVAL(pdata,4);
- if(allocation_size != get_file_size(sbuf)) {
- SMB_STRUCT_STAT new_sbuf;
-
- DEBUG(10,("call_trans2setfilepathinfo: file %s : setting new allocation size to %.0f\n",
- fname, (double)allocation_size ));
-
- if (fd == -1) {
- files_struct *new_fsp = NULL;
-
- status = open_file_ntcreate(conn, fname, &sbuf,
- FILE_WRITE_DATA,
- FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OPEN,
- 0,
- FILE_ATTRIBUTE_NORMAL,
- FORCE_OPLOCK_BREAK_TO_NONE,
- NULL, &new_fsp);
-
- if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(SVAL(inbuf,smb_mid))) {
- /* We have re-scheduled this call. */
- return -1;
- }
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
- ret = vfs_allocate_file_space(new_fsp, allocation_size);
- if (SMB_VFS_FSTAT(new_fsp,new_fsp->fh->fd,&new_sbuf) != 0) {
- DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",
- new_fsp->fnum, strerror(errno)));
- ret = -1;
- }
- close_file(new_fsp,NORMAL_CLOSE);
- } else {
- ret = vfs_allocate_file_space(fsp, allocation_size);
- if (SMB_VFS_FSTAT(fsp,fd,&new_sbuf) != 0) {
- DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",
- fsp->fnum, strerror(errno)));
- ret = -1;
- }
- }
- if (ret == -1)
- return ERROR_NT(NT_STATUS_DISK_FULL);
+ if (num_file_acls == SMB_POSIX_IGNORE_ACE_ENTRIES) {
+ valid_file_acls = False;
+ num_file_acls = 0;
+ }
- /* Allocate can truncate size... */
- size = get_file_size(new_sbuf);
- }
+ if (num_def_acls == SMB_POSIX_IGNORE_ACE_ENTRIES) {
+ valid_def_acls = False;
+ num_def_acls = 0;
+ }
- break;
- }
+ if (posix_acl_version != SMB_POSIX_ACL_VERSION) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- case SMB_FILE_END_OF_FILE_INFORMATION:
- case SMB_SET_FILE_END_OF_FILE_INFO:
- {
- if (total_data < 8) {
- 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 NT_STATUS_INVALID_PARAMETER;
+ }
- size = IVAL(pdata,0);
-#ifdef LARGE_SMB_OFF_T
- size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
-#else /* LARGE_SMB_OFF_T */
- if (IVAL(pdata,4) != 0) {
- /* more than 32 bits? */
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
-#endif /* LARGE_SMB_OFF_T */
- DEBUG(10,("call_trans2setfilepathinfo: Set end of file info for file %s to %.0f\n", fname, (double)size ));
- break;
- }
+ if (valid_file_acls && !set_unix_posix_acl(conn, fsp, fname, num_file_acls,
+ pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
+ return map_nt_error_from_unix(errno);
+ }
- case SMB_FILE_DISPOSITION_INFORMATION:
- case SMB_SET_FILE_DISPOSITION_INFO: /* Set delete on close for open file. */
- {
- if (total_data < 1) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ if (valid_def_acls && !set_unix_posix_default_acl(conn, fname, psbuf, num_def_acls,
+ pdata + SMB_POSIX_ACL_HEADER_SIZE +
+ (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE))) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_OK;
+}
+#endif
- /* Just ignore this set on a path. */
- if (tran_call != TRANSACT2_SETFILEINFO) {
- break;
- }
+/****************************************************************************
+ Deal with SMB_SET_POSIX_LOCK.
+****************************************************************************/
- return smb_set_file_disposition_info(conn,
- outbuf,
- bufsize,
- params,
- total_params,
- *ppdata,
- total_data,
- max_data_bytes,
- fsp,
- dosmode);
- }
+static NTSTATUS smb_set_posix_lock(connection_struct *conn,
+ char *inbuf,
+ int length,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp)
+{
+ SMB_BIG_UINT count;
+ SMB_BIG_UINT offset;
+ uint32 lock_pid;
+ BOOL blocking_lock = False;
+ enum brl_type lock_type;
+ NTSTATUS status = NT_STATUS_OK;
- case SMB_FILE_POSITION_INFORMATION:
- {
- SMB_BIG_UINT position_information;
+ if (fsp == NULL || fsp->fh->fd == -1) {
+ return NT_STATUS_INVALID_HANDLE;
+ }
- if (total_data < 8) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ if (total_data != POSIX_LOCK_DATA_SIZE) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- position_information = (SMB_BIG_UINT)IVAL(pdata,0);
-#ifdef LARGE_SMB_OFF_T
- position_information |= (((SMB_BIG_UINT)IVAL(pdata,4)) << 32);
-#else /* LARGE_SMB_OFF_T */
- if (IVAL(pdata,4) != 0) {
- /* more than 32 bits? */
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
-#endif /* LARGE_SMB_OFF_T */
- DEBUG(10,("call_trans2setfilepathinfo: Set file position information for file %s to %.0f\n",
- fname, (double)position_information ));
- if (fsp) {
- fsp->fh->position_information = position_information;
+ switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
+ case POSIX_LOCK_TYPE_READ:
+ lock_type = READ_LOCK;
+ break;
+ case POSIX_LOCK_TYPE_WRITE:
+ /* Return the right POSIX-mappable error code for files opened read-only. */
+ if (!fsp->can_write) {
+ return NT_STATUS_INVALID_HANDLE;
}
+ lock_type = WRITE_LOCK;
+ break;
+ case POSIX_LOCK_TYPE_UNLOCK:
+ lock_type = UNLOCK_LOCK;
+ break;
+ default:
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- /* We're done. We only get position info in this call. */
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
- }
+ if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_NOWAIT) {
+ blocking_lock = False;
+ } else if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_WAIT) {
+ blocking_lock = True;
+ } else {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- /* 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?).
- */
+ if (!lp_blocking_locks(SNUM(conn))) {
+ blocking_lock = False;
+ }
- case SMB_FILE_MODE_INFORMATION:
- {
- uint32 mode;
+ lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
+#if defined(HAVE_LONGLONG)
+ offset = (((SMB_BIG_UINT) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
+ ((SMB_BIG_UINT) IVAL(pdata,POSIX_LOCK_START_OFFSET));
+ count = (((SMB_BIG_UINT) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
+ ((SMB_BIG_UINT) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
+#else /* HAVE_LONGLONG */
+ offset = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_START_OFFSET);
+ count = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
+#endif /* HAVE_LONGLONG */
- 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);
+ if (lock_type == UNLOCK_LOCK) {
+ status = do_unlock(fsp,
+ lock_pid,
+ count,
+ offset,
+ POSIX_LOCK);
+ } else {
+ struct byte_range_lock *br_lck = do_lock(fsp,
+ lock_pid,
+ count,
+ offset,
+ lock_type,
+ POSIX_LOCK,
+ blocking_lock,
+ &status);
+
+ if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
+ /*
+ * A blocking lock was requested. Package up
+ * this smb into a queued request and push it
+ * onto the blocking lock queue.
+ */
+ if(push_blocking_lock_request(br_lck,
+ inbuf, length,
+ fsp,
+ -1, /* infinite timeout. */
+ 0,
+ lock_pid,
+ lock_type,
+ POSIX_LOCK,
+ offset,
+ count)) {
+ TALLOC_FREE(br_lck);
+ return status;
}
-
- /* We're done. We only get mode info in this call. */
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
}
+ TALLOC_FREE(br_lck);
+ }
- /*
- * CIFS UNIX extensions.
- */
+ return status;
+}
- case SMB_SET_FILE_UNIX_BASIC:
- {
- uint32 raw_unixmode;
- BOOL delete_on_fail = False;
+/****************************************************************************
+ Deal with SMB_INFO_STANDARD.
+****************************************************************************/
- if (total_data < 100) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+static NTSTATUS smb_set_info_standard(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ const char *fname,
+ const SMB_STRUCT_STAT *psbuf)
+{
+ struct utimbuf tvs;
- if(IVAL(pdata, 0) != SMB_SIZE_NO_CHANGE_LO &&
- IVAL(pdata, 4) != SMB_SIZE_NO_CHANGE_HI) {
- size=IVAL(pdata,0); /* first 8 Bytes are size */
-#ifdef LARGE_SMB_OFF_T
- size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
-#else /* LARGE_SMB_OFF_T */
- if (IVAL(pdata,4) != 0) {
- /* more than 32 bits? */
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
-#endif /* LARGE_SMB_OFF_T */
- }
- pdata+=24; /* ctime & st_blocks are not changed */
- tvs.actime = convert_timespec_to_time_t(interpret_long_date(pdata)); /* access_time */
- tvs.modtime = convert_timespec_to_time_t(interpret_long_date(pdata+8)); /* modification_time */
- pdata+=16;
- set_owner = (uid_t)IVAL(pdata,0);
- pdata += 8;
- set_grp = (gid_t)IVAL(pdata,0);
- pdata += 8;
- raw_unixmode = IVAL(pdata,28);
- unixmode = unix_perms_from_wire(conn, &sbuf, raw_unixmode);
- dosmode = 0; /* Ensure dos mode change doesn't override this. */
+ if (total_data < 12) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- DEBUG(10,("call_trans2setfilepathinfo: 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));
+ /* access time */
+ tvs.actime = srv_make_unix_date2(pdata+l1_fdateLastAccess);
+ /* write time */
+ tvs.modtime = srv_make_unix_date2(pdata+l1_fdateLastWrite);
- if (!VALID_STAT(sbuf)) {
+ return smb_set_file_time(conn,
+ fsp,
+ fname,
+ psbuf,
+ tvs);
+}
- /*
- * The only valid use of this is to create character and block
- * devices, and named pipes. This is deprecated (IMHO) and
- * a new info level should be used for mknod. JRA.
- */
+/****************************************************************************
+ Deal with SMB_SET_FILE_BASIC_INFO.
+****************************************************************************/
- uint32 file_type = IVAL(pdata,0);
-#if defined(HAVE_MAKEDEV)
- uint32 dev_major = IVAL(pdata,4);
- uint32 dev_minor = IVAL(pdata,12);
-#endif
+static NTSTATUS smb_set_file_basic_info(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
+{
+ /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
+ time_t write_time;
+ time_t changed_time;
+ uint32 dosmode = 0;
+ struct utimbuf tvs;
+ NTSTATUS status = NT_STATUS_OK;
- SMB_DEV_T dev = (SMB_DEV_T)0;
+ if (total_data < 36) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- if (tran_call == TRANSACT2_SETFILEINFO)
- return(ERROR_DOS(ERRDOS,ERRnoaccess));
+ /* Set the attributes */
+ dosmode = IVAL(pdata,32);
+ status = smb_set_file_dosmode(conn,
+ fname,
+ psbuf,
+ dosmode);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if (raw_unixmode == SMB_MODE_NO_CHANGE) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ /* Ignore create time at offset pdata. */
-#if defined(HAVE_MAKEDEV)
- dev = makedev(dev_major, dev_minor);
-#endif
+ /* access time */
+ tvs.actime = convert_timespec_to_time_t(interpret_long_date(pdata+8));
- switch (file_type) {
-#if defined(S_IFIFO)
- case UNIX_TYPE_FIFO:
- unixmode |= S_IFIFO;
- break;
-#endif
-#if defined(S_IFSOCK)
- case UNIX_TYPE_SOCKET:
- unixmode |= S_IFSOCK;
- break;
-#endif
-#if defined(S_IFCHR)
- case UNIX_TYPE_CHARDEV:
- unixmode |= S_IFCHR;
- break;
-#endif
-#if defined(S_IFBLK)
- case UNIX_TYPE_BLKDEV:
- unixmode |= S_IFBLK;
- break;
-#endif
- default:
- return(ERROR_DOS(ERRDOS,ERRnoaccess));
- }
+ write_time = convert_timespec_to_time_t(interpret_long_date(pdata+16));
+ changed_time = convert_timespec_to_time_t(interpret_long_date(pdata+24));
- DEBUG(10,("call_trans2setfilepathinfo: SMB_SET_FILE_UNIX_BASIC doing mknod dev %.0f mode \
-0%o for file %s\n", (double)dev, unixmode, fname ));
+ tvs.modtime = MIN(write_time, changed_time);
- /* Ok - do the mknod. */
- if (SMB_VFS_MKNOD(conn,fname, unixmode, dev) != 0) {
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
+ if (write_time > tvs.modtime && write_time != (time_t)-1) {
+ tvs.modtime = write_time;
+ }
+ /* Prefer a defined time to an undefined one. */
+ if (null_mtime(tvs.modtime)) {
+ tvs.modtime = null_mtime(write_time) ? changed_time : write_time;
+ }
- /* If any of the other "set" calls fail we
- * don't want to end up with a half-constructed mknod.
- */
+ return smb_set_file_time(conn,
+ fsp,
+ fname,
+ psbuf,
+ tvs);
+}
- delete_on_fail = True;
+/****************************************************************************
+ Deal with SMB_SET_FILE_ALLOCATION_INFO.
+****************************************************************************/
- if (lp_inherit_perms(SNUM(conn))) {
- inherit_access_acl(
- conn, parent_dirname(fname),
- fname, unixmode);
- }
+static NTSTATUS smb_set_file_allocation_info(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
+{
+ SMB_BIG_UINT allocation_size = 0;
+ NTSTATUS status = NT_STATUS_OK;
+ files_struct *new_fsp = NULL;
- if (SMB_VFS_STAT(conn, fname, &sbuf) != 0) {
- int saved_errno = errno;
- SMB_VFS_UNLINK(conn,fname);
- errno = saved_errno;
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
+ if (!VALID_STAT(*psbuf)) {
+ return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+ }
- /* Ensure we don't try and change anything else. */
- raw_unixmode = SMB_MODE_NO_CHANGE;
- size = get_file_size(sbuf);
- tvs.modtime = sbuf.st_mtime;
- tvs.actime = sbuf.st_atime;
- }
+ if (total_data < 8) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- /*
- * Deal with the UNIX specific mode set.
- */
+ allocation_size = (SMB_BIG_UINT)IVAL(pdata,0);
+#ifdef LARGE_SMB_OFF_T
+ allocation_size |= (((SMB_BIG_UINT)IVAL(pdata,4)) << 32);
+#else /* LARGE_SMB_OFF_T */
+ if (IVAL(pdata,4) != 0) {
+ /* more than 32 bits? */
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+#endif /* LARGE_SMB_OFF_T */
- if (raw_unixmode != SMB_MODE_NO_CHANGE) {
- DEBUG(10,("call_trans2setfilepathinfo: 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)
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
+ DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for file %s to %.0f\n",
+ fname, (double)allocation_size ));
- /*
- * Deal with the UNIX specific uid set.
- */
+ if (allocation_size) {
+ allocation_size = smb_roundup(conn, allocation_size);
+ }
- if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) && (sbuf.st_uid != set_owner)) {
- DEBUG(10,("call_trans2setfilepathinfo: SMB_SET_FILE_UNIX_BASIC changing owner %u for file %s\n",
- (unsigned int)set_owner, fname ));
- if (SMB_VFS_CHOWN(conn,fname,set_owner, (gid_t)-1) != 0) {
- if (delete_on_fail) {
- int saved_errno = errno;
- SMB_VFS_UNLINK(conn,fname);
- errno = saved_errno;
- }
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
- }
+ if(allocation_size == get_file_size(*psbuf)) {
+ return NT_STATUS_OK;
+ }
+
+ DEBUG(10,("smb_set_file_allocation_info: file %s : setting new allocation size to %.0f\n",
+ fname, (double)allocation_size ));
+
+ if (fsp && fsp->fh->fd != -1) {
+ /* Open file handle. */
+ if (vfs_allocate_file_space(fsp, allocation_size) == -1) {
+ return map_nt_error_from_unix(errno);
+ }
+ return NT_STATUS_OK;
+ }
- /*
- * Deal with the UNIX specific gid set.
- */
+ /* Pathname or stat or directory file. */
- if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) && (sbuf.st_gid != set_grp)) {
- DEBUG(10,("call_trans2setfilepathinfo: 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 (delete_on_fail) {
- int saved_errno = errno;
- SMB_VFS_UNLINK(conn,fname);
- errno = saved_errno;
- }
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
- }
- break;
- }
+ status = open_file_ntcreate(conn, fname, psbuf,
+ FILE_WRITE_DATA,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN,
+ 0,
+ FILE_ATTRIBUTE_NORMAL,
+ FORCE_OPLOCK_BREAK_TO_NONE,
+ NULL, &new_fsp);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ /* NB. We check for open_was_deferred in the caller. */
+ return status;
+ }
+ if (vfs_allocate_file_space(new_fsp, allocation_size) == -1) {
+ status = map_nt_error_from_unix(errno);
+ close_file(new_fsp,NORMAL_CLOSE);
+ return status;
+ }
- case SMB_SET_FILE_UNIX_LINK:
- {
- pstring link_target;
- char *newname = fname;
+ close_file(new_fsp,NORMAL_CLOSE);
+ return NT_STATUS_OK;
+}
- /* Set a symbolic link. */
- /* Don't allow this if follow links is false. */
+/****************************************************************************
+ Deal with SMB_SET_FILE_END_OF_FILE_INFO.
+****************************************************************************/
- if (total_data == 0) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+static NTSTATUS smb_set_file_end_of_file_info(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
+{
+ SMB_OFF_T size;
- if (!lp_symlinks(SNUM(conn)))
- return(ERROR_DOS(ERRDOS,ERRnoaccess));
+ if (total_data < 8) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- srvstr_pull(inbuf, link_target, pdata, sizeof(link_target), total_data, STR_TERMINATE);
+ size = IVAL(pdata,0);
+#ifdef LARGE_SMB_OFF_T
+ size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
+#else /* LARGE_SMB_OFF_T */
+ if (IVAL(pdata,4) != 0) {
+ /* more than 32 bits? */
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+#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 ));
+
+ return smb_set_file_size(conn,
+ fsp,
+ fname,
+ psbuf,
+ size);
+}
- /* !widelinks forces the target path to be within the share. */
- /* This means we can interpret the target as a pathname. */
- if (!lp_widelinks(SNUM(conn))) {
- pstring rel_name;
- char *last_dirp = NULL;
+/****************************************************************************
+ Allow a UNIX info mknod.
+****************************************************************************/
- unix_format(link_target);
- if (*link_target == '/') {
- /* No absolute paths allowed. */
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
- pstrcpy(rel_name, newname);
- last_dirp = strrchr_m(rel_name, '/');
- if (last_dirp) {
- last_dirp[1] = '\0';
- } else {
- pstrcpy(rel_name, "./");
- }
- pstrcat(rel_name, link_target);
+static NTSTATUS smb_unix_mknod(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
+{
+ uint32 file_type = IVAL(pdata,56);
+#if defined(HAVE_MAKEDEV)
+ uint32 dev_major = IVAL(pdata,60);
+ uint32 dev_minor = IVAL(pdata,68);
+#endif
+ SMB_DEV_T dev = (SMB_DEV_T)0;
+ uint32 raw_unixmode = IVAL(pdata,84);
+ NTSTATUS status;
+ mode_t unixmode;
- status = check_name(conn, rel_name);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
- }
- }
+ if (total_data < 100) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- DEBUG(10,("call_trans2setfilepathinfo: SMB_SET_FILE_UNIX_LINK doing symlink %s -> %s\n",
- fname, link_target ));
+ status = unix_perms_from_wire(conn, psbuf, raw_unixmode, PERM_NEW_FILE, &unixmode);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if (SMB_VFS_SYMLINK(conn,link_target,newname) != 0)
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
- }
+#if defined(HAVE_MAKEDEV)
+ dev = makedev(dev_major, dev_minor);
+#endif
- case SMB_SET_FILE_UNIX_HLINK:
- {
- pstring oldname;
- char *newname = fname;
+ switch (file_type) {
+#if defined(S_IFIFO)
+ case UNIX_TYPE_FIFO:
+ unixmode |= S_IFIFO;
+ break;
+#endif
+#if defined(S_IFSOCK)
+ case UNIX_TYPE_SOCKET:
+ unixmode |= S_IFSOCK;
+ break;
+#endif
+#if defined(S_IFCHR)
+ case UNIX_TYPE_CHARDEV:
+ unixmode |= S_IFCHR;
+ break;
+#endif
+#if defined(S_IFBLK)
+ case UNIX_TYPE_BLKDEV:
+ unixmode |= S_IFBLK;
+ break;
+#endif
+ default:
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- /* Set a hard link. */
- if (total_data == 0) {
- return ERROR_NT(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 ));
- srvstr_get_path(inbuf, oldname, pdata, sizeof(oldname), total_data, STR_TERMINATE, &status);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
- }
+ /* Ok - do the mknod. */
+ if (SMB_VFS_MKNOD(conn, fname, unixmode, dev) != 0) {
+ return map_nt_error_from_unix(errno);
+ }
- DEBUG(10,("call_trans2setfilepathinfo: SMB_SET_FILE_UNIX_LINK doing hard link %s -> %s\n",
- fname, oldname));
+ /* If any of the other "set" calls fail we
+ * don't want to end up with a half-constructed mknod.
+ */
- status = hardlink_internals(conn, oldname, newname);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
- }
+ if (lp_inherit_perms(SNUM(conn))) {
+ inherit_access_acl(
+ conn, parent_dirname(fname),
+ fname, unixmode);
+ }
+
+ if (SMB_VFS_STAT(conn, fname, psbuf) != 0) {
+ status = map_nt_error_from_unix(errno);
+ SMB_VFS_UNLINK(conn,fname);
+ return status;
+ }
+ return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Deal with SMB_SET_FILE_UNIX_BASIC.
+****************************************************************************/
+
+static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
+ const char *pdata,
+ int total_data,
+ files_struct *fsp,
+ const char *fname,
+ SMB_STRUCT_STAT *psbuf)
+{
+ struct utimbuf tvs;
+ uint32 raw_unixmode;
+ mode_t unixmode;
+ SMB_OFF_T size = 0;
+ uid_t set_owner = (uid_t)SMB_UID_NO_CHANGE;
+ gid_t set_grp = (uid_t)SMB_GID_NO_CHANGE;
+ NTSTATUS status = NT_STATUS_OK;
+ BOOL delete_on_fail = False;
+ enum perm_type ptype;
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
+ if (total_data < 100) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if(IVAL(pdata, 0) != SMB_SIZE_NO_CHANGE_LO &&
+ IVAL(pdata, 4) != SMB_SIZE_NO_CHANGE_HI) {
+ size=IVAL(pdata,0); /* first 8 Bytes are size */
+#ifdef LARGE_SMB_OFF_T
+ size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
+#else /* LARGE_SMB_OFF_T */
+ if (IVAL(pdata,4) != 0) {
+ /* more than 32 bits? */
+ return NT_STATUS_INVALID_PARAMETER;
}
+#endif /* LARGE_SMB_OFF_T */
+ }
- case SMB_FILE_RENAME_INFORMATION:
- {
- BOOL overwrite;
- /* uint32 root_fid; */ /* Not used */
- uint32 len;
- pstring newname;
- pstring base_name;
- char *p;
+ tvs.actime = convert_timespec_to_time_t(interpret_long_date(pdata+24)); /* access_time */
+ tvs.modtime = convert_timespec_to_time_t(interpret_long_date(pdata+32)); /* modification_time */
+ set_owner = (uid_t)IVAL(pdata,40);
+ set_grp = (gid_t)IVAL(pdata,48);
+ raw_unixmode = IVAL(pdata,84);
- if (total_data < 13) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ if (VALID_STAT(*psbuf)) {
+ if (S_ISDIR(psbuf->st_mode)) {
+ ptype = PERM_EXISTING_DIR;
+ } else {
+ ptype = PERM_EXISTING_FILE;
+ }
+ } else {
+ ptype = PERM_NEW_FILE;
+ }
- overwrite = (CVAL(pdata,0) ? True : False);
- /* root_fid = IVAL(pdata,4); */
- len = IVAL(pdata,8);
+ status = unix_perms_from_wire(conn, psbuf, raw_unixmode, ptype, &unixmode);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if (len > (total_data - 12) || (len == 0)) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ 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));
- srvstr_get_path(inbuf, newname, &pdata[12], sizeof(newname), len, 0, &status);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
- }
+ if (!VALID_STAT(*psbuf)) {
+ /*
+ * The only valid use of this is to create character and block
+ * devices, and named pipes. This is deprecated (IMHO) and
+ * a new info level should be used for mknod. JRA.
+ */
- /* Check the new name has no '/' characters. */
- if (strchr_m(newname, '/'))
- return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
-
- RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
-
- /* Create the base directory. */
- pstrcpy(base_name, fname);
- p = strrchr_m(base_name, '/');
- if (p)
- *p = '\0';
- /* Append the new name. */
- pstrcat(base_name, "/");
- pstrcat(base_name, newname);
-
- if (fsp) {
- DEBUG(10,("call_trans2setfilepathinfo: SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
- fsp->fnum, fsp->fsp_name, base_name ));
- status = rename_internals_fsp(conn, fsp, base_name, 0, overwrite);
- } else {
- DEBUG(10,("call_trans2setfilepathinfo: SMB_FILE_RENAME_INFORMATION %s -> %s\n",
- fname, newname ));
- status = rename_internals(conn, fname, base_name, 0, overwrite, False);
- }
+ status = smb_unix_mknod(conn,
+ pdata,
+ total_data,
+ fname,
+ psbuf);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(SVAL(inbuf,smb_mid))) {
- /* We have re-scheduled this call. */
- return -1;
- }
- return ERROR_NT(status);
- }
+ /* Ensure we don't try and change anything else. */
+ raw_unixmode = SMB_MODE_NO_CHANGE;
+ size = get_file_size(*psbuf);
+ tvs.modtime = psbuf->st_mtime;
+ tvs.actime = psbuf->st_atime;
+ /*
+ * We continue here as we might want to change the
+ * owner uid/gid.
+ */
+ delete_on_fail = True;
+ }
+
+ /*
+ * Deal with the UNIX specific mode set.
+ */
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
+ 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) {
+ return map_nt_error_from_unix(errno);
}
+ }
-#if defined(HAVE_POSIX_ACLS)
- case SMB_SET_POSIX_ACL:
- {
- uint16 posix_acl_version;
- uint16 num_file_acls;
- uint16 num_def_acls;
- BOOL valid_file_acls = True;
- BOOL valid_def_acls = True;
+ /*
+ * Deal with the UNIX specific uid set.
+ */
- if (total_data < SMB_POSIX_ACL_HEADER_SIZE) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ if ((set_owner != (uid_t)SMB_UID_NO_CHANGE) && (psbuf->st_uid != set_owner)) {
+ DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC changing owner %u for file %s\n",
+ (unsigned int)set_owner, fname ));
+ if (SMB_VFS_CHOWN(conn, fname, set_owner, (gid_t)-1) != 0) {
+ status = map_nt_error_from_unix(errno);
+ if (delete_on_fail) {
+ SMB_VFS_UNLINK(conn,fname);
}
- posix_acl_version = SVAL(pdata,0);
- num_file_acls = SVAL(pdata,2);
- num_def_acls = SVAL(pdata,4);
+ return status;
+ }
+ }
- if (num_file_acls == SMB_POSIX_IGNORE_ACE_ENTRIES) {
- valid_file_acls = False;
- num_file_acls = 0;
- }
+ /*
+ * Deal with the UNIX specific gid set.
+ */
- if (num_def_acls == SMB_POSIX_IGNORE_ACE_ENTRIES) {
- valid_def_acls = False;
- num_def_acls = 0;
+ if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) && (psbuf->st_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) {
+ status = map_nt_error_from_unix(errno);
+ if (delete_on_fail) {
+ SMB_VFS_UNLINK(conn,fname);
}
+ return status;
+ }
+ }
- if (posix_acl_version != SMB_POSIX_ACL_VERSION) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ /* Deal with any size changes. */
- if (total_data < SMB_POSIX_ACL_HEADER_SIZE +
- (num_file_acls+num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ status = smb_set_file_size(conn,
+ fsp,
+ fname,
+ psbuf,
+ size);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
- if (valid_file_acls && !set_unix_posix_acl(conn, fsp, fname, num_file_acls,
- pdata + SMB_POSIX_ACL_HEADER_SIZE)) {
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
+ /* Deal with any time changes. */
- if (valid_def_acls && !set_unix_posix_default_acl(conn, fname, &sbuf, num_def_acls,
- pdata + SMB_POSIX_ACL_HEADER_SIZE +
- (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE))) {
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
+ return smb_set_file_time(conn,
+ fsp,
+ fname,
+ psbuf,
+ tvs);
+}
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
- }
-#endif
+/****************************************************************************
+ Reply to a TRANS2_SETFILEINFO (set file info by fileid or pathname).
+****************************************************************************/
- case SMB_SET_POSIX_LOCK:
- {
- SMB_BIG_UINT count;
- SMB_BIG_UINT offset;
- uint32 lock_pid;
- BOOL blocking_lock = False;
- enum brl_type lock_type;
+static int call_trans2setfilepathinfo(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
+ 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;
+ SMB_STRUCT_STAT sbuf;
+ pstring fname;
+ files_struct *fsp = NULL;
+ NTSTATUS status = NT_STATUS_OK;
- if (fsp == NULL || fsp->fh->fd == -1) {
- return ERROR_NT(NT_STATUS_INVALID_HANDLE);
- }
+ if (!params) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
- if (total_data != POSIX_LOCK_DATA_SIZE) {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ ZERO_STRUCT(sbuf);
- switch (SVAL(pdata, POSIX_LOCK_TYPE_OFFSET)) {
- case POSIX_LOCK_TYPE_READ:
- lock_type = READ_LOCK;
- break;
- case POSIX_LOCK_TYPE_WRITE:
- /* Return the right POSIX-mappable error code for files opened read-only. */
- if (!fsp->can_write) {
- return ERROR_NT(NT_STATUS_INVALID_HANDLE);
- }
- lock_type = WRITE_LOCK;
- break;
- case POSIX_LOCK_TYPE_UNLOCK:
- lock_type = UNLOCK_LOCK;
- break;
- default:
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ if (tran_call == TRANSACT2_SETFILEINFO) {
+ if (total_params < 4) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
- if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_NOWAIT) {
- blocking_lock = False;
- } else if (SVAL(pdata,POSIX_LOCK_FLAGS_OFFSET) == POSIX_LOCK_FLAG_WAIT) {
- blocking_lock = True;
- } else {
- return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
- }
+ fsp = file_fsp(params,0);
+ info_level = SVAL(params,2);
- if (!lp_blocking_locks(SNUM(conn))) {
- blocking_lock = False;
+ if(fsp && (fsp->is_directory || fsp->fh->fd == -1)) {
+ /*
+ * This is actually a SETFILEINFO on a directory
+ * handle (returned from an NT SMB). NT5.0 seems
+ * to do this call. JRA.
+ */
+ pstrcpy(fname, fsp->fsp_name);
+ if (SMB_VFS_STAT(conn,fname,&sbuf) != 0) {
+ DEBUG(3,("call_trans2setfilepathinfo: fileinfo of %s failed (%s)\n",fname,strerror(errno)));
+ return UNIXERROR(ERRDOS,ERRbadpath);
}
+ } else if (fsp && fsp->print_file) {
+ /*
+ * Doing a DELETE_ON_CLOSE should cancel a print job.
+ */
+ if ((info_level == SMB_SET_FILE_DISPOSITION_INFO) && CVAL(pdata,0)) {
+ fsp->fh->private_options |= FILE_DELETE_ON_CLOSE;
- lock_pid = IVAL(pdata, POSIX_LOCK_PID_OFFSET);
-#if defined(HAVE_LONGLONG)
- offset = (((SMB_BIG_UINT) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
- ((SMB_BIG_UINT) IVAL(pdata,POSIX_LOCK_START_OFFSET));
- count = (((SMB_BIG_UINT) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
- ((SMB_BIG_UINT) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
-#else /* HAVE_LONGLONG */
- offset = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_START_OFFSET);
- count = (SMB_BIG_UINT)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
-#endif /* HAVE_LONGLONG */
+ DEBUG(3,("call_trans2setfilepathinfo: Cancelling print job (%s)\n", fsp->fsp_name ));
+
+ SSVAL(params,0,0);
+ send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
+ return(-1);
+ } else
+ return (UNIXERROR(ERRDOS,ERRbadpath));
+ } else {
+ /*
+ * Original code - this is an open file.
+ */
+ CHECK_FSP(fsp,conn);
- if (lock_type == UNLOCK_LOCK) {
- status = do_unlock(fsp,
- lock_pid,
- count,
- offset,
- POSIX_LOCK);
- } else {
- struct byte_range_lock *br_lck = do_lock(fsp,
- lock_pid,
- count,
- offset,
- lock_type,
- POSIX_LOCK,
- blocking_lock,
- &status);
-
- if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
- /*
- * A blocking lock was requested. Package up
- * this smb into a queued request and push it
- * onto the blocking lock queue.
- */
- if(push_blocking_lock_request(br_lck,
- inbuf, length,
- fsp,
- -1, /* infinite timeout. */
- 0,
- lock_pid,
- lock_type,
- POSIX_LOCK,
- offset,
- count)) {
- TALLOC_FREE(br_lck);
- return -1;
- }
- }
- TALLOC_FREE(br_lck);
- }
+ pstrcpy(fname, fsp->fsp_name);
- if (!NT_STATUS_IS_OK(status)) {
- return ERROR_NT(status);
+ if (SMB_VFS_FSTAT(fsp, fsp->fh->fd, &sbuf) != 0) {
+ DEBUG(3,("call_trans2setfilepathinfo: fstat of fnum %d failed (%s)\n",fsp->fnum, strerror(errno)));
+ return(UNIXERROR(ERRDOS,ERRbadfid));
}
+ }
+ } else {
+ /* set path info */
+ if (total_params < 7) {
+ return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
+ }
- SSVAL(params,0,0);
- send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
+ info_level = SVAL(params,0);
+ srvstr_get_path(inbuf, fname, ¶ms[6], sizeof(fname), total_params - 6, STR_TERMINATE, &status);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ERROR_NT(status);
+ }
+ status = unix_convert(conn, fname, False, NULL, &sbuf);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ERROR_NT(status);
+ }
+
+ /*
+ * For CIFS UNIX extensions the target name may not exist.
+ */
+
+ if(!VALID_STAT(sbuf) && !INFO_LEVEL_IS_UNIX(info_level)) {
+ DEBUG(3,("call_trans2setfilepathinfo: stat of %s failed (%s)\n", fname, strerror(errno)));
+ return UNIXERROR(ERRDOS,ERRbadpath);
+ }
+
+ status = check_name(conn, fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ERROR_NT(status);
}
- default:
- return ERROR_NT(NT_STATUS_INVALID_LEVEL);
}
- /* get some defaults (no modifications) if any info is zero or -1. */
- if (null_mtime(tvs.actime)) {
- tvs.actime = sbuf.st_atime;
+ if (!CAN_WRITE(conn)) {
+ return ERROR_DOS(ERRSRV,ERRaccess);
}
- if (null_mtime(tvs.modtime)) {
- tvs.modtime = sbuf.st_mtime;
+ if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
+ return ERROR_NT(NT_STATUS_INVALID_LEVEL);
}
- DEBUG(6,("actime: %s " , ctime(&tvs.actime)));
- DEBUG(6,("modtime: %s ", ctime(&tvs.modtime)));
- DEBUG(6,("size: %.0f ", (double)size));
+ 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));
- if (dosmode) {
- if (S_ISDIR(sbuf.st_mode))
- dosmode |= aDIR;
- else
- dosmode &= ~aDIR;
+ /* Realloc the parameter size */
+ *pparams = (char *)SMB_REALLOC(*pparams,2);
+ if (*pparams == NULL) {
+ return ERROR_NT(NT_STATUS_NO_MEMORY);
}
+ params = *pparams;
- DEBUG(6,("dosmode: %x\n" , dosmode));
-
- if(!((info_level == SMB_SET_FILE_END_OF_FILE_INFO) ||
- (info_level == SMB_SET_FILE_ALLOCATION_INFO) ||
- (info_level == SMB_FILE_ALLOCATION_INFORMATION) ||
- (info_level == SMB_FILE_END_OF_FILE_INFORMATION))) {
+ SSVAL(params,0,0);
- /*
- * Only do this test if we are not explicitly
- * changing the size of a file.
- */
- if (!size)
- size = get_file_size(sbuf);
+ if (fsp && fsp->pending_modtime) {
+ /* the pending modtime overrides the current modtime */
+ sbuf.st_mtime = fsp->pending_modtime;
}
- /*
- * Try and set the times, size and mode of this file -
- * if they are different from the current values
- */
+ switch (info_level) {
- /* check the mode isn't different, before changing it */
- if ((dosmode != 0) && (dosmode != dos_mode(conn, fname, &sbuf))) {
+ case SMB_INFO_STANDARD:
+ {
+ status = smb_set_info_standard(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
+ }
- DEBUG(10,("call_trans2setfilepathinfo: file %s : setting dos mode %x\n", fname, dosmode ));
+ case SMB_INFO_SET_EA:
+ {
+ status = smb_info_set_ea(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname);
+ break;
+ }
- if(file_set_dosmode(conn, fname, dosmode, &sbuf, False)) {
- DEBUG(2,("file_set_dosmode of %s failed (%s)\n", fname, strerror(errno)));
- return(UNIXERROR(ERRDOS,ERRnoaccess));
+ case SMB_SET_FILE_BASIC_INFO:
+ case SMB_FILE_BASIC_INFORMATION:
+ {
+ status = smb_set_file_basic_info(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
}
- }
- /* Now the size. */
- if (size != get_file_size(sbuf)) {
+ case SMB_FILE_ALLOCATION_INFORMATION:
+ case SMB_SET_FILE_ALLOCATION_INFO:
+ {
+ status = smb_set_file_allocation_info(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
+ }
- int ret;
+ case SMB_FILE_END_OF_FILE_INFORMATION:
+ case SMB_SET_FILE_END_OF_FILE_INFO:
+ {
+ status = smb_set_file_end_of_file_info(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
+ }
+
+ case SMB_FILE_DISPOSITION_INFORMATION:
+ case SMB_SET_FILE_DISPOSITION_INFO: /* Set delete on close for open file. */
+ {
+#if 0
+ /* JRA - We used to just ignore this on a path ?
+ * Shouldn't this be invalid level on a pathname
+ * based call ?
+ */
+ if (tran_call != TRANSACT2_SETFILEINFO) {
+ return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+ }
+#endif
+ status = smb_set_file_disposition_info(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
+ }
- DEBUG(10,("call_trans2setfilepathinfo: file %s : setting new size to %.0f\n",
- fname, (double)size ));
+ case SMB_FILE_POSITION_INFORMATION:
+ {
+ status = smb_file_position_information(conn,
+ pdata,
+ total_data,
+ fsp);
+ break;
+ }
- if (fd == -1) {
- files_struct *new_fsp = NULL;
+ /* 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?).
+ */
- status = open_file_ntcreate(conn, fname, &sbuf,
- FILE_WRITE_DATA,
- FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OPEN,
- 0,
- FILE_ATTRIBUTE_NORMAL,
- FORCE_OPLOCK_BREAK_TO_NONE,
- NULL, &new_fsp);
-
- if (!NT_STATUS_IS_OK(status)) {
- if (open_was_deferred(SVAL(inbuf,smb_mid))) {
- /* We have re-scheduled this call. */
- return -1;
- }
- return(UNIXERROR(ERRDOS,ERRnoaccess));
- }
- ret = vfs_set_filelen(new_fsp, size);
- close_file(new_fsp,NORMAL_CLOSE);
- } else {
- ret = vfs_set_filelen(fsp, size);
+ case SMB_FILE_MODE_INFORMATION:
+ {
+ status = smb_file_mode_information(conn,
+ pdata,
+ total_data);
+ break;
}
- if (ret == -1) {
- return (UNIXERROR(ERRHRD,ERRdiskfull));
+ /*
+ * CIFS UNIX extensions.
+ */
+
+ case SMB_SET_FILE_UNIX_BASIC:
+ {
+ if (tran_call == TRANSACT2_SETFILEINFO) {
+ return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+ }
+
+ status = smb_set_file_unix_basic(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
}
- }
- /*
- * 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.
- */
+ case SMB_SET_FILE_UNIX_LINK:
+ {
+ if (tran_call != TRANSACT2_SETPATHINFO) {
+ /* We must have a pathname for this. */
+ return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+ }
+ status = smb_set_file_unix_link(conn,
+ inbuf,
+ pdata,
+ total_data,
+ fname);
+ break;
+ }
- 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);
+ case SMB_SET_FILE_UNIX_HLINK:
+ {
+ if (tran_call != TRANSACT2_SETPATHINFO) {
+ /* We must have a pathname for this. */
+ return ERROR_NT(NT_STATUS_INVALID_LEVEL);
}
+ status = smb_set_file_unix_hlink(conn,
+ inbuf,
+ pdata,
+ total_data,
+ fname);
+ break;
+ }
+ case SMB_FILE_RENAME_INFORMATION:
+ {
+ status = smb_file_rename_information(conn,
+ inbuf,
+ outbuf,
+ pdata,
+ total_data,
+ fsp,
+ fname);
+ break;
}
- DEBUG(10,("call_trans2setfilepathinfo: setting utimes to modified values.\n"));
- if(file_utime(conn, fname, &tvs)!=0) {
- return(UNIXERROR(ERRDOS,ERRnoaccess));
+#if defined(HAVE_POSIX_ACLS)
+ case SMB_SET_POSIX_ACL:
+ {
+ status = smb_set_posix_acl(conn,
+ pdata,
+ total_data,
+ fsp,
+ fname,
+ &sbuf);
+ break;
+ }
+#endif
+
+ case SMB_SET_POSIX_LOCK:
+ {
+ status = smb_set_posix_lock(conn,
+ inbuf,
+ length,
+ pdata,
+ total_data,
+ fsp);
+ break;
}
+
+ default:
+ return ERROR_NT(NT_STATUS_INVALID_LEVEL);
+ }
+
+
+ if (!NT_STATUS_IS_OK(status)) {
+ if (open_was_deferred(SVAL(inbuf,smb_mid))) {
+ /* We have re-scheduled this call. */
+ return -1;
+ }
+ if (blocking_lock_was_deferred(SVAL(inbuf,smb_mid))) {
+ /* We have re-scheduled this call. */
+ return -1;
+ }
+ if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
+ return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
+ }
+ return ERROR_NT(status);
}
SSVAL(params,0,0);
send_trans2_replies(outbuf, bufsize, params, 2, *ppdata, 0, max_data_bytes);
- return(-1);
+ return -1;
}
/****************************************************************************