2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan (metze) Metzmacher 2003
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 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "libsmb/libsmb.h"
22 #include "../librpc/gen_ndr/ndr_security.h"
23 #include "fake_file.h"
24 #include "../libcli/security/security.h"
27 NTSTATUS
cli_get_quota_handle(struct cli_state
*cli
, uint16_t *quota_fnum
)
29 return cli_ntcreate(cli
, FAKE_FILE_NAME_QUOTA_WIN32
,
30 0x00000016, DESIRED_ACCESS_PIPE
,
31 0x00000000, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
32 FILE_OPEN
, 0x00000000, 0x03, quota_fnum
);
35 void free_ntquota_list(SMB_NTQUOTA_LIST
**qt_list
)
40 if ((*qt_list
)->mem_ctx
)
41 talloc_destroy((*qt_list
)->mem_ctx
);
48 static bool parse_user_quota_record(const uint8_t *rdata
,
49 unsigned int rdata_count
,
51 SMB_NTQUOTA_STRUCT
*pqt
)
54 SMB_NTQUOTA_STRUCT qt
;
58 if (!rdata
||!offset
||!pqt
) {
59 smb_panic("parse_quota_record: called with NULL POINTER!");
62 if (rdata_count
< 40) {
66 /* offset to next quota record.
67 * 4 bytes IVAL(rdata,0)
70 *offset
= IVAL(rdata
,0);
73 sid_len
= IVAL(rdata
,4);
75 if (rdata_count
< 40+sid_len
) {
79 /* unknown 8 bytes in pdata
80 * maybe its the change time in NTTIME
83 /* the used space 8 bytes (uint64_t)*/
84 qt
.usedspace
= BVAL(rdata
,16);
86 /* the soft quotas 8 bytes (uint64_t)*/
87 qt
.softlim
= BVAL(rdata
,24);
89 /* the hard quotas 8 bytes (uint64_t)*/
90 qt
.hardlim
= BVAL(rdata
,32);
92 if (!sid_parse((char *)rdata
+40,sid_len
,&qt
.sid
)) {
96 qt
.qtype
= SMB_USER_QUOTA_TYPE
;
103 NTSTATUS
cli_get_user_quota(struct cli_state
*cli
, int quota_fnum
,
104 SMB_NTQUOTA_STRUCT
*pqt
)
108 unsigned int data_len
;
109 uint8_t data
[SID_MAX_SIZE
+8];
110 uint8_t *rparam
, *rdata
;
111 uint32_t rparam_count
, rdata_count
;
112 unsigned int sid_len
;
117 smb_panic("cli_get_user_quota() called with NULL Pointer!");
120 SSVAL(setup
+ 0, 0, NT_TRANSACT_GET_USER_QUOTA
);
122 SSVAL(params
, 0,quota_fnum
);
123 SSVAL(params
, 2,TRANSACT_GET_USER_QUOTA_FOR_SID
);
124 SIVAL(params
, 4,0x00000024);
125 SIVAL(params
, 8,0x00000000);
126 SIVAL(params
,12,0x00000024);
128 sid_len
= ndr_size_dom_sid(&pqt
->sid
, 0);
129 data_len
= sid_len
+8;
130 SIVAL(data
, 0, 0x00000000);
131 SIVAL(data
, 4, sid_len
);
132 sid_linearize((char *)data
+8, sid_len
, &pqt
->sid
);
134 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
135 NULL
, -1, /* name, fid */
136 NT_TRANSACT_GET_USER_QUOTA
, 0,
137 setup
, 1, 0, /* setup */
138 params
, 16, 4, /* params */
139 data
, data_len
, 112, /* data */
140 NULL
, /* recv_flags2 */
141 NULL
, 0, NULL
, /* rsetup */
142 &rparam
, 4, &rparam_count
,
143 &rdata
, 8, &rdata_count
);
144 if (!NT_STATUS_IS_OK(status
)) {
145 DEBUG(1, ("NT_TRANSACT_GET_USER_QUOTA failed: %s\n",
150 if (!parse_user_quota_record(rdata
, rdata_count
, &offset
, pqt
)) {
151 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
152 DEBUG(0,("Got INVALID NT_TRANSACT_GET_USER_QUOTA reply.\n"));
160 NTSTATUS
cli_set_user_quota(struct cli_state
*cli
, int quota_fnum
,
161 SMB_NTQUOTA_STRUCT
*pqt
)
166 unsigned int sid_len
;
169 memset(data
,'\0',112);
172 smb_panic("cli_set_user_quota() called with NULL Pointer!");
175 SSVAL(setup
+ 0, 0, NT_TRANSACT_SET_USER_QUOTA
);
177 SSVAL(params
,0,quota_fnum
);
179 sid_len
= ndr_size_dom_sid(&pqt
->sid
, 0);
181 SIVAL(data
,4,sid_len
);
182 SBIG_UINT(data
, 8,(uint64_t)0);
183 SBIG_UINT(data
,16,pqt
->usedspace
);
184 SBIG_UINT(data
,24,pqt
->softlim
);
185 SBIG_UINT(data
,32,pqt
->hardlim
);
186 sid_linearize((char *)data
+40, sid_len
, &pqt
->sid
);
188 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
189 NULL
, -1, /* name, fid */
190 NT_TRANSACT_SET_USER_QUOTA
, 0,
191 setup
, 1, 0, /* setup */
192 params
, 2, 0, /* params */
193 data
, 112, 0, /* data */
194 NULL
, /* recv_flags2 */
195 NULL
, 0, NULL
, /* rsetup */
196 NULL
, 0, NULL
, /* rparams */
197 NULL
, 0, NULL
); /* rdata */
199 if (!NT_STATUS_IS_OK(status
)) {
200 DEBUG(1, ("NT_TRANSACT_SET_USER_QUOTA failed: %s\n",
207 NTSTATUS
cli_list_user_quota(struct cli_state
*cli
, int quota_fnum
,
208 SMB_NTQUOTA_LIST
**pqt_list
)
212 uint8_t *rparam
=NULL
, *rdata
=NULL
;
213 uint32_t rparam_count
=0, rdata_count
=0;
215 const uint8_t *curdata
= NULL
;
216 unsigned int curdata_count
= 0;
217 TALLOC_CTX
*mem_ctx
= NULL
;
218 SMB_NTQUOTA_STRUCT qt
;
219 SMB_NTQUOTA_LIST
*tmp_list_ent
;
222 if (!cli
||!pqt_list
) {
223 smb_panic("cli_list_user_quota() called with NULL Pointer!");
226 SSVAL(setup
+ 0, 0, NT_TRANSACT_GET_USER_QUOTA
);
228 SSVAL(params
, 0,quota_fnum
);
229 SSVAL(params
, 2,TRANSACT_GET_USER_QUOTA_LIST_START
);
230 SIVAL(params
, 4,0x00000000);
231 SIVAL(params
, 8,0x00000000);
232 SIVAL(params
,12,0x00000000);
234 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
235 NULL
, -1, /* name, fid */
236 NT_TRANSACT_GET_USER_QUOTA
, 0,
237 setup
, 1, 0, /* setup */
238 params
, 16, 4, /* params */
239 NULL
, 0, 2048, /* data */
240 NULL
, /* recv_flags2 */
241 NULL
, 0, NULL
, /* rsetup */
242 &rparam
, 0, &rparam_count
,
243 &rdata
, 0, &rdata_count
);
245 if (!NT_STATUS_IS_OK(status
)) {
246 DEBUG(1, ("NT_TRANSACT_GET_USER_QUOTA failed: %s\n",
251 if (rdata_count
== 0) {
256 if ((mem_ctx
=talloc_init("SMB_USER_QUOTA_LIST"))==NULL
) {
257 DEBUG(0,("talloc_init() failed\n"));
258 return NT_STATUS_NO_MEMORY
;
262 for (curdata
=rdata
,curdata_count
=rdata_count
;
263 ((curdata
)&&(curdata_count
>=8)&&(offset
>0));
264 curdata
+=offset
,curdata_count
-= offset
) {
266 if (!parse_user_quota_record((uint8_t *)curdata
, curdata_count
,
268 DEBUG(1,("Failed to parse the quota record\n"));
272 if ((tmp_list_ent
=TALLOC_ZERO_P(mem_ctx
,SMB_NTQUOTA_LIST
))==NULL
) {
273 DEBUG(0,("TALLOC_ZERO() failed\n"));
274 talloc_destroy(mem_ctx
);
275 return NT_STATUS_NO_MEMORY
;
278 if ((tmp_list_ent
->quotas
=TALLOC_ZERO_P(mem_ctx
,SMB_NTQUOTA_STRUCT
))==NULL
) {
279 DEBUG(0,("TALLOC_ZERO() failed\n"));
280 talloc_destroy(mem_ctx
);
281 return NT_STATUS_NO_MEMORY
;
284 memcpy(tmp_list_ent
->quotas
,&qt
,sizeof(qt
));
285 tmp_list_ent
->mem_ctx
= mem_ctx
;
287 DLIST_ADD((*pqt_list
),tmp_list_ent
);
290 SSVAL(params
, 2,TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
);
296 status
= cli_trans(talloc_tos(), cli
, SMBnttrans
,
297 NULL
, -1, /* name, fid */
298 NT_TRANSACT_GET_USER_QUOTA
, 0,
299 setup
, 1, 0, /* setup */
300 params
, 16, 4, /* params */
301 NULL
, 0, 2048, /* data */
302 NULL
, /* recv_flags2 */
303 NULL
, 0, NULL
, /* rsetup */
304 &rparam
, 0, &rparam_count
,
305 &rdata
, 0, &rdata_count
);
307 if (!NT_STATUS_IS_OK(status
)) {
308 DEBUG(1, ("NT_TRANSACT_GET_USER_QUOTA failed: %s\n",
313 if (rdata_count
== 0) {
318 for (curdata
=rdata
,curdata_count
=rdata_count
;
319 ((curdata
)&&(curdata_count
>=8)&&(offset
>0));
320 curdata
+=offset
,curdata_count
-= offset
) {
322 if (!parse_user_quota_record((uint8_t *)curdata
,
323 curdata_count
, &offset
,
325 DEBUG(1,("Failed to parse the quota record\n"));
329 if ((tmp_list_ent
=TALLOC_ZERO_P(mem_ctx
,SMB_NTQUOTA_LIST
))==NULL
) {
330 DEBUG(0,("TALLOC_ZERO() failed\n"));
331 talloc_destroy(mem_ctx
);
335 if ((tmp_list_ent
->quotas
=TALLOC_ZERO_P(mem_ctx
,SMB_NTQUOTA_STRUCT
))==NULL
) {
336 DEBUG(0,("TALLOC_ZERO() failed\n"));
337 talloc_destroy(mem_ctx
);
341 memcpy(tmp_list_ent
->quotas
,&qt
,sizeof(qt
));
342 tmp_list_ent
->mem_ctx
= mem_ctx
;
344 DLIST_ADD((*pqt_list
),tmp_list_ent
);
355 NTSTATUS
cli_get_fs_quota_info(struct cli_state
*cli
, int quota_fnum
,
356 SMB_NTQUOTA_STRUCT
*pqt
)
361 uint32_t rdata_count
=0;
362 SMB_NTQUOTA_STRUCT qt
;
368 smb_panic("cli_get_fs_quota_info() called with NULL Pointer!");
371 SSVAL(setup
+ 0, 0, TRANSACT2_QFSINFO
);
373 SSVAL(param
,0,SMB_FS_QUOTA_INFORMATION
);
375 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
376 NULL
, -1, /* name, fid */
377 0, 0, /* function, flags */
378 setup
, 1, 0, /* setup */
379 param
, 2, 0, /* param */
380 NULL
, 0, 560, /* data */
381 NULL
, /* recv_flags2 */
382 NULL
, 0, NULL
, /* rsetup */
383 NULL
, 0, NULL
, /* rparam */
384 &rdata
, 48, &rdata_count
);
386 if (!NT_STATUS_IS_OK(status
)) {
387 DEBUG(1, ("SMB_FS_QUOTA_INFORMATION failed: %s\n",
392 /* unknown_1 24 NULL bytes in pdata*/
394 /* the soft quotas 8 bytes (uint64_t)*/
395 qt
.softlim
= BVAL(rdata
,24);
397 /* the hard quotas 8 bytes (uint64_t)*/
398 qt
.hardlim
= BVAL(rdata
,32);
400 /* quota_flags 2 bytes **/
401 qt
.qflags
= SVAL(rdata
,40);
403 qt
.qtype
= SMB_USER_FS_QUOTA_TYPE
;
411 NTSTATUS
cli_set_fs_quota_info(struct cli_state
*cli
, int quota_fnum
,
412 SMB_NTQUOTA_STRUCT
*pqt
)
417 SMB_NTQUOTA_STRUCT qt
;
420 memset(data
,'\0',48);
423 smb_panic("cli_set_fs_quota_info() called with NULL Pointer!");
426 SSVAL(setup
+ 0, 0,TRANSACT2_SETFSINFO
);
428 SSVAL(param
,0,quota_fnum
);
429 SSVAL(param
,2,SMB_FS_QUOTA_INFORMATION
);
431 /* Unknown1 24 NULL bytes*/
433 /* Default Soft Quota 8 bytes */
434 SBIG_UINT(data
,24,pqt
->softlim
);
436 /* Default Hard Quota 8 bytes */
437 SBIG_UINT(data
,32,pqt
->hardlim
);
439 /* Quota flag 2 bytes */
440 SSVAL(data
,40,pqt
->qflags
);
442 /* Unknown3 6 NULL bytes */
444 status
= cli_trans(talloc_tos(), cli
, SMBtrans2
,
445 NULL
, -1, /* name, fid */
446 0, 0, /* function, flags */
447 setup
, 1, 0, /* setup */
448 param
, 8, 0, /* param */
449 data
, 48, 0, /* data */
450 NULL
, /* recv_flags2 */
451 NULL
, 0, NULL
, /* rsetup */
452 NULL
, 0, NULL
, /* rparam */
453 NULL
, 0, NULL
); /* rdata */
455 if (!NT_STATUS_IS_OK(status
)) {
456 DEBUG(1, ("SMB_FS_QUOTA_INFORMATION failed: %s\n",