[745] | 1 | /*
|
---|
| 2 | Unix SMB/CIFS implementation.
|
---|
| 3 | client security descriptor functions
|
---|
| 4 | Copyright (C) Andrew Tridgell 2000
|
---|
| 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 3 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, see <http://www.gnu.org/licenses/>.
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | #include "includes.h"
|
---|
| 21 | #include "libsmb/libsmb.h"
|
---|
| 22 |
|
---|
| 23 | /****************************************************************************
|
---|
| 24 | query the security descriptor for a open file
|
---|
| 25 | ****************************************************************************/
|
---|
| 26 | struct security_descriptor *cli_query_secdesc(struct cli_state *cli, uint16_t fnum,
|
---|
| 27 | TALLOC_CTX *mem_ctx)
|
---|
| 28 | {
|
---|
| 29 | uint8_t param[8];
|
---|
| 30 | uint8_t *rdata=NULL;
|
---|
| 31 | uint32_t rdata_count=0;
|
---|
| 32 | struct security_descriptor *psd = NULL;
|
---|
| 33 | NTSTATUS status;
|
---|
| 34 |
|
---|
| 35 | SIVAL(param, 0, fnum);
|
---|
| 36 | SIVAL(param, 4, 0x7);
|
---|
| 37 |
|
---|
| 38 | status = cli_trans(talloc_tos(), cli, SMBnttrans,
|
---|
| 39 | NULL, -1, /* name, fid */
|
---|
| 40 | NT_TRANSACT_QUERY_SECURITY_DESC, 0, /* function, flags */
|
---|
| 41 | NULL, 0, 0, /* setup, length, max */
|
---|
| 42 | param, 8, 4, /* param, length, max */
|
---|
| 43 | NULL, 0, 0x10000, /* data, length, max */
|
---|
| 44 | NULL, /* recv_flags2 */
|
---|
| 45 | NULL, 0, NULL, /* rsetup, length */
|
---|
| 46 | NULL, 0, NULL,
|
---|
| 47 | &rdata, 0, &rdata_count);
|
---|
| 48 |
|
---|
| 49 | if (!NT_STATUS_IS_OK(status)) {
|
---|
| 50 | DEBUG(1, ("NT_TRANSACT_QUERY_SECURITY_DESC failed: %s\n",
|
---|
| 51 | nt_errstr(status)));
|
---|
| 52 | goto cleanup;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | status = unmarshall_sec_desc(mem_ctx, (uint8 *)rdata, rdata_count,
|
---|
| 56 | &psd);
|
---|
| 57 |
|
---|
| 58 | if (!NT_STATUS_IS_OK(status)) {
|
---|
| 59 | DEBUG(10, ("unmarshall_sec_desc failed: %s\n",
|
---|
| 60 | nt_errstr(status)));
|
---|
| 61 | goto cleanup;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | cleanup:
|
---|
| 65 |
|
---|
| 66 | TALLOC_FREE(rdata);
|
---|
| 67 |
|
---|
| 68 | return psd;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /****************************************************************************
|
---|
| 72 | set the security descriptor for a open file
|
---|
| 73 | ****************************************************************************/
|
---|
| 74 | NTSTATUS cli_set_secdesc(struct cli_state *cli, uint16_t fnum,
|
---|
| 75 | struct security_descriptor *sd)
|
---|
| 76 | {
|
---|
| 77 | uint8_t param[8];
|
---|
| 78 | uint32 sec_info = 0;
|
---|
| 79 | uint8 *data;
|
---|
| 80 | size_t len;
|
---|
| 81 | NTSTATUS status;
|
---|
| 82 |
|
---|
| 83 | status = marshall_sec_desc(talloc_tos(), sd, &data, &len);
|
---|
| 84 | if (!NT_STATUS_IS_OK(status)) {
|
---|
| 85 | DEBUG(10, ("marshall_sec_desc failed: %s\n",
|
---|
| 86 | nt_errstr(status)));
|
---|
| 87 | return status;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | SIVAL(param, 0, fnum);
|
---|
| 91 |
|
---|
| 92 | if (sd->dacl)
|
---|
| 93 | sec_info |= SECINFO_DACL;
|
---|
| 94 | if (sd->owner_sid)
|
---|
| 95 | sec_info |= SECINFO_OWNER;
|
---|
| 96 | if (sd->group_sid)
|
---|
| 97 | sec_info |= SECINFO_GROUP;
|
---|
| 98 | SSVAL(param, 4, sec_info);
|
---|
| 99 |
|
---|
| 100 | status = cli_trans(talloc_tos(), cli, SMBnttrans,
|
---|
| 101 | NULL, -1, /* name, fid */
|
---|
| 102 | NT_TRANSACT_SET_SECURITY_DESC, 0,
|
---|
| 103 | NULL, 0, 0, /* setup */
|
---|
| 104 | param, 8, 0, /* param */
|
---|
| 105 | data, len, 0, /* data */
|
---|
| 106 | NULL, /* recv_flags2 */
|
---|
| 107 | NULL, 0, NULL, /* rsetup */
|
---|
| 108 | NULL, 0, NULL, /* rparam */
|
---|
| 109 | NULL, 0, NULL); /* rdata */
|
---|
| 110 | TALLOC_FREE(data);
|
---|
| 111 | if (!NT_STATUS_IS_OK(status)) {
|
---|
| 112 | DEBUG(1, ("Failed to send NT_TRANSACT_SET_SECURITY_DESC: %s\n",
|
---|
| 113 | nt_errstr(status)));
|
---|
| 114 | }
|
---|
| 115 | return status;
|
---|
| 116 | }
|
---|