diff options
author | Jeremy Allison <jra@samba.org> | 2004-12-07 18:25:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 10:53:32 -0500 |
commit | acf9d61421faa6c0055d57fdee7db300dc5431aa (patch) | |
tree | 5482afecfe9b4a68b9a1f18d541a3109f8143ab7 /source3/passdb | |
parent | 3bd3be97dc8a581c0502410453091c195e322766 (diff) | |
download | samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.gz samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.tar.bz2 samba-acf9d61421faa6c0055d57fdee7db300dc5431aa.zip |
r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
functions so we can funnel through some well known functions. Should help greatly with
malloc checking.
HEAD patch to follow.
Jeremy.
(This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a)
Diffstat (limited to 'source3/passdb')
-rw-r--r-- | source3/passdb/login_cache.c | 10 | ||||
-rw-r--r-- | source3/passdb/lookup_sid.c | 4 | ||||
-rw-r--r-- | source3/passdb/machine_sid.c | 2 | ||||
-rw-r--r-- | source3/passdb/passdb.c | 6 | ||||
-rw-r--r-- | source3/passdb/pdb_get_set.c | 2 | ||||
-rw-r--r-- | source3/passdb/pdb_interface.c | 6 | ||||
-rw-r--r-- | source3/passdb/pdb_ldap.c | 10 | ||||
-rw-r--r-- | source3/passdb/pdb_smbpasswd.c | 4 | ||||
-rw-r--r-- | source3/passdb/pdb_sql.c | 4 | ||||
-rw-r--r-- | source3/passdb/pdb_tdb.c | 4 | ||||
-rw-r--r-- | source3/passdb/privileges.c | 10 | ||||
-rw-r--r-- | source3/passdb/secrets.c | 10 | ||||
-rw-r--r-- | source3/passdb/util_sam_sid.c | 8 |
13 files changed, 40 insertions, 40 deletions
diff --git a/source3/passdb/login_cache.c b/source3/passdb/login_cache.c index 0d782912b1..d82cfcc560 100644 --- a/source3/passdb/login_cache.c +++ b/source3/passdb/login_cache.c @@ -72,7 +72,7 @@ LOGIN_CACHE * login_cache_read(SAM_ACCOUNT *sampass) if (!login_cache_init()) return NULL; - keybuf.dptr = strdup(pdb_get_nt_username(sampass)); + keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass)); if (!keybuf.dptr || !strlen(keybuf.dptr)) { SAFE_FREE(keybuf.dptr); return NULL; @@ -84,7 +84,7 @@ LOGIN_CACHE * login_cache_read(SAM_ACCOUNT *sampass) databuf = tdb_fetch(cache, keybuf); SAFE_FREE(keybuf.dptr); - if (!(entry = malloc(sizeof(LOGIN_CACHE)))) { + if (!(entry = SMB_MALLOC_P(LOGIN_CACHE))) { DEBUG(1, ("Unable to allocate cache entry buffer!\n")); SAFE_FREE(databuf.dptr); return NULL; @@ -117,7 +117,7 @@ BOOL login_cache_write(const SAM_ACCOUNT *sampass, LOGIN_CACHE entry) if (!login_cache_init()) return False; - keybuf.dptr = strdup(pdb_get_nt_username(sampass)); + keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass)); if (!keybuf.dptr || !strlen(keybuf.dptr)) { SAFE_FREE(keybuf.dptr); return False; @@ -132,7 +132,7 @@ BOOL login_cache_write(const SAM_ACCOUNT *sampass, LOGIN_CACHE entry) entry.acct_ctrl, entry.bad_password_count, entry.bad_password_time); - databuf.dptr = malloc(databuf.dsize); + databuf.dptr = SMB_MALLOC(databuf.dsize); if (!databuf.dptr) { SAFE_FREE(keybuf.dptr); return False; @@ -163,7 +163,7 @@ BOOL login_cache_delentry(const SAM_ACCOUNT *sampass) if (!login_cache_init()) return False; - keybuf.dptr = strdup(pdb_get_nt_username(sampass)); + keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass)); if (!keybuf.dptr || !strlen(keybuf.dptr)) { SAFE_FREE(keybuf.dptr); return False; diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c index 4df497461a..8a3d35defd 100644 --- a/source3/passdb/lookup_sid.c +++ b/source3/passdb/lookup_sid.c @@ -208,7 +208,7 @@ static void store_uid_sid_cache(const DOM_SID *psid, uid_t uid) } } - pc = (struct uid_sid_cache *)malloc(sizeof(struct uid_sid_cache)); + pc = SMB_MALLOC_P(struct uid_sid_cache); if (!pc) return; pc->uid = uid; @@ -282,7 +282,7 @@ static void store_gid_sid_cache(const DOM_SID *psid, gid_t gid) } } - pc = (struct gid_sid_cache *)malloc(sizeof(struct gid_sid_cache)); + pc = SMB_MALLOC_P(struct gid_sid_cache); if (!pc) return; pc->gid = gid; diff --git a/source3/passdb/machine_sid.c b/source3/passdb/machine_sid.c index ce1354ce81..ae0b16273f 100644 --- a/source3/passdb/machine_sid.c +++ b/source3/passdb/machine_sid.c @@ -83,7 +83,7 @@ static DOM_SID *pdb_generate_sam_sid(void) BOOL is_dc = False; DOM_SID *sam_sid; - if(!(sam_sid=(DOM_SID *)malloc(sizeof(DOM_SID)))) + if(!(sam_sid=SMB_MALLOC_P(DOM_SID))) return NULL; generate_wellknown_sids(); diff --git a/source3/passdb/passdb.c b/source3/passdb/passdb.c index 35317b9816..aeea4316f3 100644 --- a/source3/passdb/passdb.c +++ b/source3/passdb/passdb.c @@ -133,7 +133,7 @@ NTSTATUS pdb_init_sam_talloc(TALLOC_CTX *mem_ctx, SAM_ACCOUNT **user) return NT_STATUS_UNSUCCESSFUL; } - *user=(SAM_ACCOUNT *)talloc(mem_ctx, sizeof(SAM_ACCOUNT)); + *user=TALLOC_P(mem_ctx, SAM_ACCOUNT); if (*user==NULL) { DEBUG(0,("pdb_init_sam_talloc: error while allocating memory\n")); @@ -1893,7 +1893,7 @@ BOOL init_sam_from_buffer_v2(SAM_ACCOUNT *sampass, uint8 *buf, uint32 buflen) /* Change from V1 is addition of password history field. */ account_policy_get(AP_PASSWORD_HISTORY, &pwHistLen); if (pwHistLen) { - char *pw_hist = malloc(pwHistLen * PW_HISTORY_ENTRY_LEN); + char *pw_hist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN); if (!pw_hist) { ret = False; goto done; @@ -2172,7 +2172,7 @@ uint32 init_buffer_from_sam_v2 (uint8 **buf, const SAM_ACCOUNT *sampass, BOOL si } /* malloc the space needed */ - if ( (*buf=(uint8*)malloc(len)) == NULL) { + if ( (*buf=(uint8*)SMB_MALLOC(len)) == NULL) { DEBUG(0,("init_buffer_from_sam_v2: Unable to malloc() memory for buffer!\n")); return (-1); } diff --git a/source3/passdb/pdb_get_set.c b/source3/passdb/pdb_get_set.c index 51c408e6d5..2ca7638472 100644 --- a/source3/passdb/pdb_get_set.c +++ b/source3/passdb/pdb_get_set.c @@ -1224,7 +1224,7 @@ BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext) if (current_history_len < pwHistLen) { /* Ensure we have space for the needed history. */ - uchar *new_history = talloc(sampass->mem_ctx, + uchar *new_history = TALLOC(sampass->mem_ctx, pwHistLen*PW_HISTORY_ENTRY_LEN); /* And copy it into the new buffer. */ if (current_history_len) { diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c index f18ef616f0..9bc38fb444 100644 --- a/source3/passdb/pdb_interface.c +++ b/source3/passdb/pdb_interface.c @@ -98,7 +98,7 @@ NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function in return NT_STATUS_OBJECT_NAME_COLLISION; } - entry = smb_xmalloc(sizeof(struct pdb_init_function_entry)); + entry = SMB_XMALLOC_P(struct pdb_init_function_entry); entry->name = smb_xstrdup(name); entry->init = init; @@ -711,7 +711,7 @@ static NTSTATUS make_pdb_context(struct pdb_context **context) return NT_STATUS_NO_MEMORY; } - *context = talloc(mem_ctx, sizeof(**context)); + *context = TALLOC_P(mem_ctx, struct pdb_context); if (!*context) { DEBUG(0, ("make_pdb_context: talloc failed!\n")); return NT_STATUS_NO_MEMORY; @@ -1260,7 +1260,7 @@ static void pdb_default_endsampwent(struct pdb_methods *methods) NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods) { - *methods = talloc(mem_ctx, sizeof(struct pdb_methods)); + *methods = TALLOC_P(mem_ctx, struct pdb_methods); if (!*methods) { return NT_STATUS_NO_MEMORY; diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c index 3ea291b611..a84b2f35b2 100644 --- a/source3/passdb/pdb_ldap.c +++ b/source3/passdb/pdb_ldap.c @@ -730,7 +730,7 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state, /* We can only store (sizeof(pstring)-1)/64 password history entries. */ pwHistLen = MIN(pwHistLen, ((sizeof(temp)-1)/64)); - if ((pwhist = malloc(pwHistLen * PW_HISTORY_ENTRY_LEN)) == NULL){ + if ((pwhist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN)) == NULL){ DEBUG(0, ("init_sam_from_ldap: malloc failed!\n")); return False; } @@ -1266,9 +1266,9 @@ static void append_attr(char ***attr_list, const char *new_attr) ; } - (*attr_list) = Realloc((*attr_list), sizeof(**attr_list) * (i+2)); + (*attr_list) = SMB_REALLOC_ARRAY((*attr_list), char *, i+2); SMB_ASSERT((*attr_list) != NULL); - (*attr_list)[i] = strdup(new_attr); + (*attr_list)[i] = SMB_STRDUP(new_attr); (*attr_list)[i+1] = NULL; } @@ -2644,7 +2644,7 @@ static NTSTATUS ldapsam_enum_group_mapping(struct pdb_methods *methods, continue; } - mapt=(GROUP_MAP *)Realloc((*rmap), (entries+1)*sizeof(GROUP_MAP)); + mapt=SMB_REALLOC_ARRAY((*rmap), GROUP_MAP, entries+1); if (!mapt) { DEBUG(0,("ldapsam_enum_group_mapping: Unable to enlarge group map!\n")); SAFE_FREE(*rmap); @@ -2971,7 +2971,7 @@ static NTSTATUS pdb_init_ldapsam_common(PDB_CONTEXT *pdb_context, PDB_METHODS ** /* TODO: Setup private data and free */ - ldap_state = talloc_zero(pdb_context->mem_ctx, sizeof(*ldap_state)); + ldap_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct ldapsam_privates); if (!ldap_state) { DEBUG(0, ("pdb_init_ldapsam_common: talloc() failed for ldapsam private_data!\n")); return NT_STATUS_NO_MEMORY; diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c index 805201615c..d75d0ed5c8 100644 --- a/source3/passdb/pdb_smbpasswd.c +++ b/source3/passdb/pdb_smbpasswd.c @@ -551,7 +551,7 @@ static char *format_new_smbpasswd_entry(const struct smb_passwd *newpwd) new_entry_length = strlen(newpwd->smb_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + NEW_PW_FORMAT_SPACE_PADDED_LEN + 1 + 13 + 2; - if((new_entry = (char *)malloc( new_entry_length )) == NULL) { + if((new_entry = (char *)SMB_MALLOC( new_entry_length )) == NULL) { DEBUG(0, ("format_new_smbpasswd_entry: Malloc failed adding entry for user %s.\n", newpwd->smb_name )); return NULL; @@ -1505,7 +1505,7 @@ static NTSTATUS pdb_init_smbpasswd(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_m /* Setup private data and free function */ - privates = talloc_zero(pdb_context->mem_ctx, sizeof(struct smbpasswd_privates)); + privates = TALLOC_ZERO_P(pdb_context->mem_ctx, struct smbpasswd_privates); if (!privates) { DEBUG(0, ("talloc() failed for smbpasswd private_data!\n")); diff --git a/source3/passdb/pdb_sql.c b/source3/passdb/pdb_sql.c index 37e408a387..820280bcbf 100644 --- a/source3/passdb/pdb_sql.c +++ b/source3/passdb/pdb_sql.c @@ -78,7 +78,7 @@ static void pdb_sql_int_field(struct pdb_sql_query *q, const char *name, int val char *sql_escape_string(const char *unesc) { - char *esc = malloc(strlen(unesc) * 2 + 3); + char *esc = SMB_MALLOC(strlen(unesc) * 2 + 3); size_t pos_unesc = 0, pos_esc = 0; for(pos_unesc = 0; unesc[pos_unesc]; pos_unesc++) { @@ -475,7 +475,7 @@ char *sql_account_query_update(const char *location, const SAM_ACCOUNT *newpwd, " VALUES (%s", query.part2); } - ret = strdup(query.part1); + ret = SMB_STRDUP(query.part1); talloc_destroy(query.mem_ctx); return ret; } diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c index 5fb5ce3891..c792d229b9 100644 --- a/source3/passdb/pdb_tdb.c +++ b/source3/passdb/pdb_tdb.c @@ -267,7 +267,7 @@ static int tdbsam_traverse_setpwent(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, struct pwent_list *ptr; if ( strncmp(key.dptr, prefix, prefixlen) == 0 ) { - if ( !(ptr=(struct pwent_list*)malloc(sizeof(struct pwent_list))) ) { + if ( !(ptr=SMB_MALLOC_P(struct pwent_list)) ) { DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n")); /* just return 0 and let the traversal continue */ @@ -724,7 +724,7 @@ static NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth (*pdb_method)->update_sam_account = tdbsam_update_sam_account; (*pdb_method)->delete_sam_account = tdbsam_delete_sam_account; - tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates)); + tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates); if (!tdb_state) { DEBUG(0, ("talloc() failed for tdbsam private_data!\n")); diff --git a/source3/passdb/privileges.c b/source3/passdb/privileges.c index 624817e32e..69fc75a618 100644 --- a/source3/passdb/privileges.c +++ b/source3/passdb/privileges.c @@ -121,7 +121,7 @@ NTSTATUS privilege_enum_account_with_right(const char *right, *count = i; /* allocate and parse */ - *sids = malloc(sizeof(DOM_SID) * *count); + *sids = SMB_MALLOC_ARRAY(DOM_SID, *count); if (! *sids) { return NT_STATUS_NO_MEMORY; } @@ -154,7 +154,7 @@ static NTSTATUS privilege_set_accounts_with_right(const char *right, } /* allocate the maximum size that we might use */ - data.dptr = malloc(count * ((MAXSUBAUTHS*11) + 30)); + data.dptr = SMB_MALLOC(count * ((MAXSUBAUTHS*11) + 30)); if (!data.dptr) { return NT_STATUS_NO_MEMORY; } @@ -210,7 +210,7 @@ NTSTATUS privilege_add_account_right(const char *right, } /* add it in */ - current_sids = Realloc(current_sids, sizeof(current_sids[0]) * (current_count+1)); + current_sids = SMB_REALLOC_ARRAY(current_sids, DOM_SID, current_count+1); if (!current_sids) { privilege_unlock_right(right); return NT_STATUS_NO_MEMORY; @@ -323,14 +323,14 @@ NTSTATUS privilege_enum_account_rights(DOM_SID *sid, right = key.dptr; if (privilege_sid_has_right(sid, right)) { - (*rights) = (char **)Realloc(*rights,sizeof(char *) * ((*count)+1)); + (*rights) = SMB_REALLOC_ARRAY(*rights,char *, (*count)+1); if (! *rights) { safe_free(nextkey.dptr); free(key.dptr); return NT_STATUS_NO_MEMORY; } - (*rights)[*count] = strdup(right); + (*rights)[*count] = SMB_STRDUP(right); (*count)++; } diff --git a/source3/passdb/secrets.c b/source3/passdb/secrets.c index 426217b82c..6be63e4f9d 100644 --- a/source3/passdb/secrets.c +++ b/source3/passdb/secrets.c @@ -346,7 +346,7 @@ BOOL secrets_fetch_trusted_domain_password(const char *domain, char** pwd, /* the trust's password */ if (pwd) { - *pwd = strdup(pass.pass); + *pwd = SMB_STRDUP(pass.pass); if (!*pwd) { return False; } @@ -577,7 +577,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in size_t size, packed_size = 0; fstring dom_name; char *packed_pass; - struct trusted_dom_pass *pass = talloc_zero(ctx, sizeof(struct trusted_dom_pass)); + struct trusted_dom_pass *pass = TALLOC_ZERO_P(ctx, struct trusted_dom_pass); NTSTATUS status; if (!secrets_init()) return NT_STATUS_ACCESS_DENIED; @@ -599,7 +599,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in DEBUG(5, ("secrets_get_trusted_domains: looking for %d domains, starting at index %d\n", max_num_domains, *enum_ctx)); - *domains = talloc_zero(ctx, sizeof(**domains)*max_num_domains); + *domains = TALLOC_ZERO_ARRAY(ctx, TRUSTDOM *, max_num_domains); /* fetching trusted domains' data and collecting them in a list */ keys = tdb_search_keys(tdb, pattern); @@ -615,7 +615,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in char *secrets_key; /* important: ensure null-termination of the key string */ - secrets_key = strndup(k->node_key.dptr, k->node_key.dsize); + secrets_key = SMB_STRNDUP(k->node_key.dptr, k->node_key.dsize); if (!secrets_key) { DEBUG(0, ("strndup failed!\n")); return NT_STATUS_NO_MEMORY; @@ -638,7 +638,7 @@ NTSTATUS secrets_get_trusted_domains(TALLOC_CTX* ctx, int* enum_ctx, unsigned in SAFE_FREE(secrets_key); if (idx >= start_idx && idx < start_idx + max_num_domains) { - dom = talloc_zero(ctx, sizeof(*dom)); + dom = TALLOC_ZERO_P(ctx, TRUSTDOM); if (!dom) { /* free returned tdb record */ return NT_STATUS_NO_MEMORY; diff --git a/source3/passdb/util_sam_sid.c b/source3/passdb/util_sam_sid.c index 7bc6da94c0..c93c3400bd 100644 --- a/source3/passdb/util_sam_sid.c +++ b/source3/passdb/util_sam_sid.c @@ -106,16 +106,16 @@ static void init_sid_name_map (void) /* This is not lp_workgroup() for good reason: it must stay around longer than the lp_*() strings do */ - sid_name_map[i].name = strdup(lp_workgroup()); + sid_name_map[i].name = SMB_STRDUP(lp_workgroup()); sid_name_map[i].known_users = NULL; i++; sid_name_map[i].sid = get_global_sam_sid(); - sid_name_map[i].name = strdup(global_myname()); + sid_name_map[i].name = SMB_STRDUP(global_myname()); sid_name_map[i].known_users = NULL; i++; } else { sid_name_map[i].sid = get_global_sam_sid(); - sid_name_map[i].name = strdup(global_myname()); + sid_name_map[i].name = SMB_STRDUP(global_myname()); sid_name_map[i].known_users = NULL; i++; } @@ -317,7 +317,7 @@ BOOL map_name_to_wellknown_sid(DOM_SID *sid, enum SID_NAME_USE *use, const char void add_sid_to_array(const DOM_SID *sid, DOM_SID **sids, int *num) { - *sids = Realloc(*sids, ((*num)+1) * sizeof(DOM_SID)); + *sids = SMB_REALLOC_ARRAY(*sids, DOM_SID, (*num)+1); if (*sids == NULL) return; |