| 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 |  | 
|---|
| 22 | /**************************************************************************** | 
|---|
| 23 | query the security descriptor for a open file | 
|---|
| 24 | ****************************************************************************/ | 
|---|
| 25 | SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum, | 
|---|
| 26 | TALLOC_CTX *mem_ctx) | 
|---|
| 27 | { | 
|---|
| 28 | char param[8]; | 
|---|
| 29 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 30 | unsigned int rparam_count=0, rdata_count=0; | 
|---|
| 31 | SEC_DESC *psd = NULL; | 
|---|
| 32 | NTSTATUS status; | 
|---|
| 33 |  | 
|---|
| 34 | SIVAL(param, 0, fnum); | 
|---|
| 35 | SIVAL(param, 4, 0x7); | 
|---|
| 36 |  | 
|---|
| 37 | if (!cli_send_nt_trans(cli, | 
|---|
| 38 | NT_TRANSACT_QUERY_SECURITY_DESC, | 
|---|
| 39 | 0, | 
|---|
| 40 | NULL, 0, 0, | 
|---|
| 41 | param, 8, 4, | 
|---|
| 42 | NULL, 0, 0x10000)) { | 
|---|
| 43 | DEBUG(1,("Failed to send NT_TRANSACT_QUERY_SECURITY_DESC\n")); | 
|---|
| 44 | goto cleanup; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 | if (!cli_receive_nt_trans(cli, | 
|---|
| 49 | &rparam, &rparam_count, | 
|---|
| 50 | &rdata, &rdata_count)) { | 
|---|
| 51 | DEBUG(1,("Failed to recv NT_TRANSACT_QUERY_SECURITY_DESC\n")); | 
|---|
| 52 | goto cleanup; | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | if (cli_is_error(cli)) | 
|---|
| 56 | goto cleanup; | 
|---|
| 57 |  | 
|---|
| 58 | status = unmarshall_sec_desc(mem_ctx, (uint8 *)rdata, rdata_count, | 
|---|
| 59 | &psd); | 
|---|
| 60 |  | 
|---|
| 61 | if (!NT_STATUS_IS_OK(status)) { | 
|---|
| 62 | DEBUG(10, ("unmarshall_sec_desc failed: %s\n", | 
|---|
| 63 | nt_errstr(status))); | 
|---|
| 64 | goto cleanup; | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | cleanup: | 
|---|
| 68 |  | 
|---|
| 69 | SAFE_FREE(rparam); | 
|---|
| 70 | SAFE_FREE(rdata); | 
|---|
| 71 |  | 
|---|
| 72 | return psd; | 
|---|
| 73 | } | 
|---|
| 74 |  | 
|---|
| 75 | /**************************************************************************** | 
|---|
| 76 | set the security descriptor for a open file | 
|---|
| 77 | ****************************************************************************/ | 
|---|
| 78 | bool cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd) | 
|---|
| 79 | { | 
|---|
| 80 | char param[8]; | 
|---|
| 81 | char *rparam=NULL, *rdata=NULL; | 
|---|
| 82 | unsigned int rparam_count=0, rdata_count=0; | 
|---|
| 83 | uint32 sec_info = 0; | 
|---|
| 84 | TALLOC_CTX *frame = talloc_stackframe(); | 
|---|
| 85 | bool ret = False; | 
|---|
| 86 | uint8 *data; | 
|---|
| 87 | size_t len; | 
|---|
| 88 | NTSTATUS status; | 
|---|
| 89 |  | 
|---|
| 90 | status = marshall_sec_desc(talloc_tos(), sd, &data, &len); | 
|---|
| 91 | if (!NT_STATUS_IS_OK(status)) { | 
|---|
| 92 | DEBUG(10, ("marshall_sec_desc failed: %s\n", | 
|---|
| 93 | nt_errstr(status))); | 
|---|
| 94 | goto cleanup; | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | SIVAL(param, 0, fnum); | 
|---|
| 98 |  | 
|---|
| 99 | if (sd->dacl) | 
|---|
| 100 | sec_info |= DACL_SECURITY_INFORMATION; | 
|---|
| 101 | if (sd->owner_sid) | 
|---|
| 102 | sec_info |= OWNER_SECURITY_INFORMATION; | 
|---|
| 103 | if (sd->group_sid) | 
|---|
| 104 | sec_info |= GROUP_SECURITY_INFORMATION; | 
|---|
| 105 | SSVAL(param, 4, sec_info); | 
|---|
| 106 |  | 
|---|
| 107 | if (!cli_send_nt_trans(cli, | 
|---|
| 108 | NT_TRANSACT_SET_SECURITY_DESC, | 
|---|
| 109 | 0, | 
|---|
| 110 | NULL, 0, 0, | 
|---|
| 111 | param, 8, 0, | 
|---|
| 112 | (char *)data, len, 0)) { | 
|---|
| 113 | DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n")); | 
|---|
| 114 | goto cleanup; | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 |  | 
|---|
| 118 | if (!cli_receive_nt_trans(cli, | 
|---|
| 119 | &rparam, &rparam_count, | 
|---|
| 120 | &rdata, &rdata_count)) { | 
|---|
| 121 | DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n")); | 
|---|
| 122 | goto cleanup; | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | ret = True; | 
|---|
| 126 |  | 
|---|
| 127 | cleanup: | 
|---|
| 128 |  | 
|---|
| 129 | SAFE_FREE(rparam); | 
|---|
| 130 | SAFE_FREE(rdata); | 
|---|
| 131 |  | 
|---|
| 132 | TALLOC_FREE(frame); | 
|---|
| 133 |  | 
|---|
| 134 | return ret; | 
|---|
| 135 | } | 
|---|