Remove the code in memcache that does a TALLOC_FREE on stored pointers. That's a disaster waiting
to happen. If you're storing talloc'ed pointers, you can't know their lifecycle and they should
be deleted when their parent context is deleted, so freeing them at some arbitrary point later
will be a double-free.
Jeremy.
uid_to_sid(&u_sid, pw->pw_uid);
gid_to_sid(&g_sid, pw->pw_gid);
- token = create_local_nt_token(NULL, &u_sid, False,
+ token = create_local_nt_token(talloc_autofree_context(), &u_sid, False,
1, &global_sid_Builtin_Administrators);
token->privileges = se_disk_operators;
* seriously this will be secret.
*/
- pw = getpwnam_alloc(NULL, "root");
+ pw = getpwnam_alloc(talloc_autofree_context(), "root");
if (pw && pw->pw_passwd) {
size_t i;
unsigned char md4_tmp[16];
static void memcache_element_parse(struct memcache_element *e,
DATA_BLOB *key, DATA_BLOB *value);
-static bool memcache_is_talloc(enum memcache_number n)
-{
- bool result;
-
- switch (n) {
- case GETPWNAM_CACHE:
- case PDB_GETPWSID_CACHE:
- case SINGLETON_CACHE_TALLOC:
- result = true;
- break;
- default:
- result = false;
- break;
- }
-
- return result;
-}
-
static int memcache_destructor(struct memcache *cache) {
struct memcache_element *e, *next;
for (e = cache->mru; e != NULL; e = next) {
next = e->next;
- if (memcache_is_talloc((enum memcache_number)e->n)
- && (e->valuelength == sizeof(void *))) {
- DATA_BLOB key, value;
- void *ptr;
- memcache_element_parse(e, &key, &value);
- memcpy(&ptr, value.data, sizeof(ptr));
- TALLOC_FREE(ptr);
- }
SAFE_FREE(e);
}
return 0;
char *p;
uid_t u;
- pass = getpwnam_alloc(NULL, name);
+ pass = getpwnam_alloc(talloc_autofree_context(), name);
if (pass) {
u = pass->pw_uid;
TALLOC_FREE(pass);
static char *ret;
if (ret == NULL) {
/* This is cached forever so
- * use NULL talloc ctx. */
- ret = get_myname(NULL);
+ * use autofree talloc ctx. */
+ ret = get_myname(talloc_autofree_context());
}
return ret;
}
return NULL;
}
- cached = tcopy_passwd(NULL, temp);
+ cached = tcopy_passwd(talloc_autofree_context(), temp);
if (cached == NULL) {
/*
* Just don't add this into the cache, ignore the failure
Globals.bWinbindTrustedDomainsOnly = False;
Globals.bWinbindNestedGroups = True;
Globals.winbind_expand_groups = 1;
- Globals.szWinbindNssInfo = str_list_make(NULL, "template", NULL);
+ Globals.szWinbindNssInfo = str_list_make(talloc_autofree_context(), "template", NULL);
Globals.bWinbindRefreshTickets = False;
Globals.bWinbindOfflineLogon = False;
return (const char **)def;
if (data->list==NULL) {
- data->list = str_list_make(NULL, data->value, NULL);
+ data->list = str_list_make(talloc_autofree_context(), data->value, NULL);
}
return (const char **)data->list;
static bool handle_netbios_aliases(int snum, const char *pszParmValue, char **ptr)
{
TALLOC_FREE(Globals.szNetbiosAliases);
- Globals.szNetbiosAliases = str_list_make(NULL, pszParmValue, NULL);
+ Globals.szNetbiosAliases = str_list_make(talloc_autofree_context(), pszParmValue, NULL);
return set_netbios_aliases((const char **)Globals.szNetbiosAliases);
}
case P_LIST:
TALLOC_FREE(*((char ***)parm_ptr));
*(char ***)parm_ptr = str_list_make(
- NULL, pszParmValue, NULL);
+ talloc_autofree_context(), pszParmValue, NULL);
break;
case P_STRING:
DEBUGLEVEL = 1;
}
- if ( !(pwd = getpwnam_alloc( NULL, user_name)) ) {
+ if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), user_name)) ) {
return NT_STATUS_NO_SUCH_USER;
}
NTSTATUS result;
const char *guestname = lp_guestaccount();
- if ( !(pwd = getpwnam_alloc( NULL, guestname ) ) ) {
+ if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), guestname ) ) ) {
DEBUG(0,("guest_user_info: Unable to locate guest account [%s]!\n",
guestname));
return False;
{
/* allocate memory for the structure as its own talloc CTX */
- if ( !(*methods = TALLOC_ZERO_P(NULL, struct pdb_methods) ) ) {
+ if ( !(*methods = TALLOC_ZERO_P(talloc_autofree_context(), struct pdb_methods) ) ) {
return NT_STATUS_NO_MEMORY;
}
{
struct passwd *pwd;
- pwd = getpwnam_alloc(NULL, name);
+ pwd = getpwnam_alloc(talloc_autofree_context(), name);
if (pwd == NULL) {
return False;
}
{
static struct event_context *ctx;
- if (!ctx && !(ctx = event_context_init(NULL))) {
+ if (!ctx && !(ctx = event_context_init(talloc_autofree_context()))) {
smb_panic("Could not init smbd event context");
}
return ctx;
static struct messaging_context *ctx;
if (ctx == NULL) {
- ctx = messaging_init(NULL, server_id_self(),
+ ctx = messaging_init(talloc_autofree_context(), server_id_self(),
smbd_event_context());
}
if (ctx == NULL) {
static struct memcache *cache;
if (!cache
- && !(cache = memcache_init(NULL,
+ && !(cache = memcache_init(talloc_autofree_context(),
lp_max_stat_cache_size()*1024))) {
smb_panic("Could not init smbd memcache");
if (!pass) {
/* Don't need to free() this as its stored in a static */
- pass = getpwnam_alloc(NULL, lp_guestaccount());
+ pass = getpwnam_alloc(talloc_autofree_context(), lp_guestaccount());
if (!pass)
return(False);
}
d_printf("Checking Guest's group.\n");
- pwd = getpwnam_alloc(NULL, lp_guestaccount());
+ pwd = getpwnam_alloc(talloc_autofree_context(), lp_guestaccount());
if (!pwd) {
d_fprintf(stderr, "Failed to find just created Guest account!\n"
" Is nss properly configured?!\n");
get_global_sam_sid();
- if ( !(pwd = getpwnam_alloc( NULL, username )) ) {
+ if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), username )) ) {
DEBUG(0,("Cannot locate Unix account for %s\n", username));
return -1;
}
fstrcpy(machineaccount, machinename);
fstrcat(machineaccount, "$");
- if ( !(pwd = getpwnam_alloc( NULL, machineaccount )) ) {
+ if ( !(pwd = getpwnam_alloc(talloc_autofree_context(), machineaccount )) ) {
DEBUG(0,("Cannot locate Unix account for %s\n", machineaccount));
return -1;
}
load_interfaces();
}
- if (!user_name[0] && (pwd = getpwuid_alloc(NULL, geteuid()))) {
+ if (!user_name[0] && (pwd = getpwuid_alloc(talloc_autofree_context(), geteuid()))) {
fstrcpy(user_name, pwd->pw_name);
TALLOC_FREE(pwd);
}
}
if (!user_name[0]) {
- pwd = getpwuid_alloc(NULL, getuid());
+ pwd = getpwuid_alloc(talloc_autofree_context(), getuid());
if (pwd) {
fstrcpy(user_name,pwd->pw_name);
TALLOC_FREE(pwd);
exit(0);
}
- pwd = getpwnam_alloc(NULL, user);
+ pwd = getpwnam_alloc(talloc_autofree_context(), user);
if (!pwd) {
printf("%sCannot find user %s<br>%s\n", head, user, tail);
exit(0);
* Try and get the user from the UNIX password file.
*/
- pass = getpwnam_alloc(NULL, user);
+ pass = getpwnam_alloc(talloc_autofree_context(), user);
/*
* Validate the password they have given.