s3:libsmb: allow store_cldap_reply() to work with a ipv6 response
[samba.git] / source3 / modules / util_reparse.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * Utility functions for reparse points.
4  *
5  * Copyright (C) Jeremy Allison 2018
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "includes.h"
22 #include "util_reparse.h"
23
24 NTSTATUS fsctl_get_reparse_point(struct files_struct *fsp,
25                                  TALLOC_CTX *mem_ctx,
26                                  char **out_data,
27                                  uint32_t max_out_len,
28                                  uint32_t *out_len)
29 {
30         DBG_DEBUG("Called on %s\n", fsp_str_dbg(fsp));
31         return NT_STATUS_NOT_A_REPARSE_POINT;
32 }
33
34 static NTSTATUS check_reparse_data_buffer(
35         const uint8_t *in_data, size_t in_len)
36 {
37         uint16_t reparse_data_length;
38
39         if (in_len == 0) {
40                 DBG_DEBUG("in_len=0\n");
41                 return NT_STATUS_INVALID_BUFFER_SIZE;
42         }
43         if (in_len < 8) {
44                 DBG_DEBUG("in_len=%zu\n", in_len);
45                 return NT_STATUS_IO_REPARSE_DATA_INVALID;
46         }
47
48         reparse_data_length = PULL_LE_U16(in_data, 4);
49
50         if (reparse_data_length != (in_len - 8)) {
51                 DBG_DEBUG("in_len=%zu, reparse_data_length=%"PRIu16"\n",
52                           in_len,
53                           reparse_data_length);
54                 return NT_STATUS_IO_REPARSE_DATA_INVALID;
55         }
56
57         return NT_STATUS_OK;
58 }
59
60 NTSTATUS fsctl_set_reparse_point(struct files_struct *fsp,
61                                  TALLOC_CTX *mem_ctx,
62                                  const uint8_t *in_data,
63                                  uint32_t in_len)
64 {
65         NTSTATUS status;
66
67         DBG_DEBUG("Called on %s\n", fsp_str_dbg(fsp));
68
69         status = check_reparse_data_buffer(in_data, in_len);
70         if (!NT_STATUS_IS_OK(status)) {
71                 return status;
72         }
73
74         return NT_STATUS_NOT_A_REPARSE_POINT;
75 }
76
77 NTSTATUS fsctl_del_reparse_point(struct files_struct *fsp,
78                                  TALLOC_CTX *mem_ctx,
79                                  const uint8_t *in_data,
80                                  uint32_t in_len)
81 {
82         DBG_DEBUG("Called on %s\n", fsp_str_dbg(fsp));
83         return NT_STATUS_NOT_A_REPARSE_POINT;
84 }