diff -ur ../samba-base2/include/proto.h source/include/proto.h --- ../samba-base2/include/proto.h Fri Sep 12 12:03:13 2003 +++ source/include/proto.h Sun Sep 28 16:15:53 2003 @@ -2162,6 +2162,8 @@ BOOL lp_blocking_locks(int ); BOOL lp_inherit_perms(int ); BOOL lp_inherit_acls(int ); +BOOL lp_inherit_owner(int ); +BOOL lp_inherit_group(int ); BOOL lp_use_client_driver(int ); BOOL lp_default_devmode(int ); BOOL lp_nt_acl_support(int ); @@ -4562,6 +4564,8 @@ files_struct *open_directory(connection_struct *conn, char *fname, SMB_STRUCT_STAT *psbuf, uint32 desired_access, int share_mode, int smb_ofun, mode_t unixmode, int *action); files_struct *open_file_stat(connection_struct *conn, char *fname, SMB_STRUCT_STAT *psbuf); +void inherit_owner_byname(struct connection_struct *conn, const char *name); +void inherit_owner_byfile(struct connection_struct *conn, files_struct *fsp); /* The following definitions come from smbd/oplock.c */ diff -ur ../samba-base2/param/loadparm.c source/param/loadparm.c --- ../samba-base2/param/loadparm.c Fri Sep 12 11:46:49 2003 +++ source/param/loadparm.c Sun Sep 28 15:58:11 2003 @@ -409,6 +409,8 @@ BOOL bBlockingLocks; BOOL bInheritPerms; BOOL bInheritACLS; + BOOL bInheritOwner; + BOOL bInheritGroup; BOOL bMSDfsRoot; BOOL bUseClientDriver; BOOL bDefaultDevmode; @@ -535,6 +537,8 @@ True, /* bBlockingLocks */ False, /* bInheritPerms */ False, /* bInheritACLS */ + False, /* bInheritOwner */ + False, /* bInheritGroup */ False, /* bMSDfsRoot */ False, /* bUseClientDriver */ False, /* bDefaultDevmode */ @@ -801,6 +805,8 @@ {"force unknown acl user", P_OCTAL, P_LOCAL, &sDefault.bForceUnknownAclUser, NULL, NULL, FLAG_GLOBAL | FLAG_SHARE}, {"inherit permissions", P_BOOL, P_LOCAL, &sDefault.bInheritPerms, NULL, NULL, FLAG_SHARE}, {"inherit acls", P_BOOL, P_LOCAL, &sDefault.bInheritACLS, NULL, NULL, FLAG_SHARE}, + {"inherit owner", P_BOOL, P_LOCAL, &sDefault.bInheritOwner, NULL, NULL, FLAG_SHARE}, + {"inherit group", P_BOOL, P_LOCAL, &sDefault.bInheritGroup, NULL, NULL, FLAG_SHARE}, {"guest only", P_BOOL, P_LOCAL, &sDefault.bGuest_only, NULL, NULL, FLAG_SHARE}, {"only guest", P_BOOL, P_LOCAL, &sDefault.bGuest_only, NULL, NULL, 0}, @@ -1808,6 +1814,8 @@ FN_LOCAL_BOOL(lp_blocking_locks, bBlockingLocks) FN_LOCAL_BOOL(lp_inherit_perms, bInheritPerms) FN_LOCAL_BOOL(lp_inherit_acls, bInheritACLS) +FN_LOCAL_BOOL(lp_inherit_owner, bInheritOwner) +FN_LOCAL_BOOL(lp_inherit_group, bInheritGroup) FN_LOCAL_BOOL(lp_use_client_driver, bUseClientDriver) FN_LOCAL_BOOL(lp_default_devmode, bDefaultDevmode) FN_LOCAL_BOOL(lp_nt_acl_support, bNTAclSupport) diff -ur ../samba-base2/smbd/open.c source/smbd/open.c --- ../samba-base2/smbd/open.c Sat Mar 1 02:56:20 2003 +++ source/smbd/open.c Fri Oct 3 12:07:56 2003 @@ -1079,8 +1079,10 @@ if (action) { if (file_existed && !(flags2 & O_TRUNC)) *action = FILE_WAS_OPENED; - if (!file_existed) + if (!file_existed) { *action = FILE_WAS_CREATED; + inherit_owner_byfile(conn, fsp); + } if (file_existed && (flags2 & O_TRUNC)) *action = FILE_WAS_OVERWRITTEN; } @@ -1263,6 +1265,8 @@ return NULL; } + inherit_owner_byname(conn, fname); + if(vfs_stat(conn,fname, psbuf) != 0) { file_free(fsp); return NULL; @@ -1399,3 +1403,104 @@ return fsp; } + + + +/* + return a parent path from a filename +*/ +static char *find_parent_path(const char *name) +{ + char *p, *ret; + + ret = strdup(name); + + if (!ret) return NULL; + + p = strrchr(ret, '/'); + if (!p) { + free(ret); + return strdup("."); + } + + *p = 0; + + return ret; +} + + +/* + handle built in inheritance from parent directory for files and directories + inherit via open file descriptor +*/ +static void inherit_owner_fd(struct connection_struct *conn, const char *name, int fd) +{ + uid_t owner; + gid_t group; + char *parent_path; + SMB_STRUCT_STAT st_parent, st_file; + + if (!lp_inherit_owner(SNUM(conn)) && !lp_inherit_group(SNUM(conn))) { + return; + } + + parent_path = find_parent_path(name); + if (!parent_path) return; + + if (conn->vfs_ops.stat(conn, parent_path, &st_parent) != 0) { + free(parent_path); + return; + } + free(parent_path); + + if (conn->vfs_ops.fstat(conn, fd, &st_file) != 0) { + return; + } + + if (lp_inherit_owner(SNUM(conn))) { + owner = st_parent.st_uid; + } else { + owner = st_file.st_uid; + } + + if (lp_inherit_group(SNUM(conn))) { + group = st_parent.st_gid; + } else { + group = st_file.st_gid; + } + + if (owner == st_file.st_uid && + group == st_file.st_gid) { + return; + } + + + become_root(); + fchown(fd, owner, group); + unbecome_root(); +} + +/* + handle built in inheritance from parent directory for files and directories + inherit by name (for directories) +*/ +void inherit_owner_byname(struct connection_struct *conn, const char *name) +{ + int fd; + + fd = open(name, O_RDONLY|O_DIRECTORY); + if (fd == -1) return; + + inherit_owner_fd(conn, name, fd); + + close(fd); +} + +/* + handle built in inheritance from parent directory for files and directories + inherit via open file descriptor +*/ +void inherit_owner_byfile(struct connection_struct *conn, files_struct *fsp) +{ + inherit_owner_fd(conn, fsp->fsp_name, fsp->fd); +} diff -ur ../samba-base2/smbd/reply.c source/smbd/reply.c --- ../samba-base2/smbd/reply.c Fri Sep 12 11:46:49 2003 +++ source/smbd/reply.c Sun Sep 28 15:52:04 2003 @@ -3636,6 +3636,8 @@ return map_nt_error_from_unix(errno); } + inherit_owner_byname(conn, directory); + return NT_STATUS_OK; } diff -ur ../samba-base2/smbd/trans2.c source/smbd/trans2.c --- ../samba-base2/smbd/trans2.c Fri Sep 12 11:46:49 2003 +++ source/smbd/trans2.c Sun Sep 28 15:52:31 2003 @@ -2950,6 +2950,9 @@ return(UNIXERROR(ERRDOS,ERRnoaccess)); } + + inherit_owner_byname(conn, directory); + /* Realloc the parameter and data sizes */ params = Realloc(*pparams,2); if(params == NULL)