summaryrefslogtreecommitdiffstats
path: root/source/smbd/dosmode.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-08-17 13:11:34 +0000
committerAndrew Tridgell <tridge@samba.org>1998-08-17 13:11:34 +0000
commita6d194886a4a5f7507fa37289ff96c1be56f14a6 (patch)
tree1b24d31f4b2b8d050f73089607382907f78e1232 /source/smbd/dosmode.c
parent534a90ca44641417c21f6ed6d4b94b1de60f808d (diff)
downloadsamba-a6d194886a4a5f7507fa37289ff96c1be56f14a6.tar.gz
samba-a6d194886a4a5f7507fa37289ff96c1be56f14a6.tar.xz
samba-a6d194886a4a5f7507fa37289ff96c1be56f14a6.zip
this completes the splitup of server.c.
the splitup was done with an axe, not a scalpel, so there are some rough edges. I mostly wanted to get the general form right with fine tuning of what goes where to come later. Still, this is better than what we had before where server.c was a general repository for anything that didn't fit elsewhere.
Diffstat (limited to 'source/smbd/dosmode.c')
-rw-r--r--source/smbd/dosmode.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/source/smbd/dosmode.c b/source/smbd/dosmode.c
index c1af18d80ba..9db3e208b5e 100644
--- a/source/smbd/dosmode.c
+++ b/source/smbd/dosmode.c
@@ -200,3 +200,71 @@ int dos_chmod(connection_struct *conn,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(connection_struct *conn, char *fname, struct utimbuf *times)
+{
+ extern struct current_user current_user;
+ struct stat sb;
+ int ret = -1;
+
+ errno = 0;
+
+ if(sys_utime(fname, times) == 0)
+ return 0;
+
+ if((errno != EPERM) && (errno != EACCES))
+ return -1;
+
+ if(!lp_dos_filetimes(SNUM(conn)))
+ 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(conn)) {
+ if (((sb.st_mode & S_IWOTH) ||
+ conn->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.groups)))) {
+ /* 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(connection_struct *conn, char *fname, time_t mtime)
+{
+ struct utimbuf times;
+
+ if (null_mtime(mtime)) return(True);
+
+ times.modtime = times.actime = mtime;
+
+ if (file_utime(conn, fname, &times)) {
+ DEBUG(4,("set_filetime(%s) failed: %s\n",fname,strerror(errno)));
+ }
+
+ return(True);
+}
+
+