1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00
samba-mirror/source3/rpc_parse/parse_ntsvcs.c
Volker Lendecke 929e1d9920 r24809: Consolidate the use of temporary talloc contexts.
This adds the two functions talloc_stackframe() and talloc_tos().

 * When a new talloc stackframe is allocated with talloc_stackframe(), then
 * the TALLOC_CTX returned with talloc_tos() is reset to that new
 * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse
 * happens: The previous talloc_tos() is restored.
 *
 * This API is designed to be robust in the sense that if someone forgets to
 * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and
 * resets the talloc_tos().

The original motivation for this patch was to get rid of the
sid_string_static & friends buffers. Explicitly passing talloc context
everywhere clutters code too much for my taste, so an implicit
talloc_tos() is introduced here. Many of these static buffers are
replaced by a single static pointer.

The intended use would thus be that low-level functions can rather
freely push stuff to talloc_tos, the upper layers clean up by freeing
the stackframe. The more of these stackframes are used and correctly
freed the more exact the memory cleanup happens.

This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and
lp_talloc_ctx (did I forget any?)

So, never do a

tmp_ctx = talloc_init("foo");

anymore, instead, use

tmp_ctx = talloc_stackframe()

:-)

Volker
(This used to be commit 6585ea2cb7)
2007-10-10 12:30:24 -05:00

427 lines
11 KiB
C

/*
* Unix SMB/CIFS implementation.
* RPC Pipe client / server routines
* Copyright (C) Gerald (Jerry) Carter 2005.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_PARSE
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_get_version(const char *desc, NTSVCS_Q_GET_VERSION *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_get_version");
depth++;
/* there is nothing to parse in this PDU */
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_get_version(const char *desc, NTSVCS_R_GET_VERSION *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_get_version");
depth++;
if(!prs_align(ps))
return False;
if(!prs_uint32("version", ps, depth, &r_u->version))
return False;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_get_device_list_size(const char *desc, NTSVCS_Q_GET_DEVICE_LIST_SIZE *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_get_device_list_size");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_pointer("devicename", ps, depth, (void*)&q_u->devicename, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2) )
return False;
if ( !prs_align(ps) )
return False;
if ( !prs_uint32("flags", ps, depth, &q_u->flags) )
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_get_device_list_size(const char *desc, NTSVCS_R_GET_DEVICE_LIST_SIZE *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_get_device_list_size");
depth++;
if(!prs_align(ps))
return False;
if(!prs_uint32("size", ps, depth, &r_u->size))
return False;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_get_device_list(const char *desc, NTSVCS_Q_GET_DEVICE_LIST *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_get_device_list");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_pointer("devicename", ps, depth, (void*)&q_u->devicename, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2) )
return False;
if( !prs_align(ps) )
return False;
if ( !prs_uint32("buffer_size", ps, depth, &q_u->buffer_size) )
return False;
if ( !prs_uint32("flags", ps, depth, &q_u->flags) )
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_get_device_list(const char *desc, NTSVCS_R_GET_DEVICE_LIST *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_get_device_list_size");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_io_unistr2("devicepath", ps, depth, &r_u->devicepath) )
return False;
if(!prs_align(ps))
return False;
if(!prs_uint32("needed", ps, depth, &r_u->needed))
return False;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_validate_device_instance(const char *desc, NTSVCS_Q_VALIDATE_DEVICE_INSTANCE *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_validate_device_instance");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_io_unistr2("devicepath", ps, depth, &q_u->devicepath) )
return False;
if( !prs_align(ps) )
return False;
if ( !prs_uint32("flags", ps, depth, &q_u->flags) )
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_validate_device_instance(const char *desc, NTSVCS_R_VALIDATE_DEVICE_INSTANCE *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_validate_device_instance");
depth++;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_get_device_reg_property(const char *desc, NTSVCS_Q_GET_DEVICE_REG_PROPERTY *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_get_device_reg_property");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_io_unistr2("devicepath", ps, depth, &q_u->devicepath) )
return False;
if( !prs_align(ps) )
return False;
if ( !prs_uint32("property", ps, depth, &q_u->property) )
return False;
if ( !prs_uint32("unknown2", ps, depth, &q_u->unknown2) )
return False;
if ( !prs_uint32("buffer_size1", ps, depth, &q_u->buffer_size1) )
return False;
if ( !prs_uint32("buffer_size2", ps, depth, &q_u->buffer_size2) )
return False;
if ( !prs_uint32("unknown5", ps, depth, &q_u->unknown5) )
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_get_device_reg_property(const char *desc, NTSVCS_R_GET_DEVICE_REG_PROPERTY *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_get_device_reg_property");
depth++;
if ( !prs_align(ps) )
return False;
if ( !prs_uint32("unknown1", ps, depth, &r_u->unknown1) )
return False;
if ( !smb_io_regval_buffer("value", ps, depth, &r_u->value) )
return False;
if ( !prs_align(ps) )
return False;
if ( !prs_uint32("size", ps, depth, &r_u->size) )
return False;
if ( !prs_uint32("needed", ps, depth, &r_u->needed) )
return False;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_get_hw_profile_info(const char *desc, NTSVCS_Q_GET_HW_PROFILE_INFO *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_get_hw_profile_info");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_uint32("index", ps, depth, &q_u->index) )
return False;
q_u->buffer_size = 0x000000a8;
if ( UNMARSHALLING(ps) ) {
q_u->buffer = TALLOC_ARRAY(talloc_tos(), uint8, q_u->buffer_size );
if (!q_u->buffer) {
return False;
}
}
if ( !prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size) )
return False;
if ( !prs_uint32("buffer_size", ps, depth, &q_u->buffer_size) )
return False;
if ( !prs_uint32("unknown1", ps, depth, &q_u->unknown1) )
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_get_hw_profile_info(const char *desc, NTSVCS_R_GET_HW_PROFILE_INFO *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_get_device_reg_property");
depth++;
if ( !prs_align(ps) )
return False;
if ( UNMARSHALLING(ps) ) {
if (r_u->buffer_size) {
r_u->buffer = TALLOC_ARRAY(talloc_tos(), uint8, r_u->buffer_size );
if (!r_u->buffer) {
return False;
}
} else {
r_u->buffer = NULL;
}
}
if ( !prs_uint8s(True, "buffer", ps, depth, r_u->buffer, r_u->buffer_size) )
return False;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_q_hw_profile_flags(const char *desc, NTSVCS_Q_HW_PROFILE_FLAGS *q_u, prs_struct *ps, int depth)
{
if (q_u == NULL)
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_q_hw_profile_flags");
depth++;
if(!prs_align(ps))
return False;
if ( !prs_uint32("unknown1", ps, depth, &q_u->unknown1) )
return False;
if ( !prs_io_unistr2("devicepath", ps, depth, &q_u->devicepath) )
return False;
if( !prs_align(ps) )
return False;
if ( !prs_uint32("unknown2", ps, depth, &q_u->unknown2) )
return False;
if ( !prs_uint32("unknown3", ps, depth, &q_u->unknown3) )
return False;
if ( !prs_uint32("unknown4", ps, depth, &q_u->unknown4) )
return False;
if ( !prs_uint32("unknown5", ps, depth, &q_u->unknown5) )
return False;
if ( !prs_uint32("unknown6", ps, depth, &q_u->unknown6) )
return False;
if ( !prs_uint32("unknown7", ps, depth, &q_u->unknown7) )
return False;
if ( !prs_uint32("unknown1", ps, depth, &q_u->unknown1) )
return False;
return True;
}
/*******************************************************************
********************************************************************/
BOOL ntsvcs_io_r_hw_profile_flags(const char *desc, NTSVCS_R_HW_PROFILE_FLAGS *r_u, prs_struct *ps, int depth)
{
if ( !r_u )
return False;
prs_debug(ps, depth, desc, "ntsvcs_io_r_hw_profile_flags");
depth++;
if ( !prs_align(ps) )
return False;
if ( !prs_uint32("unknown1", ps, depth, &r_u->unknown1) )
return False;
if ( !prs_uint32("unknown2", ps, depth, &r_u->unknown2) )
return False;
if ( !prs_uint32("unknown3", ps, depth, &r_u->unknown3) )
return False;
if(!prs_werror("status", ps, depth, &r_u->status))
return False;
return True;
}