summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-10-10 13:47:49 +1100
committerJeremy Allison <jra@samba.org>2013-01-07 16:09:39 -0800
commit6c80cf747d75e648a1d88d477bcf476e6874c4b3 (patch)
treece9aef0f15d9c9588eb0cd4b0a12c347591a8e86
parent6a5afa244203c42265207c56e95783ec740ee89e (diff)
downloadsamba-6c80cf747d75e648a1d88d477bcf476e6874c4b3.tar.gz
samba-6c80cf747d75e648a1d88d477bcf476e6874c4b3.tar.bz2
samba-6c80cf747d75e648a1d88d477bcf476e6874c4b3.zip
smbd: Split create_conn_struct into a fn that does not change the working dir
The python bindings do not want the current working directory changed during operations, so we provide two functions, one providing the original behaviour, and other providing the python bindings with just the memory allocation and initilisation stuff. Andrew Bartlett Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/printing/nt_printing.c6
-rw-r--r--source3/rpc_server/srvsvc/srv_srvsvc_nt.c4
-rw-r--r--source3/smbd/msdfs.c58
-rw-r--r--source3/smbd/proto.h11
4 files changed, 58 insertions, 21 deletions
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index 252fbb8db5..f27003c338 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -616,7 +616,7 @@ static uint32 get_correct_cversion(struct auth_session_info *session_info,
return -1;
}
- nt_status = create_conn_struct(talloc_tos(),
+ nt_status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
&conn,
@@ -1003,7 +1003,7 @@ WERROR move_driver_to_download_area(struct auth_session_info *session_info,
return WERR_NO_SUCH_SHARE;
}
- nt_status = create_conn_struct(talloc_tos(),
+ nt_status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
&conn,
@@ -1539,7 +1539,7 @@ bool delete_driver_files(const struct auth_session_info *session_info,
return false;
}
- nt_status = create_conn_struct(talloc_tos(),
+ nt_status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
&conn,
diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index a6472a67ca..e14b7973a1 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -2037,7 +2037,7 @@ WERROR _srvsvc_NetGetFileSecurity(struct pipes_struct *p,
goto error_exit;
}
- nt_status = create_conn_struct(talloc_tos(),
+ nt_status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
&conn,
@@ -2184,7 +2184,7 @@ WERROR _srvsvc_NetSetFileSecurity(struct pipes_struct *p,
goto error_exit;
}
- nt_status = create_conn_struct(talloc_tos(),
+ nt_status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
&conn,
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index b6ebaca1a1..83f140c25b 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -218,8 +218,9 @@ static NTSTATUS parse_dfs_path(connection_struct *conn,
}
/********************************************************
- Fake up a connection struct for the VFS layer.
- Note: this performs a vfs connect and CHANGES CWD !!!! JRA.
+ Fake up a connection struct for the VFS layer, for use in
+ applications (such as the python bindings), that do not want the
+ global working directory changed under them.
*********************************************************/
NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
@@ -228,12 +229,10 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
connection_struct **pconn,
int snum,
const char *path,
- const struct auth_session_info *session_info,
- char **poldcwd)
+ const struct auth_session_info *session_info)
{
connection_struct *conn;
char *connpath;
- char *oldcwd;
const char *vfs_user;
conn = talloc_zero(ctx, connection_struct);
@@ -247,9 +246,9 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
return NT_STATUS_NO_MEMORY;
}
connpath = talloc_string_sub(conn,
- connpath,
- "%S",
- lp_servicename(talloc_tos(), snum));
+ connpath,
+ "%S",
+ lp_servicename(talloc_tos(), snum));
if (!connpath) {
TALLOC_FREE(conn);
return NT_STATUS_NO_MEMORY;
@@ -341,6 +340,37 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
}
conn->fs_capabilities = SMB_VFS_FS_CAPABILITIES(conn, &conn->ts_res);
+ *pconn = conn;
+
+ return NT_STATUS_OK;
+}
+
+/********************************************************
+ Fake up a connection struct for the VFS layer.
+ Note: this performs a vfs connect and CHANGES CWD !!!! JRA.
+
+ The old working directory is returned on *poldcwd, allocated on ctx.
+*********************************************************/
+
+NTSTATUS create_conn_struct_cwd(TALLOC_CTX *ctx,
+ struct tevent_context *ev,
+ struct messaging_context *msg,
+ connection_struct **pconn,
+ int snum,
+ const char *path,
+ const struct auth_session_info *session_info,
+ char **poldcwd)
+{
+ connection_struct *conn;
+ char *oldcwd;
+
+ NTSTATUS status = create_conn_struct(ctx, ev,
+ msg, &conn,
+ snum, path,
+ session_info);
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
/*
* Windows seems to insist on doing trans2getdfsreferral() calls on
@@ -350,14 +380,14 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
oldcwd = vfs_GetWd(ctx, conn);
if (oldcwd == NULL) {
- NTSTATUS status = map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
DEBUG(3, ("vfs_GetWd failed: %s\n", strerror(errno)));
conn_free(conn);
return status;
}
if (vfs_ChDir(conn,conn->connectpath) != 0) {
- NTSTATUS status = map_nt_error_from_unix(errno);
+ status = map_nt_error_from_unix(errno);
DEBUG(3,("create_conn_struct: Can't ChDir to new conn path %s. "
"Error was %s\n",
conn->connectpath, strerror(errno) ));
@@ -981,7 +1011,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
return NT_STATUS_OK;
}
- status = create_conn_struct(ctx,
+ status = create_conn_struct_cwd(ctx,
server_event_context(),
server_messaging_context(),
&conn, snum,
@@ -1160,7 +1190,7 @@ static bool junction_to_local_path(const struct junction_map *jucn,
if(snum < 0) {
return False;
}
- status = create_conn_struct(talloc_tos(),
+ status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
conn_out,
@@ -1325,7 +1355,7 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
* Fake up a connection struct for the VFS layer.
*/
- status = create_conn_struct(talloc_tos(),
+ status = create_conn_struct_cwd(talloc_tos(),
server_event_context(),
server_messaging_context(),
&conn,
@@ -1401,7 +1431,7 @@ static int form_junctions(TALLOC_CTX *ctx,
* Fake up a connection struct for the VFS layer.
*/
- status = create_conn_struct(ctx,
+ status = create_conn_struct_cwd(ctx,
server_event_context(),
server_messaging_context(),
&conn, snum, connect_path, NULL,
diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h
index 9a9a010671..888f4afdcb 100644
--- a/source3/smbd/proto.h
+++ b/source3/smbd/proto.h
@@ -490,8 +490,15 @@ NTSTATUS create_conn_struct(TALLOC_CTX *ctx,
connection_struct **pconn,
int snum,
const char *path,
- const struct auth_session_info *session_info,
- char **poldcwd);
+ const struct auth_session_info *session_info);
+NTSTATUS create_conn_struct_cwd(TALLOC_CTX *ctx,
+ struct tevent_context *ev,
+ struct messaging_context *msg,
+ connection_struct **pconn,
+ int snum,
+ const char *path,
+ const struct auth_session_info *session_info,
+ char **poldcwd);
/* The following definitions come from smbd/negprot.c */