/src/samba/libcli/smb/smb2_lease.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | Unix SMB/CIFS implementation. |
3 | | |
4 | | SMB2 Lease context handling |
5 | | |
6 | | Copyright (C) Stefan Metzmacher 2012 |
7 | | Copyright (C) Volker Lendecke 2013 |
8 | | |
9 | | This program is free software; you can redistribute it and/or modify |
10 | | it under the terms of the GNU General Public License as published by |
11 | | the Free Software Foundation; either version 3 of the License, or |
12 | | (at your option) any later version. |
13 | | |
14 | | This program is distributed in the hope that it will be useful, |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | GNU General Public License for more details. |
18 | | |
19 | | You should have received a copy of the GNU General Public License |
20 | | along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | #include "includes.h" |
24 | | #include "../libcli/smb/smb_common.h" |
25 | | |
26 | | /** |
27 | | * Pull a lease off the wire into a struct smb2_lease. |
28 | | * |
29 | | * Note: the caller MUST zero initialize "lease". |
30 | | **/ |
31 | | ssize_t smb2_lease_pull(const uint8_t *buf, size_t len, |
32 | | struct smb2_lease *lease) |
33 | 0 | { |
34 | 0 | int version; |
35 | |
|
36 | 0 | switch (len) { |
37 | 0 | case 32: |
38 | 0 | version = 1; |
39 | 0 | break; |
40 | 0 | case 52: |
41 | 0 | version = 2; |
42 | 0 | break; |
43 | 0 | default: |
44 | 0 | return -1; |
45 | 0 | } |
46 | | |
47 | 0 | lease->lease_key.data[0] = PULL_LE_U64(buf, 0); |
48 | 0 | lease->lease_key.data[1] = PULL_LE_U64(buf, 8); |
49 | 0 | lease->lease_state = PULL_LE_U32(buf, 16); |
50 | 0 | lease->lease_version = version; |
51 | |
|
52 | 0 | switch (version) { |
53 | 0 | case 1: |
54 | 0 | break; |
55 | 0 | case 2: |
56 | 0 | lease->lease_flags = PULL_LE_U32(buf, 20); |
57 | 0 | lease->lease_duration = PULL_LE_U64(buf, 24); |
58 | 0 | lease->lease_flags &= SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET; |
59 | 0 | if (lease->lease_flags & SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET) { |
60 | 0 | lease->parent_lease_key.data[0] = PULL_LE_U64(buf, 32); |
61 | 0 | lease->parent_lease_key.data[1] = PULL_LE_U64(buf, 40); |
62 | 0 | } |
63 | 0 | lease->lease_epoch = PULL_LE_U16(buf, 48); |
64 | 0 | break; |
65 | 0 | } |
66 | | |
67 | 0 | return len; |
68 | 0 | } |
69 | | |
70 | | bool smb2_lease_push(const struct smb2_lease *lease, uint8_t *buf, size_t len) |
71 | 0 | { |
72 | 0 | int version; |
73 | |
|
74 | 0 | switch (len) { |
75 | 0 | case 32: |
76 | 0 | version = 1; |
77 | 0 | break; |
78 | 0 | case 52: |
79 | 0 | version = 2; |
80 | 0 | break; |
81 | 0 | default: |
82 | 0 | return false; |
83 | 0 | } |
84 | | |
85 | 0 | PUSH_LE_U64(buf, 0, lease->lease_key.data[0]); |
86 | 0 | PUSH_LE_U64(buf, 8, lease->lease_key.data[1]); |
87 | 0 | PUSH_LE_U32(buf, 16, lease->lease_state); |
88 | 0 | PUSH_LE_U32(buf, 20, lease->lease_flags); |
89 | 0 | PUSH_LE_U64(buf, 24, lease->lease_duration); |
90 | |
|
91 | 0 | if (version == 2) { |
92 | 0 | PUSH_LE_U64(buf, 32, lease->parent_lease_key.data[0]); |
93 | 0 | PUSH_LE_U64(buf, 40, lease->parent_lease_key.data[1]); |
94 | 0 | PUSH_LE_U16(buf, 48, lease->lease_epoch); |
95 | 0 | PUSH_LE_U16(buf, 50, 0); /* reserved */ |
96 | 0 | } |
97 | |
|
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | | bool smb2_lease_key_equal(const struct smb2_lease_key *k1, |
102 | | const struct smb2_lease_key *k2) |
103 | 0 | { |
104 | 0 | return ((k1->data[0] == k2->data[0]) && (k1->data[1] == k2->data[1])); |
105 | 0 | } |
106 | | |
107 | | bool smb2_lease_equal(const struct GUID *g1, |
108 | | const struct smb2_lease_key *k1, |
109 | | const struct GUID *g2, |
110 | | const struct smb2_lease_key *k2) |
111 | 0 | { |
112 | 0 | return GUID_equal(g1, g2) && smb2_lease_key_equal(k1, k2); |
113 | 0 | } |