[SCM] Samba Shared Repository - branch master updated
Volker Lendecke
vlendec at samba.org
Fri Jun 24 14:37:01 MDT 2011
The branch, master has been updated
via 21b30d5 Add NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED
via c8d374a s3: Fix an error message in smbclient symlink
via daec41c s3: Use reparse point style symlinks
via d637cd2 s3: Remove a call to cli_errstr
via bbe8e0b s3: Add cli_symlink
via 57a0207 s3: Add SYMLINK_FLAG_RELATIVE define
via 829974c s3: Add symlink reparse point marshalling routines
via a52f179 lib: Allow NULL converted_size in convert_string_talloc
from d7cc857 s4:selftest: test ntvfs.cifs with s4u2proxy
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 21b30d52f534f4833bb77c32c2d4fdaecfbbd7e8
Author: Volker Lendecke <vl at samba.org>
Date: Fri Jun 24 21:23:21 2011 +0200
Add NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED
Autobuild-User: Volker Lendecke <vlendec at samba.org>
Autobuild-Date: Fri Jun 24 22:36:50 CEST 2011 on sn-devel-104
commit c8d374a0f23fe74b72e5bcfd62c3ff17dc6928e3
Author: Volker Lendecke <vl at samba.org>
Date: Fri Jun 24 17:01:44 2011 +0200
s3: Fix an error message in smbclient symlink
commit daec41c84614b485c8df90fc95467024bcb68110
Author: Volker Lendecke <vl at samba.org>
Date: Thu Jun 23 16:54:50 2011 +0200
s3: Use reparse point style symlinks
commit d637cd23809c9b5ace233e24df3ea25df4735d7a
Author: Volker Lendecke <vl at samba.org>
Date: Thu Jun 23 16:52:34 2011 +0200
s3: Remove a call to cli_errstr
commit bbe8e0bcf47022584f4d908adf52dec522f3d736
Author: Volker Lendecke <vl at samba.org>
Date: Thu Jun 23 16:49:17 2011 +0200
s3: Add cli_symlink
commit 57a02077c917d6deefce716f32b5a5bf30227f07
Author: Volker Lendecke <vl at samba.org>
Date: Thu Jun 23 16:02:50 2011 +0200
s3: Add SYMLINK_FLAG_RELATIVE define
commit 829974c940c39cc65b0f725f0e5a38917fc61254
Author: Volker Lendecke <vl at samba.org>
Date: Thu Jun 23 15:33:58 2011 +0200
s3: Add symlink reparse point marshalling routines
commit a52f17995177ca8751400570cc8aabc7e06ade72
Author: Volker Lendecke <vl at samba.org>
Date: Thu Jun 23 14:44:25 2011 +0200
lib: Allow NULL converted_size in convert_string_talloc
-----------------------------------------------------------------------
Summary of changes:
lib/util/charset/convert_string.c | 8 +-
libcli/util/nterr.c | 2 +
libcli/util/ntstatus.h | 1 +
source3/Makefile.in | 2 +
source3/client/client.c | 40 ++++---
source3/include/ntioctl.h | 2 +
source3/libsmb/clisymlink.c | 228 +++++++++++++++++++++++++++++++++++++
source3/libsmb/proto.h | 21 ++++
source3/libsmb/reparse_symlink.c | 174 ++++++++++++++++++++++++++++
source3/wscript_build | 2 +
10 files changed, 459 insertions(+), 21 deletions(-)
create mode 100644 source3/libsmb/clisymlink.c
create mode 100644 source3/libsmb/reparse_symlink.c
Changeset truncated at 500 lines:
diff --git a/lib/util/charset/convert_string.c b/lib/util/charset/convert_string.c
index 51f9fec..8f46c88 100644
--- a/lib/util/charset/convert_string.c
+++ b/lib/util/charset/convert_string.c
@@ -376,7 +376,9 @@ bool convert_string_talloc_handle(TALLOC_CTX *ctx, struct smb_iconv_handle *ic,
errno = ENOMEM;
return false;
}
- *converted_size = destlen;
+ if (converted_size != NULL) {
+ *converted_size = destlen;
+ }
*dest = ob;
return true;
}
@@ -470,7 +472,9 @@ bool convert_string_talloc_handle(TALLOC_CTX *ctx, struct smb_iconv_handle *ic,
}
}
- *converted_size = destlen;
+ if (converted_size != NULL) {
+ *converted_size = destlen;
+ }
return true;
}
diff --git a/libcli/util/nterr.c b/libcli/util/nterr.c
index f79f66a..405ff6d 100644
--- a/libcli/util/nterr.c
+++ b/libcli/util/nterr.c
@@ -546,6 +546,8 @@ const nt_err_code_struct nt_errs[] =
{ "NT_STATUS_DS_NO_MORE_RIDS", NT_STATUS_DS_NO_MORE_RIDS },
{ "NT_STATUS_IO_REPARSE_DATA_INVALID",
NT_STATUS_IO_REPARSE_DATA_INVALID },
+ { "NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED",
+ NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED },
{ "NT_STATUS_NOT_A_REPARSE_POINT", NT_STATUS_NOT_A_REPARSE_POINT },
{ "NT_STATUS_NO_MORE_ENTRIES", NT_STATUS_NO_MORE_ENTRIES },
{ "NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED", NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED },
diff --git a/libcli/util/ntstatus.h b/libcli/util/ntstatus.h
index b1286a2..36a040d 100644
--- a/libcli/util/ntstatus.h
+++ b/libcli/util/ntstatus.h
@@ -598,6 +598,7 @@ typedef uint32_t NTSTATUS;
#define NT_STATUS_DS_NO_MORE_RIDS NT_STATUS(0xC0000000 | 0x02A8)
#define NT_STATUS_NOT_A_REPARSE_POINT NT_STATUS(0xC0000000 | 0x0275)
#define NT_STATUS_IO_REPARSE_DATA_INVALID NT_STATUS(0xC0000000 | 0x0278)
+#define NT_STATUS_IO_REPARSE_TAG_NOT_HANDLED NT_STATUS(0xC0000000 | 0x0279)
#define NT_STATUS_CURRENT_DOMAIN_NOT_ALLOWED NT_STATUS(0xC0000000 | 0x02E9)
#define NT_STATUS_OBJECTID_NOT_FOUND NT_STATUS(0xC0000000 | 0x02F0)
#define NT_STATUS_NO_SUCH_JOB NT_STATUS(0xC0000000 | 0xEDE) /* scheduler */
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 59f9032..b37f315 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -590,6 +590,8 @@ LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
libsmb/clikrb5.o ../libcli/auth/krb5_wrap.o libsmb/clispnego.o \
../libcli/auth/spnego_parse.o \
../lib/util/asn1.o \
+ libsmb/reparse_symlink.o \
+ libsmb/clisymlink.o \
libsmb/clirap.o libsmb/clierror.o libsmb/climessage.o \
libsmb/clireadwrite.o libsmb/clilist.o libsmb/cliprint.o \
libsmb/clitrans.o libsmb/clisecdesc.o libsmb/clidgram.o \
diff --git a/source3/client/client.c b/source3/client/client.c
index b485df7..207147c 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -36,6 +36,7 @@
#include "libsmb/clirap.h"
#include "trans2.h"
#include "libsmb/nmblib.h"
+#include "include/ntioctl.h"
#ifndef REGISTER
#define REGISTER 0
@@ -3004,6 +3005,7 @@ static int cmd_symlink(void)
char *buf = NULL;
char *buf2 = NULL;
struct cli_state *newcli;
+ NTSTATUS status;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) ||
!next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) {
@@ -3013,28 +3015,28 @@ static int cmd_symlink(void)
/* Oldname (link target) must be an untouched blob. */
oldname = buf;
- newname = talloc_asprintf(ctx,
- "%s%s",
- client_get_cur_dir(),
- buf2);
- if (!newname) {
- return 1;
- }
-
- /* New name must be present in share namespace. */
- if (!cli_resolve_path(ctx, "", auth_info, cli, newname, &newcli, &newname)) {
- d_printf("link %s: %s\n", oldname, cli_errstr(cli));
- return 1;
- }
-
- if (!SERVER_HAS_UNIX_CIFS(newcli)) {
- d_printf("Server doesn't support UNIX CIFS calls.\n");
- return 1;
+ if (SERVER_HAS_UNIX_CIFS(cli)) {
+ newname = talloc_asprintf(ctx, "%s%s", client_get_cur_dir(),
+ buf2);
+ if (!newname) {
+ return 1;
+ }
+ /* New name must be present in share namespace. */
+ if (!cli_resolve_path(ctx, "", auth_info, cli, newname,
+ &newcli, &newname)) {
+ d_printf("link %s: %s\n", oldname, cli_errstr(cli));
+ return 1;
+ }
+ status = cli_posix_symlink(newcli, oldname, newname);
+ } else {
+ status = cli_symlink(
+ cli, oldname, buf2,
+ buf2[0] == '\\' ? 0 : SYMLINK_FLAG_RELATIVE);
}
- if (!NT_STATUS_IS_OK(cli_posix_symlink(newcli, oldname, newname))) {
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s symlinking files (%s -> %s)\n",
- cli_errstr(newcli), newname, newname);
+ nt_errstr(status), oldname, newname);
return 1;
}
diff --git a/source3/include/ntioctl.h b/source3/include/ntioctl.h
index 131d596..706cc16 100644
--- a/source3/include/ntioctl.h
+++ b/source3/include/ntioctl.h
@@ -70,6 +70,8 @@
#endif
#define IO_REPARSE_TAG_SYMLINK 0xA000000C
+#define SYMLINK_FLAG_RELATIVE 0x00000001
+
#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
#define IO_REPARSE_TAG_HSM 0xC0000004
#define IO_REPARSE_TAG_SIS 0x80000007
diff --git a/source3/libsmb/clisymlink.c b/source3/libsmb/clisymlink.c
new file mode 100644
index 0000000..e5c2c1a
--- /dev/null
+++ b/source3/libsmb/clisymlink.c
@@ -0,0 +1,228 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Client implementation of setting symlinks using reparse points
+ * Copyright (C) Volker Lendecke 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "system/filesys.h"
+#include "libsmb/libsmb.h"
+#include "../lib/util/tevent_ntstatus.h"
+#include "async_smb.h"
+#include "libsmb/clirap.h"
+#include "trans2.h"
+#include "ntioctl.h"
+#include "libcli/security/secdesc.h"
+#include "libcli/security/security.h"
+
+struct cli_symlink_state {
+ struct tevent_context *ev;
+ struct cli_state *cli;
+ const char *oldpath;
+ const char *newpath;
+ uint32_t flags;
+
+ uint16_t fnum;
+
+ uint16_t setup[4];
+ NTSTATUS set_reparse_status;
+};
+
+static void cli_symlink_create_done(struct tevent_req *subreq);
+static void cli_symlink_set_reparse_done(struct tevent_req *subreq);
+static void cli_symlink_delete_on_close_done(struct tevent_req *subreq);
+static void cli_symlink_close_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_symlink_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct cli_state *cli,
+ const char *oldpath,
+ const char *newpath,
+ uint32_t flags)
+{
+ struct tevent_req *req, *subreq;
+ struct cli_symlink_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct cli_symlink_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->ev = ev;
+ state->cli = cli;
+ state->oldpath = oldpath;
+ state->newpath = newpath;
+ state->flags = flags;
+
+ subreq = cli_ntcreate_send(
+ state, ev, cli, state->oldpath, 0,
+ SYNCHRONIZE_ACCESS|DELETE_ACCESS|
+ FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES,
+ FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_CREATE,
+ FILE_OPEN_REPARSE_POINT|FILE_SYNCHRONOUS_IO_NONALERT|
+ FILE_NON_DIRECTORY_FILE, 0);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, cli_symlink_create_done, req);
+ return req;
+}
+
+static void cli_symlink_create_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cli_symlink_state *state = tevent_req_data(
+ req, struct cli_symlink_state);
+ uint8_t *data;
+ size_t data_len;
+ NTSTATUS status;
+
+ status = cli_ntcreate_recv(subreq, &state->fnum);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ SIVAL(state->setup, 0, FSCTL_SET_REPARSE_POINT);
+ SSVAL(state->setup, 4, state->fnum);
+ SCVAL(state->setup, 6, 1); /* IsFcntl */
+ SCVAL(state->setup, 7, 0); /* IsFlags */
+
+ if (!symlink_reparse_buffer_marshall(
+ state->newpath, NULL, state->flags, state,
+ &data, &data_len)) {
+ tevent_req_oom(req);
+ return;
+ }
+
+ subreq = cli_trans_send(state, state->ev, state->cli, SMBnttrans,
+ NULL, -1, /* name, fid */
+ NT_TRANSACT_IOCTL, 0,
+ state->setup, 4, 0, /* setup */
+ NULL, 0, 0, /* param */
+ data, data_len, 0); /* data */
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cli_symlink_set_reparse_done, req);
+}
+
+static void cli_symlink_set_reparse_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cli_symlink_state *state = tevent_req_data(
+ req, struct cli_symlink_state);
+
+ state->set_reparse_status = cli_trans_recv(
+ subreq, NULL, NULL,
+ NULL, 0, NULL, /* rsetup */
+ NULL, 0, NULL, /* rparam */
+ NULL, 0, NULL); /* rdata */
+ TALLOC_FREE(subreq);
+
+ if (NT_STATUS_IS_OK(state->set_reparse_status)) {
+ subreq = cli_close_send(state, state->ev, state->cli,
+ state->fnum);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cli_symlink_close_done, req);
+ return;
+ }
+ subreq = cli_nt_delete_on_close_send(
+ state, state->ev, state->cli, state->fnum, true);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cli_symlink_delete_on_close_done, req);
+}
+
+static void cli_symlink_delete_on_close_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cli_symlink_state *state = tevent_req_data(
+ req, struct cli_symlink_state);
+ NTSTATUS status;
+
+ status = cli_nt_delete_on_close_recv(subreq);
+ TALLOC_FREE(subreq);
+
+ /*
+ * Ignore status, we can't do much anyway in case of failure
+ */
+
+ subreq = cli_close_send(state, state->ev, state->cli, state->fnum);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, cli_symlink_close_done, req);
+}
+
+static void cli_symlink_close_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct cli_symlink_state *state = tevent_req_data(
+ req, struct cli_symlink_state);
+ NTSTATUS status;
+
+ status = cli_close_recv(subreq);
+ TALLOC_FREE(subreq);
+
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+ if (tevent_req_nterror(req, state->set_reparse_status)) {
+ return;
+ }
+ tevent_req_done(req);
+}
+
+NTSTATUS cli_symlink_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_symlink(struct cli_state *cli, const char *oldname,
+ const char *newname, uint32_t flags)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct event_context *ev;
+ struct tevent_req *req;
+ NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+ if (cli_has_async_calls(cli)) {
+ status = NT_STATUS_INVALID_PARAMETER;
+ goto fail;
+ }
+ ev = event_context_init(frame);
+ if (ev == NULL) {
+ goto fail;
+ }
+ req = cli_symlink_send(frame, ev, cli, oldname, newname, flags);
+ if (req == NULL) {
+ goto fail;
+ }
+ if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+ goto fail;
+ }
+ status = cli_symlink_recv(req);
+ fail:
+ TALLOC_FREE(frame);
+ return status;
+}
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index f88a891..a266f7c 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -851,4 +851,25 @@ bool client_is_signing_allowed(struct cli_state *cli);
bool client_is_signing_mandatory(struct cli_state *cli);
void cli_set_signing_negotiated(struct cli_state *cli);
+/* The following definitions come from libsmb/reparse_symlink.c */
+
+bool symlink_reparse_buffer_marshall(
+ const char *substitute, const char *printname, uint32_t flags,
+ TALLOC_CTX *mem_ctx, uint8_t **pdst, size_t *pdstlen);
+bool symlink_reparse_buffer_parse(
+ const uint8_t *src, size_t srclen, TALLOC_CTX *mem_ctx,
+ char **psubstitute_name, char **pprint_name, uint32_t *pflags);
+
+/* The following definitions come from libsmb/clisymlink.c */
+
+struct tevent_req *cli_symlink_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct cli_state *cli,
+ const char *oldpath,
+ const char *newpath,
+ uint32_t flags);
+NTSTATUS cli_symlink_recv(struct tevent_req *req);
+NTSTATUS cli_symlink(struct cli_state *cli, const char *oldname,
+ const char *newname, uint32_t flags);
+
#endif /* _LIBSMB_PROTO_H_ */
diff --git a/source3/libsmb/reparse_symlink.c b/source3/libsmb/reparse_symlink.c
new file mode 100644
index 0000000..9c158ee
--- /dev/null
+++ b/source3/libsmb/reparse_symlink.c
@@ -0,0 +1,174 @@
+/*
+ * Unix SMB/CIFS implementation.
+ *
+ * Implementation of
+ * http://msdn.microsoft.com/en-us/library/cc232006%28v=PROT.13%29.aspx
+ *
+ * Copyright (C) Volker Lendecke 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "include/client.h"
+#include "libsmb/proto.h"
+#include "include/ntioctl.h"
+
+bool symlink_reparse_buffer_marshall(
+ const char *substitute, const char *printname, uint32_t flags,
+ TALLOC_CTX *mem_ctx, uint8_t **pdst, size_t *pdstlen)
+{
+ uint8_t *dst = NULL;
+ size_t dst_len;
+ uint8_t *subst_utf16 = NULL;
+ uint8_t *print_utf16 = NULL;
+ size_t subst_len = 0;
+ size_t print_len = 0;
+
+ if (substitute == NULL) {
+ return false;
+ }
+ if (printname == NULL) {
+ printname = substitute;
+ }
+
+ if (!convert_string_talloc(talloc_tos(), CH_UNIX, CH_UTF16,
+ substitute, strlen(substitute),
+ &subst_utf16, &subst_len)) {
+ goto fail;
+ }
+ if (!convert_string_talloc(talloc_tos(), CH_UNIX, CH_UTF16,
+ printname, strlen(printname),
+ &print_utf16, &print_len)) {
+ goto fail;
+ }
+ dst_len = 20 + subst_len + print_len;
+ dst = talloc_array(mem_ctx, uint8_t, dst_len);
+ if (dst == NULL) {
+ goto fail;
+ }
+
+ SIVAL(dst, 0, IO_REPARSE_TAG_SYMLINK); /* ReparseTag */
+ SSVAL(dst, 4, 12 + subst_len + print_len); /* ReparseDataLength */
+ SSVAL(dst, 6, 0); /* Reserved */
+ SSVAL(dst, 8, 0); /* SubstituteNameOffset */
+ SSVAL(dst, 10, subst_len); /* SubstituteNameLength */
+ SSVAL(dst, 12, subst_len); /* PrintNameOffset */
+ SSVAL(dst, 14, print_len); /* PrintNameLength */
+ SIVAL(dst, 16, flags); /* Flags */
+
+ if ((subst_utf16 != NULL) && (subst_len != 0)) {
+ memcpy(dst + 20, subst_utf16, subst_len);
+ TALLOC_FREE(subst_utf16);
+ }
+
+ if ((print_utf16 != NULL) && (print_len != 0)) {
+ memcpy(dst + 20 + subst_len, print_utf16, print_len);
+ TALLOC_FREE(print_utf16);
+ }
+
+ *pdst = dst;
+ *pdstlen = dst_len;
+ return true;
+fail:
+ TALLOC_FREE(subst_utf16);
--
Samba Shared Repository
More information about the samba-cvs
mailing list