summaryrefslogtreecommitdiff
path: root/source3/smbd/server.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1997-10-20 18:52:04 +0000
committerJeremy Allison <jra@samba.org>1997-10-20 18:52:04 +0000
commit79f4fb52c1ed56fd843f81b4eb0cdd2991d4d0f4 (patch)
tree2011e0c8045a90593bc71f0e802eed91e4c82ffb /source3/smbd/server.c
parent77a93855259fe29c8b37575aba5f07dbb70d3510 (diff)
downloadsamba-79f4fb52c1ed56fd843f81b4eb0cdd2991d4d0f4.tar.gz
samba-79f4fb52c1ed56fd843f81b4eb0cdd2991d4d0f4.tar.bz2
samba-79f4fb52c1ed56fd843f81b4eb0cdd2991d4d0f4.zip
loadparm.c: Changed 'interfaces only' parameter to 'bind interfaces only'. Added
'dos filetimes' parameter for UTIME fix. locking_shm.c: Fixed typo (sorry Andrew :-). namepacket.c: Changed lp_interfaces_only() to lp_bind_interfaces_only(). proto.h: The usual. reply.c: Made filetime calls use new file_utime call (wrapper for sys_utime). server.c: Made filetime calls use new file_utime call (wrapper for sys_utime). system.c: Added Andrew's sanity checks to times in sys_utime(). time.c: Moved set_filetime() to server.c. Made null_mtime() global. trans2.c: Made filetime calls use new file_utime call (wrapper for sys_utime). Jeremy (jallison@whistle.com) (This used to be commit 41a1d81c112a82ad2ae1b3c4ee81051f133ce1ed)
Diffstat (limited to 'source3/smbd/server.c')
-rw-r--r--source3/smbd/server.c72
1 files changed, 64 insertions, 8 deletions
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 7d9638f01e..7639c5940b 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -254,7 +254,6 @@ int dos_mode(int cnum,char *path,struct stat *sbuf)
return(result);
}
-
/*******************************************************************
chmod a file - but preserve some bits
********************************************************************/
@@ -308,6 +307,70 @@ int dos_chmod(int cnum,char *fname,int dosmode,struct stat *st)
return(sys_chmod(fname,unixmode));
}
+/*******************************************************************
+Wrapper around sys_utime that possibly allows DOS semantics rather
+than POSIX.
+*******************************************************************/
+
+int file_utime(int cnum, char *fname, struct utimbuf *times)
+{
+ extern struct current_user current_user;
+ struct stat sb;
+ int ret = -1;
+
+ if(sys_utime(fname, times) == 0)
+ return 0;
+
+ if((errno != EPERM) || !lp_dos_filetimes(SNUM(cnum)))
+ return -1;
+
+ /* We have permission (given by the Samba admin) to
+ break POSIX semantics and allow a user to change
+ the time on a file they don't own but can write to
+ (as DOS does).
+ */
+
+ if(sys_stat(fname,&sb) != 0)
+ return -1;
+
+ /* Check if we have write access. */
+ if (CAN_WRITE(cnum) && !lp_alternate_permissions(SNUM(cnum)))
+ {
+ if (((sb.st_mode & S_IWOTH) ||
+ Connections[cnum].admin_user ||
+ ((sb.st_mode & S_IWUSR) && current_user.uid==sb.st_uid) ||
+ ((sb.st_mode & S_IWGRP) &&
+ in_group(sb.st_gid,current_user.gid,
+ current_user.ngroups,current_user.igroups))))
+ {
+ /* We are allowed to become root and change the filetime. */
+ become_root(False);
+ ret = sys_utime(fname, times);
+ unbecome_root(False);
+ }
+ }
+
+ return ret;
+}
+
+/*******************************************************************
+Change a filetime - possibly allowing DOS semantics.
+*******************************************************************/
+
+BOOL set_filetime(int cnum, char *fname, time_t mtime)
+{
+ struct utimbuf times;
+
+ if (null_mtime(mtime)) return(True);
+
+ times.modtime = times.actime = mtime;
+
+ if (file_utime(cnum, fname, &times)) {
+ DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno)));
+ }
+
+ return(True);
+}
/****************************************************************************
check if two filenames are equal
@@ -1099,13 +1162,6 @@ static void open_file(int fnum,int cnum,char *fname1,int flags,int mode, struct
DEBUG(3,("Bug in client? Set O_WRONLY without O_CREAT\n"));
*/
-#if UTIME_WORKAROUND
- /* XXXX - is this OK?? */
- /* this works around a utime bug but can cause other problems */
- if ((flags & (O_WRONLY|O_RDWR)) && (flags & O_CREAT) && !(flags & O_APPEND))
- sys_unlink(fname);
-#endif
-
/*
* Ensure we have a valid struct stat so we can search the
* open fd table.