svn commit: samba r20343 - in branches/SAMBA_3_0/source/smbd: .
vlendec at samba.org
vlendec at samba.org
Sun Dec 24 15:29:11 GMT 2006
Author: vlendec
Date: 2006-12-24 15:29:09 +0000 (Sun, 24 Dec 2006)
New Revision: 20343
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20343
Log:
Split change_owner_to_parent fd-based (for file opens) and a name-based (for
directory opens) routines.
Volker
Modified:
branches/SAMBA_3_0/source/smbd/open.c
Changeset:
Modified: branches/SAMBA_3_0/source/smbd/open.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/open.c 2006-12-24 15:11:03 UTC (rev 20342)
+++ branches/SAMBA_3_0/source/smbd/open.c 2006-12-24 15:29:09 UTC (rev 20343)
@@ -84,11 +84,43 @@
Do this by fd if possible.
****************************************************************************/
+static void change_fd_owner_to_parent(connection_struct *conn,
+ files_struct *fsp)
+{
+ const char *parent_path = parent_dirname(fsp->fsp_name);
+ SMB_STRUCT_STAT parent_st;
+ int ret;
+
+ ret = SMB_VFS_STAT(conn, parent_path, &parent_st);
+ if (ret == -1) {
+ DEBUG(0,("change_fd_owner_to_parent: failed to stat parent "
+ "directory %s. Error was %s\n",
+ parent_path, strerror(errno) ));
+ return;
+ }
+
+ become_root();
+ ret = SMB_VFS_FCHOWN(fsp, fsp->fh->fd, parent_st.st_uid, (gid_t)-1);
+ unbecome_root();
+ if (ret == -1) {
+ DEBUG(0,("change_fd_owner_to_parent: failed to fchown "
+ "file %s to parent directory uid %u. Error "
+ "was %s\n", fsp->fsp_name,
+ (unsigned int)parent_st.st_uid,
+ strerror(errno) ));
+ }
+
+ DEBUG(10,("change_fd_owner_to_parent: changed new file %s to "
+ "parent directory uid %u.\n", fsp->fsp_name,
+ (unsigned int)parent_st.st_uid ));
+}
+
static void change_owner_to_parent(connection_struct *conn,
- files_struct *fsp,
const char *fname,
SMB_STRUCT_STAT *psbuf)
{
+ pstring saved_dir;
+ SMB_STRUCT_STAT sbuf;
const char *parent_path = parent_dirname(fname);
SMB_STRUCT_STAT parent_st;
int ret;
@@ -101,83 +133,62 @@
return;
}
- if (fsp && fsp->fh->fd != -1) {
- become_root();
- ret = SMB_VFS_FCHOWN(fsp, fsp->fh->fd, parent_st.st_uid, (gid_t)-1);
- unbecome_root();
- if (ret == -1) {
- DEBUG(0,("change_owner_to_parent: failed to fchown "
- "file %s to parent directory uid %u. Error "
- "was %s\n", fname,
- (unsigned int)parent_st.st_uid,
- strerror(errno) ));
- }
+ /* We've already done an lstat into psbuf, and we know it's a
+ directory. If we can cd into the directory and the dev/ino
+ are the same then we can safely chown without races as
+ we're locking the directory in place by being in it. This
+ should work on any UNIX (thanks tridge :-). JRA.
+ */
- DEBUG(10,("change_owner_to_parent: changed new file %s to "
- "parent directory uid %u.\n", fname,
- (unsigned int)parent_st.st_uid ));
+ if (!vfs_GetWd(conn,saved_dir)) {
+ DEBUG(0,("change_owner_to_parent: failed to get "
+ "current working directory\n"));
+ return;
+ }
- } else {
- /* We've already done an lstat into psbuf, and we know it's a
- directory. If we can cd into the directory and the dev/ino
- are the same then we can safely chown without races as
- we're locking the directory in place by being in it. This
- should work on any UNIX (thanks tridge :-). JRA.
- */
+ /* Chdir into the new path. */
+ if (vfs_ChDir(conn, fname) == -1) {
+ DEBUG(0,("change_owner_to_parent: failed to change "
+ "current working directory to %s. Error "
+ "was %s\n", fname, strerror(errno) ));
+ goto out;
+ }
- pstring saved_dir;
- SMB_STRUCT_STAT sbuf;
+ if (SMB_VFS_STAT(conn,".",&sbuf) == -1) {
+ DEBUG(0,("change_owner_to_parent: failed to stat "
+ "directory '.' (%s) Error was %s\n",
+ fname, strerror(errno)));
+ goto out;
+ }
- if (!vfs_GetWd(conn,saved_dir)) {
- DEBUG(0,("change_owner_to_parent: failed to get "
- "current working directory\n"));
- return;
- }
+ /* Ensure we're pointing at the same place. */
+ if (sbuf.st_dev != psbuf->st_dev ||
+ sbuf.st_ino != psbuf->st_ino ||
+ sbuf.st_mode != psbuf->st_mode ) {
+ DEBUG(0,("change_owner_to_parent: "
+ "device/inode/mode on directory %s changed. "
+ "Refusing to chown !\n", fname ));
+ goto out;
+ }
- /* Chdir into the new path. */
- if (vfs_ChDir(conn, fname) == -1) {
- DEBUG(0,("change_owner_to_parent: failed to change "
- "current working directory to %s. Error "
- "was %s\n", fname, strerror(errno) ));
- goto out;
- }
+ become_root();
+ ret = SMB_VFS_CHOWN(conn, ".", parent_st.st_uid, (gid_t)-1);
+ unbecome_root();
+ if (ret == -1) {
+ DEBUG(10,("change_owner_to_parent: failed to chown "
+ "directory %s to parent directory uid %u. "
+ "Error was %s\n", fname,
+ (unsigned int)parent_st.st_uid, strerror(errno) ));
+ goto out;
+ }
- if (SMB_VFS_STAT(conn,".",&sbuf) == -1) {
- DEBUG(0,("change_owner_to_parent: failed to stat "
- "directory '.' (%s) Error was %s\n",
- fname, strerror(errno)));
- goto out;
- }
+ DEBUG(10,("change_owner_to_parent: changed ownership of new "
+ "directory %s to parent directory uid %u.\n",
+ fname, (unsigned int)parent_st.st_uid ));
- /* Ensure we're pointing at the same place. */
- if (sbuf.st_dev != psbuf->st_dev ||
- sbuf.st_ino != psbuf->st_ino ||
- sbuf.st_mode != psbuf->st_mode ) {
- DEBUG(0,("change_owner_to_parent: "
- "device/inode/mode on directory %s changed. "
- "Refusing to chown !\n", fname ));
- goto out;
- }
+ out:
- become_root();
- ret = SMB_VFS_CHOWN(conn, ".", parent_st.st_uid, (gid_t)-1);
- unbecome_root();
- if (ret == -1) {
- DEBUG(10,("change_owner_to_parent: failed to chown "
- "directory %s to parent directory uid %u. "
- "Error was %s\n", fname,
- (unsigned int)parent_st.st_uid, strerror(errno) ));
- goto out;
- }
-
- DEBUG(10,("change_owner_to_parent: changed ownership of new "
- "directory %s to parent directory uid %u.\n",
- fname, (unsigned int)parent_st.st_uid ));
-
- out:
-
- vfs_ChDir(conn,saved_dir);
- }
+ vfs_ChDir(conn,saved_dir);
}
/****************************************************************************
@@ -1693,8 +1704,7 @@
info = FILE_WAS_CREATED;
/* Change the owner if required. */
if (lp_inherit_owner(SNUM(conn))) {
- change_owner_to_parent(conn, fsp, fsp->fsp_name,
- psbuf);
+ change_fd_owner_to_parent(conn, fsp);
}
}
@@ -2078,7 +2088,7 @@
/* Change the owner if required. */
if ((info == FILE_WAS_CREATED) && lp_inherit_owner(SNUM(conn))) {
- change_owner_to_parent(conn, fsp, fsp->fsp_name, psbuf);
+ change_owner_to_parent(conn, fsp->fsp_name, psbuf);
}
if (pinfo) {
More information about the samba-cvs
mailing list