POLICY_HND pol_hnd;
void *data_ptr;
- void (*free_fn)(void *);
};
struct handle_list {
/* The following definitions come from rpc_server/srv_lsa_hnd.c */
bool init_pipe_handle_list(pipes_struct *p, const char *pipe_name);
-bool create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void (*free_fn)(void *), void *data_ptr);
+bool create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void *data_ptr);
bool find_policy_by_hnd(pipes_struct *p, POLICY_HND *hnd, void **data_p);
bool close_policy_hnd(pipes_struct *p, POLICY_HND *hnd);
void close_policy_by_pipe(pipes_struct *p);
return 0;
}
-static void free_eventlog_info( void *ptr )
-{
- TALLOC_FREE(ptr);
-}
-
/********************************************************************
********************************************************************/
/* create the policy handle */
- if ( !create_policy_hnd
- ( p, hnd, free_eventlog_info, ( void * ) elog ) ) {
- free_eventlog_info( elog );
+ if ( !create_policy_hnd( p, hnd, elog ) ) {
+ TALLOC_FREE(elog);
return NT_STATUS_NO_MEMORY;
}
/****************************************************************************
find first available policy slot. creates a policy handle for you.
+
+ If "data_ptr" is given, this must be a talloc'ed object, create_policy_hnd
+ talloc_moves this into the handle. If the policy_hnd is closed,
+ data_ptr is TALLOC_FREE()'ed
****************************************************************************/
-bool create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void (*free_fn)(void *), void *data_ptr)
+bool create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void *data_ptr)
{
static uint32 pol_hnd_low = 0;
static uint32 pol_hnd_high = 0;
return False;
}
- pol = SMB_MALLOC_P(struct policy);
+ pol = TALLOC_ZERO_P(NULL, struct policy);
if (!pol) {
DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
return False;
}
- ZERO_STRUCTP(pol);
-
- pol->data_ptr = data_ptr;
- pol->free_fn = free_fn;
+ if (data_ptr != NULL) {
+ pol->data_ptr = talloc_move(pol, &data_ptr);
+ }
pol_hnd_low++;
if (pol_hnd_low == 0)
DEBUG(3,("Closed policy\n"));
- if (pol->free_fn && pol->data_ptr)
- (*pol->free_fn)(pol->data_ptr);
-
p->pipe_handles->count--;
DLIST_REMOVE(p->pipe_handles->Policy, pol);
- ZERO_STRUCTP(pol);
-
- SAFE_FREE(pol);
+ TALLOC_FREE(pol);
return True;
}
}
-/*******************************************************************
- Function to free the per handle data.
- ********************************************************************/
-
-static void free_lsa_info(void *ptr)
-{
- TALLOC_FREE(ptr);
-}
-
/***************************************************************************
initialize a lsa_DomainInfo structure.
***************************************************************************/
acc_granted = LSA_POLICY_ALL_ACCESS;
/* associate the domain SID with the (unique) handle. */
- info = TALLOC_ZERO_P(NULL, struct lsa_info);
+ info = TALLOC_ZERO_P(p->mem_ctx, struct lsa_info);
if (info == NULL) {
return NT_STATUS_NO_MEMORY;
}
info->access = acc_granted;
/* set up the LSA QUERY INFO response */
- if (!create_policy_hnd(p, r->out.handle, free_lsa_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
}
/* associate the domain SID with the (unique) handle. */
- info = TALLOC_ZERO_P(NULL, struct lsa_info);
+ info = TALLOC_ZERO_P(p->mem_ctx, struct lsa_info);
if (info == NULL) {
return NT_STATUS_NO_MEMORY;
}
info->access = acc_granted;
/* set up the LSA QUERY INFO response */
- if (!create_policy_hnd(p, r->out.handle, free_lsa_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
/* associate the user/group SID with the (unique) handle. */
- info = TALLOC_ZERO_P(NULL, struct lsa_info);
+ info = TALLOC_ZERO_P(p->mem_ctx, struct lsa_info);
if (info == NULL) {
return NT_STATUS_NO_MEMORY;
}
info->access = r->in.access_mask;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.acct_handle, free_lsa_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.acct_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return privilege_create_account( &info->sid );
return NT_STATUS_ACCESS_DENIED;
#endif
/* associate the user/group SID with the (unique) handle. */
- info = TALLOC_ZERO_P(NULL, struct lsa_info);
+ info = TALLOC_ZERO_P(p->mem_ctx, struct lsa_info);
if (info == NULL) {
return NT_STATUS_NO_MEMORY;
}
info->access = r->in.access_mask;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.acct_handle, free_lsa_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.acct_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
static int samr_info_destructor(struct samr_info *info);
-static struct samr_info *get_samr_info_by_sid(DOM_SID *psid)
+static struct samr_info *get_samr_info_by_sid(TALLOC_CTX *mem_ctx,
+ DOM_SID *psid)
{
struct samr_info *info;
fstring sid_str;
fstrcpy(sid_str,"(NULL)");
}
- if ((info = TALLOC_ZERO_P(NULL, struct samr_info)) == NULL) {
+ if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL) {
return NULL;
}
talloc_set_destructor(info, samr_info_destructor);
return 0;
}
-/*******************************************************************
- Function to free the per handle data.
- ********************************************************************/
-
-static void free_samr_info(void *ptr)
-{
- TALLOC_FREE(ptr);
-}
-
/*******************************************************************
Idle event handler. Throw away the disp info cache.
********************************************************************/
}
/* associate the domain SID with the (unique) handle. */
- if ((info = get_samr_info_by_sid(r->in.sid))==NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, r->in.sid))==NULL)
return NT_STATUS_NO_MEMORY;
info->acc_granted = acc_granted;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.domain_handle, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.domain_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
TALLOC_FREE(sampass);
/* associate the user's SID and access bits with the new handle. */
- if ((info = get_samr_info_by_sid(&sid)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
return NT_STATUS_NO_MEMORY;
info->acc_granted = acc_granted;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, user_pol, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
}
/* associate the user's SID with the new handle. */
- if ((info = get_samr_info_by_sid(&sid)) == NULL) {
+ if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL) {
return NT_STATUS_NO_MEMORY;
}
info->acc_granted = acc_granted;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info)) {
+ if (!create_policy_hnd(p, user_pol, info)) {
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
/* set up the SAMR connect_anon response */
/* associate the user's SID with the new handle. */
- if ((info = get_samr_info_by_sid(NULL)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
return NT_STATUS_NO_MEMORY;
/* don't give away the farm but this is probably ok. The SAMR_ACCESS_ENUM_DOMAINS
info->acc_granted = des_access & (SAMR_ACCESS_ENUM_DOMAINS|SAMR_ACCESS_OPEN_DOMAIN);
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.connect_handle, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.connect_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
return nt_status;
/* associate the user's SID and access granted with the new handle. */
- if ((info = get_samr_info_by_sid(NULL)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, NULL)) == NULL)
return NT_STATUS_NO_MEMORY;
info->acc_granted = acc_granted;
info->status = r->in.access_mask; /* this looks so wrong... - gd */
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.connect_handle, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.connect_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
DEBUG(5,("%s: %d\n", fn, __LINE__));
}
/* associate the alias SID with the new handle. */
- if ((info = get_samr_info_by_sid(&sid)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, &sid)) == NULL)
return NT_STATUS_NO_MEMORY;
info->acc_granted = acc_granted;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, alias_pol, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, alias_pol, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
- if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
return NT_STATUS_NO_MEMORY;
/* they created it; let the user do what he wants with it */
info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.group_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
force_flush_samr_cache(disp_info);
return NT_STATUS_ACCESS_DENIED;
}
- if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
return NT_STATUS_NO_MEMORY;
/* they created it; let the user do what he wants with it */
info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.alias_handle, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.alias_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
force_flush_samr_cache(disp_info);
sid_append_rid(&info_sid, r->in.rid);
sid_to_fstring(sid_string, &info_sid);
- if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
+ if ((info = get_samr_info_by_sid(p->mem_ctx, &info_sid)) == NULL)
return NT_STATUS_NO_MEMORY;
info->acc_granted = acc_granted;
return NT_STATUS_NO_SUCH_GROUP;
/* get a (unique) handle. open a policy on it. */
- if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
+ if (!create_policy_hnd(p, r->out.group_handle, info))
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
return NT_STATUS_OK;
return 0;
}
-static void free_printer_entry(void *Printer)
-{
- TALLOC_FREE(Printer);
-}
-
/****************************************************************************
Functions to duplicate a SPOOL_NOTIFY_OPTION struct stored in Printer_entry.
****************************************************************************/
}
talloc_set_destructor(new_printer, printer_entry_destructor);
- if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) {
- SAFE_FREE(new_printer);
+ if (!create_policy_hnd(p, hnd, new_printer)) {
+ TALLOC_FREE(new_printer);
return False;
}
return sd;
}
-/******************************************************************
- free() function for REGISTRY_KEY
- *****************************************************************/
-
-static void free_service_handle_info(void *ptr)
-{
- TALLOC_FREE( ptr );
-}
-
/******************************************************************
Find a registry key handle and return a SERVICE_INFO
*****************************************************************/
/* store the SERVICE_INFO and create an open handle */
- if ( !create_policy_hnd( p, handle, free_service_handle_info, info ) ) {
+ if ( !create_policy_hnd( p, handle, info ) ) {
result = WERR_ACCESS_DENIED;
goto done;
}
done:
if ( !W_ERROR_IS_OK(result) )
- free_service_handle_info( info );
+ TALLOC_FREE(info);
return result;
}
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
-/******************************************************************
- free() function for struct registry_key
- *****************************************************************/
-
-static void free_regkey(void *ptr)
-{
- struct registry_key *key = (struct registry_key *)ptr;
- TALLOC_FREE(key);
-}
-
/******************************************************************
Find a registry key handle and return a struct registry_key *
*****************************************************************/
struct registry_key *key;
if (parent == NULL) {
- result = reg_openhive(NULL, subkeyname, access_desired,
+ result = reg_openhive(p->mem_ctx, subkeyname, access_desired,
p->server_info->ptok, &key);
}
else {
- result = reg_openkey(NULL, parent, subkeyname, access_desired,
- &key);
+ result = reg_openkey(p->mem_ctx, parent, subkeyname,
+ access_desired, &key);
}
if ( !W_ERROR_IS_OK(result) ) {
return result;
}
- if ( !create_policy_hnd( p, hnd, free_regkey, key ) ) {
+ if ( !create_policy_hnd( p, hnd, key ) ) {
return WERR_BADFILE;
}
return result;
}
- if (!create_policy_hnd(p, r->out.new_handle, free_regkey, new_key)) {
+ if (!create_policy_hnd(p, r->out.new_handle, new_key)) {
TALLOC_FREE(new_key);
return WERR_BADFILE;
}