summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorTim Prouty <tprouty@samba.org>2009-06-10 16:02:00 -0700
committerTim Prouty <tprouty@samba.org>2009-06-11 11:01:50 -0700
commit6eadb8a2855c729e742c72afcc9585adccc7bb12 (patch)
treef2c892665c7eff01652a70d113a38ae301bd8b6b /source3
parentcc216340a61d1d48a2b9844f66061b59c674465b (diff)
downloadsamba-6eadb8a2855c729e742c72afcc9585adccc7bb12.tar.gz
samba-6eadb8a2855c729e742c72afcc9585adccc7bb12.tar.bz2
samba-6eadb8a2855c729e742c72afcc9585adccc7bb12.zip
s3: refactor utility function to handle splitting the directory from the mask
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/reply.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index f91a3c7550..830cfca592 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -1327,6 +1327,38 @@ void reply_dskattr(struct smb_request *req)
return;
}
+/*
+ * Utility function to split the filename from the directory.
+ */
+static NTSTATUS split_fname_dir_mask(TALLOC_CTX *ctx, const char *fname_in,
+ char **fname_dir_out,
+ char **fname_mask_out)
+{
+ const char *p = NULL;
+ char *fname_dir = NULL;
+ char *fname_mask = NULL;
+
+ p = strrchr_m(fname_in, '/');
+ if (!p) {
+ fname_dir = talloc_strdup(ctx, ".");
+ fname_mask = talloc_strdup(ctx, fname_in);
+ } else {
+ fname_dir = talloc_strndup(ctx, fname_in,
+ PTR_DIFF(p, fname_in));
+ fname_mask = talloc_strdup(ctx, p+1);
+ }
+
+ if (!fname_dir || !fname_mask) {
+ TALLOC_FREE(fname_dir);
+ TALLOC_FREE(fname_mask);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ *fname_dir_out = fname_dir;
+ *fname_mask_out = fname_mask;
+ return NT_STATUS_OK;
+}
+
/****************************************************************************
Reply to a search.
Can be called from SMBsearch, SMBffirst or SMBfunique.
@@ -6727,17 +6759,9 @@ void reply_copy(struct smb_request *req)
}
/* Split up the directory from the filename/mask. */
- p = strrchr_m(smb_fname_src->base_name,'/');
- if (p != NULL) {
- fname_src_dir = talloc_strndup(ctx, smb_fname_src->base_name,
- PTR_DIFF(p, smb_fname_src->base_name));
- fname_src_mask = talloc_strdup(ctx, p+1);
- } else {
- fname_src_dir = talloc_strdup(ctx, "./");
- fname_src_mask = talloc_strdup(ctx, smb_fname_src->base_name);
- }
-
- if (!fname_src_dir || !fname_src_mask) {
+ status = split_fname_dir_mask(ctx, smb_fname_src->base_name,
+ &fname_src_dir, &fname_src_mask);
+ if (!NT_STATUS_IS_OK(status)) {
reply_nterror(req, NT_STATUS_NO_MEMORY);
goto out;
}