0f19788b9731d0587f5d3e6b50bb7f7aefd326c1
[kai/samba.git] / source4 / ntvfs / posix / pvfs_resolve.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend - filename resolution
5
6    Copyright (C) Andrew Tridgell 2004
7
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 3 of the License, or
11    (at your option) any later version.
12    
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.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 /*
23   this is the core code for converting a filename from the format as
24   given by a client to a posix filename, including any case-matching
25   required, and checks for legal characters
26 */
27
28
29 #include "includes.h"
30 #include "vfs_posix.h"
31 #include "system/dir.h"
32 #include "param/param.h"
33
34 /**
35   compare two filename components. This is where the name mangling hook will go
36 */
37 static int component_compare(struct pvfs_state *pvfs, const char *comp, const char *name)
38 {
39         int ret;
40
41         ret = strcasecmp_m(comp, name);
42
43         if (ret != 0) {
44                 char *shortname = pvfs_short_name_component(pvfs, name);
45                 if (shortname) {
46                         ret = strcasecmp_m(comp, shortname);
47                         talloc_free(shortname);
48                 }
49         }
50
51         return ret;
52 }
53
54 /*
55   search for a filename in a case insensitive fashion
56
57   TODO: add a cache for previously resolved case-insensitive names
58   TODO: add mangled name support
59 */
60 static NTSTATUS pvfs_case_search(struct pvfs_state *pvfs,
61                                  struct pvfs_filename *name,
62                                  uint_t flags)
63 {
64         /* break into a series of components */
65         int num_components;
66         char **components;
67         char *p, *partial_name;
68         int i;
69
70         /* break up the full name info pathname components */
71         num_components=2;
72         p = name->full_name + strlen(pvfs->base_directory) + 1;
73
74         for (;*p;p++) {
75                 if (*p == '/') {
76                         num_components++;
77                 }
78         }
79
80         components = talloc_array(name, char *, num_components);
81         p = name->full_name + strlen(pvfs->base_directory);
82         *p++ = 0;
83
84         components[0] = name->full_name;
85
86         for (i=1;i<num_components;i++) {
87                 components[i] = p;
88                 p = strchr(p, '/');
89                 if (p) *p++ = 0;
90                 if (pvfs_is_reserved_name(pvfs, components[i])) {
91                         return NT_STATUS_ACCESS_DENIED;
92                 }
93         }
94
95         partial_name = talloc_strdup(name, components[0]);
96         if (!partial_name) {
97                 return NT_STATUS_NO_MEMORY;
98         }
99
100         /* for each component, check if it exists as-is, and if not then
101            do a directory scan */
102         for (i=1;i<num_components;i++) {
103                 char *test_name;
104                 DIR *dir;
105                 struct dirent *de;
106                 char *long_component;
107
108                 /* possibly remap from the short name cache */
109                 long_component = pvfs_mangled_lookup(pvfs, name, components[i]);
110                 if (long_component) {
111                         components[i] = long_component;
112                 }
113
114                 test_name = talloc_asprintf(name, "%s/%s", partial_name, components[i]);
115                 if (!test_name) {
116                         return NT_STATUS_NO_MEMORY;
117                 }
118
119                 /* check if this component exists as-is */
120                 if (stat(test_name, &name->st) == 0) {
121                         if (i<num_components-1 && !S_ISDIR(name->st.st_mode)) {
122                                 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
123                         }
124                         talloc_free(partial_name);
125                         partial_name = test_name;
126                         if (i == num_components - 1) {
127                                 name->exists = true;
128                         }
129                         continue;
130                 }
131
132                 /* the filesystem might be case insensitive, in which
133                    case a search is pointless unless the name is
134                    mangled */
135                 if ((pvfs->flags & PVFS_FLAG_CI_FILESYSTEM) &&
136                     !pvfs_is_mangled_component(pvfs, components[i])) {
137                         if (i < num_components-1) {
138                                 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
139                         }
140                         partial_name = test_name;
141                         continue;
142                 }
143                 
144                 dir = opendir(partial_name);
145                 if (!dir) {
146                         return pvfs_map_errno(pvfs, errno);
147                 }
148
149                 while ((de = readdir(dir))) {
150                         if (component_compare(pvfs, components[i], de->d_name) == 0) {
151                                 break;
152                         }
153                 }
154
155                 if (!de) {
156                         if (i < num_components-1) {
157                                 closedir(dir);
158                                 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
159                         }
160                 } else {
161                         components[i] = talloc_strdup(name, de->d_name);
162                 }
163                 test_name = talloc_asprintf(name, "%s/%s", partial_name, components[i]);
164                 talloc_free(partial_name);
165                 partial_name = test_name;
166
167                 closedir(dir);
168         }
169
170         if (!name->exists) {
171                 if (stat(partial_name, &name->st) == 0) {
172                         name->exists = true;
173                 }
174         }
175
176         talloc_free(name->full_name);
177         name->full_name = partial_name;
178
179         if (name->exists) {
180                 return pvfs_fill_dos_info(pvfs, name, flags, -1);
181         }
182
183         return NT_STATUS_OK;
184 }
185
186 /*
187   parse a alternate data stream name
188 */
189 static NTSTATUS parse_stream_name(struct pvfs_filename *name, const char *s)
190 {
191         char *p;
192         name->stream_name = talloc_strdup(name, s+1);
193         if (name->stream_name == NULL) {
194                 return NT_STATUS_NO_MEMORY;
195         }
196         p = strchr_m(name->stream_name, ':');
197         if (p == NULL) {
198                 name->stream_id = pvfs_name_hash(name->stream_name, 
199                                                  strlen(name->stream_name));
200                 return NT_STATUS_OK;
201         }
202         if (strcasecmp_m(p, ":$DATA") != 0) {
203                 return NT_STATUS_OBJECT_NAME_INVALID;
204         }
205         *p = 0;
206         if (strcmp(name->stream_name, "") == 0) {
207                 /*
208                  * we don't set stream_name to NULL, here
209                  * as this would be wrong for directories
210                  *
211                  * pvfs_fill_dos_info() will set it to NULL
212                  * if it's not a directory.
213                  */
214                 name->stream_id = 0;
215         } else {
216                 name->stream_id = pvfs_name_hash(name->stream_name, 
217                                                  strlen(name->stream_name));
218         }
219                                                  
220         return NT_STATUS_OK;    
221 }
222
223
224 /*
225   convert a CIFS pathname to a unix pathname. Note that this does NOT
226   take into account case insensitivity, and in fact does not access
227   the filesystem at all. It is merely a reformatting and charset
228   checking routine.
229
230   errors are returned if the filename is illegal given the flags
231 */
232 static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name,
233                                uint_t flags, struct pvfs_filename *name)
234 {
235         char *ret, *p, *p_start;
236         NTSTATUS status;
237
238         name->original_name = talloc_strdup(name, cifs_name);
239         name->stream_name = NULL;
240         name->stream_id = 0;
241         name->has_wildcard = false;
242
243         while (*cifs_name == '\\') {
244                 cifs_name++;
245         }
246
247         if (*cifs_name == 0) {
248                 name->full_name = talloc_asprintf(name, "%s/.", pvfs->base_directory);
249                 if (name->full_name == NULL) {
250                         return NT_STATUS_NO_MEMORY;
251                 }
252                 return NT_STATUS_OK;
253         }
254
255         ret = talloc_asprintf(name, "%s/%s", pvfs->base_directory, cifs_name);
256         if (ret == NULL) {
257                 return NT_STATUS_NO_MEMORY;
258         }
259
260         p = ret + strlen(pvfs->base_directory) + 1;
261
262         /* now do an in-place conversion of '\' to '/', checking
263            for legal characters */
264         p_start = p;
265
266         while (*p) {
267                 size_t c_size;
268                 codepoint_t c = next_codepoint(lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx), p, &c_size);
269                 switch (c) {
270                 case '\\':
271                         if (name->has_wildcard) {
272                                 /* wildcards are only allowed in the last part
273                                    of a name */
274                                 return NT_STATUS_ILLEGAL_CHARACTER;
275                         }
276                         if (p > p_start && (p[1] == '\\' || p[1] == '\0')) {
277                                 /* see if it is definately a "\\" or
278                                  * a trailing "\". If it is then fail here,
279                                  * and let the next layer up try again after
280                                  * pvfs_reduce_name() if it wants to. This is
281                                  * much more efficient on average than always
282                                  * scanning for these separately
283                                  */
284                                 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
285                         } else {
286                                 *p = '/';
287                         }
288                         break;
289                 case ':':
290                         if (!(flags & PVFS_RESOLVE_STREAMS)) {
291                                 return NT_STATUS_ILLEGAL_CHARACTER;
292                         }
293                         if (name->has_wildcard) {
294                                 return NT_STATUS_ILLEGAL_CHARACTER;
295                         }
296                         status = parse_stream_name(name, p);
297                         if (!NT_STATUS_IS_OK(status)) {
298                                 return status;
299                         }
300                         *p-- = 0;
301                         break;
302                 case '*':
303                 case '>':
304                 case '<':
305                 case '?':
306                 case '"':
307                         if (!(flags & PVFS_RESOLVE_WILDCARD)) {
308                                 return NT_STATUS_OBJECT_NAME_INVALID;
309                         }
310                         name->has_wildcard = true;
311                         break;
312                 case '/':
313                 case '|':
314                         return NT_STATUS_ILLEGAL_CHARACTER;
315                 case '.':
316                         /* see if it is definately a .. or
317                            . component. If it is then fail here, and
318                            let the next layer up try again after
319                            pvfs_reduce_name() if it wants to. This is
320                            much more efficient on average than always
321                            scanning for these separately */
322                         if (p[1] == '.' && 
323                             (p[2] == 0 || p[2] == '\\') &&
324                             (p == p_start || p[-1] == '/')) {
325                                 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
326                         }
327                         if ((p[1] == 0 || p[1] == '\\') &&
328                             (p == p_start || p[-1] == '/')) {
329                                 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
330                         }
331                         break;
332                 }
333
334                 p += c_size;
335         }
336
337         name->full_name = ret;
338
339         return NT_STATUS_OK;
340 }
341
342
343 /*
344   reduce a name that contains .. components or repeated \ separators
345   return NULL if it can't be reduced
346 */
347 static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx, 
348                                  struct smb_iconv_convenience *iconv_convenience, 
349                                  const char **fname, uint_t flags)
350 {
351         codepoint_t c;
352         size_t c_size, len;
353         int i, num_components, err_count;
354         char **components;
355         char *p, *s, *ret;
356
357         s = talloc_strdup(mem_ctx, *fname);
358         if (s == NULL) return NT_STATUS_NO_MEMORY;
359
360         for (num_components=1, p=s; *p; p += c_size) {
361                 c = next_codepoint(iconv_convenience, p, &c_size);
362                 if (c == '\\') num_components++;
363         }
364
365         components = talloc_array(s, char *, num_components+1);
366         if (components == NULL) {
367                 talloc_free(s);
368                 return NT_STATUS_NO_MEMORY;
369         }
370
371         components[0] = s;
372         for (i=0, p=s; *p; p += c_size) {
373                 c = next_codepoint(iconv_convenience, p, &c_size);
374                 if (c == '\\') {
375                         *p = 0;
376                         components[++i] = p+1;
377                 }
378         }
379         components[i+1] = NULL;
380
381         /*
382           rather bizarre!
383
384           '.' components are not allowed, but the rules for what error
385           code to give don't seem to make sense. This is a close
386           approximation.
387         */
388         for (err_count=i=0;components[i];i++) {
389                 if (strcmp(components[i], "") == 0) {
390                         continue;
391                 }
392                 if (ISDOT(components[i]) || err_count) {
393                         err_count++;
394                 }
395         }
396         if (err_count) {
397                 if (flags & PVFS_RESOLVE_WILDCARD) err_count--;
398
399                 if (err_count==1) {
400                         return NT_STATUS_OBJECT_NAME_INVALID;
401                 } else {
402                         return NT_STATUS_OBJECT_PATH_NOT_FOUND;
403                 }
404         }
405
406         /* remove any null components */
407         for (i=0;components[i];i++) {
408                 if (strcmp(components[i], "") == 0) {
409                         memmove(&components[i], &components[i+1], 
410                                 sizeof(char *)*(num_components-i));
411                         i--;
412                         continue;
413                 }
414                 if (ISDOTDOT(components[i])) {
415                         if (i < 1) return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
416                         memmove(&components[i-1], &components[i+1], 
417                                 sizeof(char *)*(num_components-i));
418                         i -= 2;
419                         continue;
420                 }
421         }
422
423         if (components[0] == NULL) {
424                 talloc_free(s);
425                 *fname = talloc_strdup(mem_ctx, "\\");
426                 return NT_STATUS_OK;
427         }
428
429         for (len=i=0;components[i];i++) {
430                 len += strlen(components[i]) + 1;
431         }
432
433         /* rebuild the name */
434         ret = talloc_size(mem_ctx, len+1);
435         if (ret == NULL) {
436                 talloc_free(s);
437                 return NT_STATUS_NO_MEMORY;
438         }
439
440         for (len=0,i=0;components[i];i++) {
441                 size_t len1 = strlen(components[i]);
442                 ret[len] = '\\';
443                 memcpy(ret+len+1, components[i], len1);
444                 len += len1 + 1;
445         }       
446         ret[len] = 0;
447
448         talloc_free(s);
449
450         *fname = ret;
451         
452         return NT_STATUS_OK;
453 }
454
455
456 /*
457   resolve a name from relative client format to a struct pvfs_filename
458   the memory for the filename is made as a talloc child of 'name'
459
460   flags include:
461      PVFS_RESOLVE_NO_WILDCARD = wildcards are considered illegal characters
462      PVFS_RESOLVE_STREAMS     = stream names are allowed
463
464      TODO: ../ collapsing, and outside share checking
465 */
466 NTSTATUS pvfs_resolve_name(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
467                            const char *cifs_name,
468                            uint_t flags, struct pvfs_filename **name)
469 {
470         NTSTATUS status;
471
472         *name = talloc(mem_ctx, struct pvfs_filename);
473         if (*name == NULL) {
474                 return NT_STATUS_NO_MEMORY;
475         }
476
477         (*name)->exists = false;
478         (*name)->stream_exists = false;
479
480         if (!(pvfs->fs_attribs & FS_ATTR_NAMED_STREAMS)) {
481                 flags &= ~PVFS_RESOLVE_STREAMS;
482         }
483
484         /* do the basic conversion to a unix formatted path,
485            also checking for allowable characters */
486         status = pvfs_unix_path(pvfs, cifs_name, flags, *name);
487
488         if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD)) {
489                 /* it might contain .. components which need to be reduced */
490                 status = pvfs_reduce_name(*name, lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx), &cifs_name, flags);
491                 if (!NT_STATUS_IS_OK(status)) {
492                         return status;
493                 }
494                 status = pvfs_unix_path(pvfs, cifs_name, flags, *name);
495         }
496
497         if (!NT_STATUS_IS_OK(status)) {
498                 return status;
499         }
500
501         /* if it has a wildcard then no point doing a stat() of the
502            full name. Instead We need check if the directory exists 
503          */
504         if ((*name)->has_wildcard) {
505                 const char *p;
506                 char *dir_name, *saved_name;
507                 p = strrchr((*name)->full_name, '/');
508                 if (p == NULL) {
509                         /* root directory wildcard is OK */
510                         return NT_STATUS_OK;
511                 }
512                 dir_name = talloc_strndup(*name, (*name)->full_name, (p-(*name)->full_name));
513                 if (stat(dir_name, &(*name)->st) == 0) {
514                         talloc_free(dir_name);
515                         return NT_STATUS_OK;
516                 }
517                 /* we need to search for a matching name */
518                 saved_name = (*name)->full_name;
519                 (*name)->full_name = dir_name;
520                 status = pvfs_case_search(pvfs, *name, flags);
521                 if (!NT_STATUS_IS_OK(status)) {
522                         /* the directory doesn't exist */
523                         (*name)->full_name = saved_name;
524                         return status;
525                 }
526                 /* it does exist, but might need a case change */
527                 if (dir_name != (*name)->full_name) {
528                         (*name)->full_name = talloc_asprintf(*name, "%s%s",
529                                                              (*name)->full_name, p);
530                         NT_STATUS_HAVE_NO_MEMORY((*name)->full_name);
531                 } else {
532                         (*name)->full_name = saved_name;
533                         talloc_free(dir_name);
534                 }
535                 return NT_STATUS_OK;
536         }
537
538         /* if we can stat() the full name now then we are done */
539         if (stat((*name)->full_name, &(*name)->st) == 0) {
540                 (*name)->exists = true;
541                 return pvfs_fill_dos_info(pvfs, *name, flags, -1);
542         }
543
544         /* search for a matching filename */
545         status = pvfs_case_search(pvfs, *name, flags);
546
547         return status;
548 }
549
550
551 /*
552   do a partial resolve, returning a pvfs_filename structure given a
553   base path and a relative component. It is an error if the file does
554   not exist. No case-insensitive matching is done.
555
556   this is used in places like directory searching where we need a pvfs_filename
557   to pass to a function, but already know the unix base directory and component
558 */
559 NTSTATUS pvfs_resolve_partial(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
560                               const char *unix_dir, const char *fname,
561                               uint_t flags, struct pvfs_filename **name)
562 {
563         NTSTATUS status;
564
565         *name = talloc(mem_ctx, struct pvfs_filename);
566         if (*name == NULL) {
567                 return NT_STATUS_NO_MEMORY;
568         }
569
570         (*name)->full_name = talloc_asprintf(*name, "%s/%s", unix_dir, fname);
571         if ((*name)->full_name == NULL) {
572                 return NT_STATUS_NO_MEMORY;
573         }
574
575         if (stat((*name)->full_name, &(*name)->st) == -1) {
576                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
577         }
578
579         (*name)->exists = true;
580         (*name)->stream_exists = true;
581         (*name)->has_wildcard = false;
582         (*name)->original_name = talloc_strdup(*name, fname);
583         (*name)->stream_name = NULL;
584         (*name)->stream_id = 0;
585
586         status = pvfs_fill_dos_info(pvfs, *name, flags, -1);
587
588         return status;
589 }
590
591
592 /*
593   fill in the pvfs_filename info for an open file, given the current
594   info for a (possibly) non-open file. This is used by places that need
595   to update the pvfs_filename stat information, and by pvfs_open()
596 */
597 NTSTATUS pvfs_resolve_name_fd(struct pvfs_state *pvfs, int fd,
598                               struct pvfs_filename *name, uint_t flags)
599 {
600         dev_t device = (dev_t)0;
601         ino_t inode = 0;
602
603         if (name->exists) {
604                 device = name->st.st_dev;
605                 inode = name->st.st_ino;
606         }
607
608         if (fd == -1) {
609                 if (stat(name->full_name, &name->st) == -1) {
610                         return NT_STATUS_INVALID_HANDLE;
611                 }
612         } else {
613                 if (fstat(fd, &name->st) == -1) {
614                         return NT_STATUS_INVALID_HANDLE;
615                 }
616         }
617
618         if (name->exists &&
619             (device != name->st.st_dev || inode != name->st.st_ino)) {
620                 /* the file we are looking at has changed! this could
621                  be someone trying to exploit a race
622                  condition. Certainly we don't want to continue
623                  operating on this file */
624                 DEBUG(0,("pvfs: WARNING: file '%s' changed during resolve - failing\n",
625                          name->full_name));
626                 return NT_STATUS_UNEXPECTED_IO_ERROR;
627         }
628
629         name->exists = true;
630         
631         return pvfs_fill_dos_info(pvfs, name, flags, fd);
632 }
633
634 /*
635   fill in the pvfs_filename info for an open file, given the current
636   info for a (possibly) non-open file. This is used by places that need
637   to update the pvfs_filename stat information, and the path
638   after a possible rename on a different handle.
639 */
640 NTSTATUS pvfs_resolve_name_handle(struct pvfs_state *pvfs,
641                                   struct pvfs_file_handle *h)
642 {
643         NTSTATUS status;
644
645         if (h->have_opendb_entry) {
646                 struct odb_lock *lck;
647                 const char *name = NULL;
648
649                 lck = odb_lock(h, h->pvfs->odb_context, &h->odb_locking_key);
650                 if (lck == NULL) {
651                         DEBUG(0,("%s: failed to lock file '%s' in opendb\n",
652                                  __FUNCTION__, h->name->full_name));
653                         /* we were supposed to do a blocking lock, so something
654                            is badly wrong! */
655                         return NT_STATUS_INTERNAL_DB_CORRUPTION;
656                 }
657
658                 status = odb_get_path(lck, &name);
659                 if (NT_STATUS_IS_OK(status)) {
660                         /*
661                          * This relies an the fact that
662                          * renames of open files are only
663                          * allowed by setpathinfo() and setfileinfo()
664                          * and there're only renames within the same
665                          * directory supported
666                          */
667                         if (strcmp(h->name->full_name, name) != 0) {
668                                 const char *orig_dir;
669                                 const char *new_file;
670                                 const char *new_orig;
671                                 char *delim;
672
673                                 delim = strrchr(name, '/');
674                                 if (!delim) {
675                                         talloc_free(lck);
676                                         return NT_STATUS_INTERNAL_ERROR;
677                                 }
678
679                                 new_file = delim + 1;
680                                 delim = strrchr(h->name->original_name, '\\');
681                                 if (delim) {
682                                         delim[0] = '\0';
683                                         orig_dir = h->name->original_name;
684                                         new_orig = talloc_asprintf(h->name, "%s\\%s",
685                                                                    orig_dir, new_file);
686                                         if (!new_orig) {
687                                                 talloc_free(lck);
688                                                 return NT_STATUS_NO_MEMORY;
689                                         }
690                                 } else {
691                                         new_orig = talloc_strdup(h->name, new_file);
692                                         if (!new_orig) {
693                                                 talloc_free(lck);
694                                                 return NT_STATUS_NO_MEMORY;
695                                         }
696                                 }
697
698                                 talloc_free(h->name->original_name);
699                                 talloc_free(h->name->full_name);
700                                 h->name->full_name = talloc_steal(h->name, name);
701                                 h->name->original_name = new_orig;
702                         }
703                 }
704
705                 talloc_free(lck);
706         }
707
708         /*
709          * TODO: pass PVFS_RESOLVE_NO_OPENDB and get
710          *       the write time from odb_lock() above.
711          */
712         status = pvfs_resolve_name_fd(pvfs, h->fd, h->name, 0);
713         NT_STATUS_NOT_OK_RETURN(status);
714
715         if (!null_nttime(h->write_time.close_time)) {
716                 h->name->dos.write_time = h->write_time.close_time;
717         }
718
719         return NT_STATUS_OK;
720 }
721
722
723 /*
724   resolve the parent of a given name
725 */
726 NTSTATUS pvfs_resolve_parent(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
727                              const struct pvfs_filename *child,
728                              struct pvfs_filename **name)
729 {
730         NTSTATUS status;
731         char *p;
732
733         *name = talloc(mem_ctx, struct pvfs_filename);
734         if (*name == NULL) {
735                 return NT_STATUS_NO_MEMORY;
736         }
737
738         (*name)->full_name = talloc_strdup(*name, child->full_name);
739         if ((*name)->full_name == NULL) {
740                 return NT_STATUS_NO_MEMORY;
741         }
742
743         p = strrchr_m((*name)->full_name, '/');
744         if (p == NULL) {
745                 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
746         }
747
748         /* this handles the root directory */
749         if (p == (*name)->full_name) {
750                 p[1] = 0;
751         } else {
752                 p[0] = 0;
753         }
754
755         if (stat((*name)->full_name, &(*name)->st) == -1) {
756                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
757         }
758
759         (*name)->exists = true;
760         (*name)->stream_exists = true;
761         (*name)->has_wildcard = false;
762         /* we can't get the correct 'original_name', but for the purposes
763            of this call this is close enough */
764         (*name)->original_name = talloc_reference(*name, child->original_name);
765         (*name)->stream_name = NULL;
766         (*name)->stream_id = 0;
767
768         status = pvfs_fill_dos_info(pvfs, *name, PVFS_RESOLVE_NO_OPENDB, -1);
769
770         return status;
771 }