r3240: - update the rules for what error codes should be given on the
[jelmer/samba4-debian.git] / source / ntvfs / posix / pvfs_util.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Copyright (C) Andrew Tridgell 2004
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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /*
21   utility functions for posix backend
22 */
23
24 #include "includes.h"
25 #include "vfs_posix.h"
26
27 /*
28   return True if a string contains one of the CIFS wildcard characters
29 */
30 BOOL pvfs_has_wildcard(const char *str)
31 {
32         if (strpbrk(str, "*?<>\"")) {
33                 return True;
34         }
35         return False;
36 }
37
38 /*
39   map a unix errno to a NTSTATUS
40 */
41 NTSTATUS pvfs_map_errno(struct pvfs_state *pvfs, int unix_errno)
42 {
43         return map_nt_error_from_unix(unix_errno);
44 }
45
46
47 /*
48   check if a filename has an attribute matching the given attribute search value
49   this is used by calls like unlink and search which take an attribute
50   and only include special files if they match the given attribute
51 */
52 NTSTATUS pvfs_match_attrib(struct pvfs_state *pvfs, struct pvfs_filename *name, 
53                            uint32_t attrib, uint32_t must_attrib)
54 {
55         if ((name->dos.attrib & ~attrib) & FILE_ATTRIBUTE_DIRECTORY) {
56                 return NT_STATUS_FILE_IS_A_DIRECTORY;
57         }
58         if ((name->dos.attrib & ~attrib) & (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)) {
59                 return NT_STATUS_NO_SUCH_FILE;
60         }
61         if (must_attrib & ~name->dos.attrib) {
62                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
63         }
64         return NT_STATUS_OK;
65 }