source: vendor/current/source3/lib/filename_util.c@ 740

Last change on this file since 740 was 740, checked in by Silvan Scherrer, 13 years ago

Samba Server: update vendor to 3.6.0

File size: 5.9 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 Filename utility functions.
4 Copyright (C) Tim Prouty 2009
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "includes.h"
20
21/**
22 * XXX: This is temporary and there should be no callers of this outside of
23 * this file once smb_filename is plumbed through all path based operations.
24 * The one legitimate caller currently is smb_fname_str_dbg(), which this
25 * could be made static for.
26 */
27NTSTATUS get_full_smb_filename(TALLOC_CTX *ctx,
28 const struct smb_filename *smb_fname,
29 char **full_name)
30{
31 if (smb_fname->stream_name) {
32 /* stream_name must always be NULL if there is no stream. */
33 SMB_ASSERT(smb_fname->stream_name[0] != '\0');
34
35 *full_name = talloc_asprintf(ctx, "%s%s", smb_fname->base_name,
36 smb_fname->stream_name);
37 } else {
38 *full_name = talloc_strdup(ctx, smb_fname->base_name);
39 }
40
41 if (!*full_name) {
42 return NT_STATUS_NO_MEMORY;
43 }
44
45 return NT_STATUS_OK;
46}
47
48/**
49 * There are actually legitimate callers of this such as functions that
50 * enumerate streams using the SMB_VFS_STREAMINFO interface and then want to
51 * operate on each stream.
52 */
53NTSTATUS create_synthetic_smb_fname(TALLOC_CTX *ctx, const char *base_name,
54 const char *stream_name,
55 const SMB_STRUCT_STAT *psbuf,
56 struct smb_filename **smb_fname_out)
57{
58 struct smb_filename smb_fname_loc;
59
60 ZERO_STRUCT(smb_fname_loc);
61
62 /* Setup the base_name/stream_name. */
63 smb_fname_loc.base_name = CONST_DISCARD(char *, base_name);
64 smb_fname_loc.stream_name = CONST_DISCARD(char *, stream_name);
65
66 /* Copy the psbuf if one was given. */
67 if (psbuf)
68 smb_fname_loc.st = *psbuf;