2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1994-1998
5 Copyright (C) Jeremy Allison 2001-2002
6 Copyright (C) James Myers 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 3 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, see <http://www.gnu.org/licenses/>.
23 #include "libcli/smb/smb_common.h"
24 #include "system/filesys.h"
27 Return a string representing a CIFS attribute for a file.
29 char *attrib_string(TALLOC_CTX
*mem_ctx
, uint32_t attrib
)
36 {'V', FILE_ATTRIBUTE_VOLUME
},
37 {'D', FILE_ATTRIBUTE_DIRECTORY
},
38 {'A', FILE_ATTRIBUTE_ARCHIVE
},
39 {'H', FILE_ATTRIBUTE_HIDDEN
},
40 {'S', FILE_ATTRIBUTE_SYSTEM
},
41 {'N', FILE_ATTRIBUTE_NORMAL
},
42 {'R', FILE_ATTRIBUTE_READONLY
},
43 {'d', FILE_ATTRIBUTE_DEVICE
},
44 {'t', FILE_ATTRIBUTE_TEMPORARY
},
45 {'s', FILE_ATTRIBUTE_SPARSE
},
46 {'r', FILE_ATTRIBUTE_REPARSE_POINT
},
47 {'c', FILE_ATTRIBUTE_COMPRESSED
},
48 {'o', FILE_ATTRIBUTE_OFFLINE
},
49 {'n', FILE_ATTRIBUTE_NONINDEXED
},
50 {'e', FILE_ATTRIBUTE_ENCRYPTED
}
54 ret
= talloc_array(mem_ctx
, char, ARRAY_SIZE(attr_strs
)+1);
59 for (len
=i
=0; i
<ARRAY_SIZE(attr_strs
); i
++) {
60 if (attrib
& attr_strs
[i
].attr
) {
61 ret
[len
++] = attr_strs
[i
].c
;
67 talloc_set_name_const(ret
, ret
);
72 /****************************************************************************
73 Map standard UNIX permissions onto wire representations.
74 ****************************************************************************/
76 uint32_t unix_perms_to_wire(mode_t perms
)
80 ret
|= ((perms
& S_IXOTH
) ? UNIX_X_OTH
: 0);
81 ret
|= ((perms
& S_IWOTH
) ? UNIX_W_OTH
: 0);
82 ret
|= ((perms
& S_IROTH
) ? UNIX_R_OTH
: 0);
83 ret
|= ((perms
& S_IXGRP
) ? UNIX_X_GRP
: 0);
84 ret
|= ((perms
& S_IWGRP
) ? UNIX_W_GRP
: 0);
85 ret
|= ((perms
& S_IRGRP
) ? UNIX_R_GRP
: 0);
86 ret
|= ((perms
& S_IXUSR
) ? UNIX_X_USR
: 0);
87 ret
|= ((perms
& S_IWUSR
) ? UNIX_W_USR
: 0);
88 ret
|= ((perms
& S_IRUSR
) ? UNIX_R_USR
: 0);
90 ret
|= ((perms
& S_ISVTX
) ? UNIX_STICKY
: 0);
93 ret
|= ((perms
& S_ISGID
) ? UNIX_SET_GID
: 0);
96 ret
|= ((perms
& S_ISUID
) ? UNIX_SET_UID
: 0);
101 /****************************************************************************
102 Map wire permissions to standard UNIX.
103 ****************************************************************************/
105 mode_t
wire_perms_to_unix(uint32_t perms
)
107 mode_t ret
= (mode_t
)0;
109 ret
|= ((perms
& UNIX_X_OTH
) ? S_IXOTH
: 0);
110 ret
|= ((perms
& UNIX_W_OTH
) ? S_IWOTH
: 0);
111 ret
|= ((perms
& UNIX_R_OTH
) ? S_IROTH
: 0);
112 ret
|= ((perms
& UNIX_X_GRP
) ? S_IXGRP
: 0);
113 ret
|= ((perms
& UNIX_W_GRP
) ? S_IWGRP
: 0);
114 ret
|= ((perms
& UNIX_R_GRP
) ? S_IRGRP
: 0);
115 ret
|= ((perms
& UNIX_X_USR
) ? S_IXUSR
: 0);
116 ret
|= ((perms
& UNIX_W_USR
) ? S_IWUSR
: 0);
117 ret
|= ((perms
& UNIX_R_USR
) ? S_IRUSR
: 0);
119 ret
|= ((perms
& UNIX_STICKY
) ? S_ISVTX
: 0);
122 ret
|= ((perms
& UNIX_SET_GID
) ? S_ISGID
: 0);
125 ret
|= ((perms
& UNIX_SET_UID
) ? S_ISUID
: 0);
130 /****************************************************************************
131 Return the file type from the wire filetype for UNIX extensions.
132 ****************************************************************************/
134 mode_t
unix_filetype_from_wire(uint32_t wire_type
)
142 case UNIX_TYPE_SYMLINK
:
146 case UNIX_TYPE_CHARDEV
:
150 case UNIX_TYPE_BLKDEV
:
158 case UNIX_TYPE_SOCKET
:
166 bool smb_buffer_oob(uint32_t bufsize
, uint32_t offset
, uint32_t length
)
168 if ((offset
+ length
< offset
) || (offset
+ length
< length
)) {
172 if ((offset
> bufsize
) || (offset
+ length
> bufsize
)) {