00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "includes.h"
00022
00023
00024
00025
00026 SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum,
00027 TALLOC_CTX *mem_ctx)
00028 {
00029 char param[8];
00030 char *rparam=NULL, *rdata=NULL;
00031 unsigned int rparam_count=0, rdata_count=0;
00032 prs_struct pd;
00033 BOOL pd_initialized = False;
00034 SEC_DESC *psd = NULL;
00035
00036 SIVAL(param, 0, fnum);
00037 SIVAL(param, 4, 0x7);
00038
00039 if (!cli_send_nt_trans(cli,
00040 NT_TRANSACT_QUERY_SECURITY_DESC,
00041 0,
00042 NULL, 0, 0,
00043 param, 8, 4,
00044 NULL, 0, 0x10000)) {
00045 DEBUG(1,("Failed to send NT_TRANSACT_QUERY_SECURITY_DESC\n"));
00046 goto cleanup;
00047 }
00048
00049
00050 if (!cli_receive_nt_trans(cli,
00051 &rparam, &rparam_count,
00052 &rdata, &rdata_count)) {
00053 DEBUG(1,("Failed to recv NT_TRANSACT_QUERY_SECURITY_DESC\n"));
00054 goto cleanup;
00055 }
00056
00057 if (cli_is_error(cli))
00058 goto cleanup;
00059
00060 if (!prs_init(&pd, rdata_count, mem_ctx, UNMARSHALL)) {
00061 goto cleanup;
00062 }
00063 pd_initialized = True;
00064 prs_copy_data_in(&pd, rdata, rdata_count);
00065 prs_set_offset(&pd,0);
00066
00067 if (!sec_io_desc("sd data", &psd, &pd, 1)) {
00068 DEBUG(1,("Failed to parse secdesc\n"));
00069 goto cleanup;
00070 }
00071
00072 cleanup:
00073
00074 SAFE_FREE(rparam);
00075 SAFE_FREE(rdata);
00076
00077 if (pd_initialized)
00078 prs_mem_free(&pd);
00079 return psd;
00080 }
00081
00082
00083
00084
00085 BOOL cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd)
00086 {
00087 char param[8];
00088 char *rparam=NULL, *rdata=NULL;
00089 unsigned int rparam_count=0, rdata_count=0;
00090 uint32 sec_info = 0;
00091 TALLOC_CTX *mem_ctx;
00092 prs_struct pd;
00093 BOOL ret = False;
00094
00095 if ((mem_ctx = talloc_init("cli_set_secdesc")) == NULL) {
00096 DEBUG(0,("talloc_init failed.\n"));
00097 goto cleanup;
00098 }
00099
00100 prs_init(&pd, 0, mem_ctx, MARSHALL);
00101 prs_give_memory(&pd, NULL, 0, True);
00102
00103 if (!sec_io_desc("sd data", &sd, &pd, 1)) {
00104 DEBUG(1,("Failed to marshall secdesc\n"));
00105 goto cleanup;
00106 }
00107
00108 SIVAL(param, 0, fnum);
00109
00110 if (sd->off_dacl)
00111 sec_info |= DACL_SECURITY_INFORMATION;
00112 if (sd->off_owner_sid)
00113 sec_info |= OWNER_SECURITY_INFORMATION;
00114 if (sd->off_grp_sid)
00115 sec_info |= GROUP_SECURITY_INFORMATION;
00116 SSVAL(param, 4, sec_info);
00117
00118 if (!cli_send_nt_trans(cli,
00119 NT_TRANSACT_SET_SECURITY_DESC,
00120 0,
00121 NULL, 0, 0,
00122 param, 8, 0,
00123 prs_data_p(&pd), prs_offset(&pd), 0)) {
00124 DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n"));
00125 goto cleanup;
00126 }
00127
00128
00129 if (!cli_receive_nt_trans(cli,
00130 &rparam, &rparam_count,
00131 &rdata, &rdata_count)) {
00132 DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n"));
00133 goto cleanup;
00134 }
00135
00136 ret = True;
00137
00138 cleanup:
00139
00140 SAFE_FREE(rparam);
00141 SAFE_FREE(rdata);
00142
00143 talloc_destroy(mem_ctx);
00144
00145 prs_mem_free(&pd);
00146 return ret;
00147 }