2 Unix SMB/CIFS implementation.
4 simple NTVFS filesystem backend
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 utility functions for simple backend
30 convert a windows path to a unix path - don't do any manging or case sensitive handling
32 char *svfs_unix_path(struct smbsrv_request *req, const char *name)
34 struct svfs_private *private = req->conn->ntvfs_private;
38 ret = talloc_asprintf(req->mem_ctx, "%s/%s", private->connectpath, name);
40 ret = talloc_asprintf(req->mem_ctx, "%s%s", private->connectpath, name);
42 all_string_sub(ret, "\\", "/", 0);
51 read a directory and find all matching file names and stat info
52 returned names are separate unix and DOS names. The returned names
53 are relative to the directory
55 struct svfs_dir *svfs_list(TALLOC_CTX *mem_ctx, struct smbsrv_request *req, const char *pattern)
65 unix_path = svfs_unix_path(req, pattern);
66 if (!unix_path) { return NULL; }
68 dir = talloc(mem_ctx, sizeof(struct svfs_dir));
69 if (!dir) { return NULL; }
74 /* find the base directory */
75 p = strrchr(unix_path, '/');
76 if (!p) { return NULL; }
78 dir->unix_dir = talloc_strndup(mem_ctx, unix_path, PTR_DIFF(p, unix_path));
79 if (!dir->unix_dir) { return NULL; }
81 /* the wildcard pattern is the last part */
84 low_mask = talloc_strdup(mem_ctx, mask);
85 if (!low_mask) { return NULL; }
88 odir = opendir(dir->unix_dir);
89 if (!odir) { return NULL; }
91 while ((dent = readdir(odir))) {
92 uint_t i = dir->count;
96 low_name = talloc_strdup(mem_ctx, dent->d_name);
97 if (!low_name) { continue; }
100 /* check it matches the wildcard pattern */
101 if (ms_fnmatch(low_mask, low_name, PROTOCOL_NT1) != 0) {
105 if (dir->count >= allocated) {
106 allocated = (allocated + 100) * 1.2;
107 dir->files = talloc_realloc(dir->files, allocated * sizeof(dir->files[0]));
114 dir->files[i].name = low_name;
115 if (!dir->files[i].name) { continue; }
117 asprintf(&full_name, "%s/%s", dir->unix_dir, dir->files[i].name);
118 if (!full_name) { continue; }
120 if (stat(full_name, &dir->files[i].st) == 0) {
134 convert a unix stat struct to a dos attrib
136 uint32_t svfs_file_attrib(struct stat *st)
138 if (S_ISDIR(st->st_mode)) {
139 return FILE_ATTRIBUTE_DIRECTORY;