libsmb/clisecdesc.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    client security descriptor functions
00004    Copyright (C) Andrew Tridgell 2000
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "includes.h"
00022 
00023 /****************************************************************************
00024   query the security descriptor for a open file
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   set the security descriptor for a open file
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 }

Sambaに対してSat Aug 29 21:23:05 2009に生成されました。  doxygen 1.4.7