summaryrefslogtreecommitdiff
path: root/source3/nsswitch
diff options
context:
space:
mode:
Diffstat (limited to 'source3/nsswitch')
-rw-r--r--source3/nsswitch/pam_winbind.h8
-rw-r--r--source3/nsswitch/wb_client.c4
-rw-r--r--source3/nsswitch/wb_common.c8
-rw-r--r--source3/nsswitch/winbind_nss_solaris.c4
-rw-r--r--source3/nsswitch/winbindd.c12
-rw-r--r--source3/nsswitch/winbindd_cache.c4
-rw-r--r--source3/nsswitch/winbindd_glue.c4
-rw-r--r--source3/nsswitch/winbindd_group.c33
-rw-r--r--source3/nsswitch/winbindd_idmap.c4
-rw-r--r--source3/nsswitch/winbindd_misc.c4
-rw-r--r--source3/nsswitch/winbindd_nss.h4
-rw-r--r--source3/nsswitch/winbindd_user.c19
-rw-r--r--source3/nsswitch/winbindd_util.c8
-rw-r--r--source3/nsswitch/wins.c3
14 files changed, 51 insertions, 68 deletions
diff --git a/source3/nsswitch/pam_winbind.h b/source3/nsswitch/pam_winbind.h
index 5618dc1b61..991c117656 100644
--- a/source3/nsswitch/pam_winbind.h
+++ b/source3/nsswitch/pam_winbind.h
@@ -68,13 +68,7 @@ do { \
* Don't just free it, forget it too.
*/
-#define _pam_drop(X) \
-do { \
- if (X) { \
- free(X); \
- X=NULL; \
- } \
-} while (0)
+#define _pam_drop(X) SAFE_FREE(X)
#define x_strdup(s) ( (s) ? strdup(s):NULL )
#endif
diff --git a/source3/nsswitch/wb_client.c b/source3/nsswitch/wb_client.c
index 12e4bb11db..bc76771f9d 100644
--- a/source3/nsswitch/wb_client.c
+++ b/source3/nsswitch/wb_client.c
@@ -347,7 +347,7 @@ int winbind_initgroups(char *user, gid_t gid)
/* Free response data if necessary */
done:
- safe_free(groups);
+ SAFE_FREE(groups);
return result;
}
@@ -381,7 +381,7 @@ int winbind_getgroups(char *user, int size, gid_t *list)
}
done:
- safe_free(groups);
+ SAFE_FREE(groups);
return result;
}
diff --git a/source3/nsswitch/wb_common.c b/source3/nsswitch/wb_common.c
index 7fb2bc2cf5..0cfefa6f86 100644
--- a/source3/nsswitch/wb_common.c
+++ b/source3/nsswitch/wb_common.c
@@ -36,7 +36,7 @@ static char *excluded_domain;
*/
void winbind_exclude_domain(const char *domain)
{
- if (excluded_domain) free(excluded_domain);
+ SAFE_FREE(excluded_domain);
excluded_domain = strdup(domain);
}
@@ -311,10 +311,8 @@ void free_response(struct winbindd_response *response)
{
/* Free any allocated extra_data */
- if (response && response->extra_data) {
- free(response->extra_data);
- response->extra_data = NULL;
- }
+ if (response)
+ SAFE_FREE(response->extra_data);
}
/* Handle simple types of requests */
diff --git a/source3/nsswitch/winbind_nss_solaris.c b/source3/nsswitch/winbind_nss_solaris.c
index de8a63b90b..9c71c75e9d 100644
--- a/source3/nsswitch/winbind_nss_solaris.c
+++ b/source3/nsswitch/winbind_nss_solaris.c
@@ -117,7 +117,7 @@ _nss_winbind_getpwuid_solwrap(nss_backend_t* be, void* args)
static NSS_STATUS _nss_winbind_passwd_destr (nss_backend_t * be, void *args)
{
- free(be);
+ SAFE_FREE(be);
NSS_DEBUG("_nss_winbind_passwd_destr");
return NSS_STATUS_SUCCESS;
}
@@ -241,7 +241,7 @@ _nss_winbind_getgroupsbymember_solwrap(nss_backend_t* be, void* args)
static NSS_STATUS
_nss_winbind_group_destr (nss_backend_t* be, void* args)
{
- free(be);
+ SAFE_FREE(be);
NSS_DEBUG("_nss_winbind_group_destr");
return NSS_STATUS_SUCCESS;
}
diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c
index 713cef312f..13b8478257 100644
--- a/source3/nsswitch/winbindd.c
+++ b/source3/nsswitch/winbindd.c
@@ -281,7 +281,7 @@ static void process_request(struct winbindd_cli_state *state)
/* Free response data - we may be interrupted and receive another
command before being able to send this data off. */
- safe_free(state->response.extra_data);
+ SAFE_FREE(state->response.extra_data);
ZERO_STRUCT(state->response);
@@ -363,12 +363,12 @@ static void remove_client(struct winbindd_cli_state *state)
/* We may have some extra data that was not freed if the
client was killed unexpectedly */
- safe_free(state->response.extra_data);
+ SAFE_FREE(state->response.extra_data);
/* Remove from list and free */
DLIST_REMOVE(client_list, state);
- free(state);
+ SAFE_FREE(state);
num_clients--;
}
}
@@ -454,8 +454,7 @@ static void client_write(struct winbindd_cli_state *state)
state->finished = True;
- safe_free(state->response.extra_data);
- state->response.extra_data = NULL;
+ SAFE_FREE(state->response.extra_data);
return;
}
@@ -472,8 +471,7 @@ static void client_write(struct winbindd_cli_state *state)
if (state->write_extra_data) {
- safe_free(state->response.extra_data);
- state->response.extra_data = NULL;
+ SAFE_FREE(state->response.extra_data);
state->write_extra_data = False;
diff --git a/source3/nsswitch/winbindd_cache.c b/source3/nsswitch/winbindd_cache.c
index 07b1cab583..3fa50abfba 100644
--- a/source3/nsswitch/winbindd_cache.c
+++ b/source3/nsswitch/winbindd_cache.c
@@ -61,7 +61,7 @@ static uint32 cached_sequence_number(char *domain_name)
goto refetch;
}
memcpy(&rec, dbuf.dptr, sizeof(rec));
- free(dbuf.dptr);
+ SAFE_FREE(dbuf.dptr);
if (t < (rec.mod_time + lp_winbind_cache_time())) {
DEBUG(3,("cached sequence number for %s is %u\n",
@@ -359,7 +359,7 @@ static BOOL fetch_cache_entry(char *domain, char *cache_type, char *name,
/* Copy found entry into buffer */
memcpy((char *)buf, data.dptr, len < data.dsize ? len : data.dsize);
- free(data.dptr);
+ SAFE_FREE(data.dptr);
return True;
}
diff --git a/source3/nsswitch/winbindd_glue.c b/source3/nsswitch/winbindd_glue.c
index 0b721e36d2..0c508ccf4b 100644
--- a/source3/nsswitch/winbindd_glue.c
+++ b/source3/nsswitch/winbindd_glue.c
@@ -82,7 +82,7 @@ BOOL wb_lsa_open_policy(char *server, BOOL sec_qos, uint32 des_access,
if (!NT_STATUS_IS_OK(result) && pol->cli) {
if (pol->cli->initialised)
cli_shutdown(pol->cli);
- free(pol->cli);
+ SAFE_FREE(pol->cli);
}
return NT_STATUS_IS_OK(result);
@@ -228,7 +228,7 @@ BOOL wb_samr_connect(char *server, uint32 access_mask, CLI_POLICY_HND *pol)
if (!NT_STATUS_IS_OK(result) && pol->cli) {
if (pol->cli->initialised)
cli_shutdown(pol->cli);
- free(pol->cli);
+ SAFE_FREE(pol->cli);
}
return NT_STATUS_IS_OK(result);
diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c
index 55dd41afd4..2b567f1336 100644
--- a/source3/nsswitch/winbindd_group.c
+++ b/source3/nsswitch/winbindd_group.c
@@ -173,8 +173,8 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain,
/* Free memory allocated in winbindd_lookup_groupmem() */
- safe_free(name_types);
- safe_free(rid_mem);
+ SAFE_FREE(name_types);
+ SAFE_FREE(rid_mem);
free_char_array(num_names, names);
@@ -489,11 +489,8 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
/* Free any existing group info */
- if (ent->sam_entries) {
- free(ent->sam_entries);
- ent->sam_entries = NULL;
- ent->num_sam_entries = 0;
- }
+ SAFE_FREE(ent->sam_entries);
+ ent->num_sam_entries = 0;
/* Enumerate domain groups */
@@ -522,7 +519,7 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
sam_grp_entries,
num_entries * sizeof(struct acct_info));
- safe_free(sam_grp_entries);
+ SAFE_FREE(sam_grp_entries);
}
ent->num_sam_entries += num_entries;
@@ -610,13 +607,13 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
/* Free state information for this domain */
- safe_free(ent->sam_entries);
+ SAFE_FREE(ent->sam_entries);
ent->sam_entries = NULL;
next_ent = ent->next;
DLIST_REMOVE(state->getgrent_state, ent);
- free(ent);
+ SAFE_FREE(ent);
ent = next_ent;
}
@@ -676,7 +673,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
if (!new_gr_mem_list && (group_list[group_list_ndx].num_gr_mem != 0)) {
DEBUG(0, ("getgrent(): out of memory\n"));
- free(gr_mem_list);
+ SAFE_FREE(gr_mem_list);
gr_mem_list_len = 0;
break;
}
@@ -689,7 +686,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
memcpy(&gr_mem_list[gr_mem_list_len], gr_mem,
gr_mem_len);
- safe_free(gr_mem);
+ SAFE_FREE(gr_mem);
group_list[group_list_ndx].gr_mem_ofs =
gr_mem_list_len;
@@ -731,9 +728,8 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
if (!new_extra_data) {
DEBUG(0, ("out of memory\n"));
group_list_ndx = 0;
- safe_free(state->response.extra_data);
- state->response.extra_data = NULL;
- safe_free(gr_mem_list);
+ SAFE_FREE(state->response.extra_data);
+ SAFE_FREE(gr_mem_list);
return WINBINDD_ERROR;
}
@@ -744,7 +740,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
[group_list_ndx * sizeof(struct winbindd_gr)],
gr_mem_list, gr_mem_list_len);
- safe_free(gr_mem_list);
+ SAFE_FREE(gr_mem_list);
state->response.length += gr_mem_list_len;
@@ -840,8 +836,7 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
if (!ted) {
DEBUG(0,("winbindd_list_groups: failed to enlarge buffer!\n"));
- if (extra_data)
- free(extra_data);
+ SAFE_FREE(extra_data);
return WINBINDD_ERROR;
} else
extra_data = ted;
@@ -977,7 +972,7 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state)
result = WINBINDD_OK;
done:
- safe_free(user_groups);
+ SAFE_FREE(user_groups);
return result;
}
diff --git a/source3/nsswitch/winbindd_idmap.c b/source3/nsswitch/winbindd_idmap.c
index 5f667a621b..8925e947b9 100644
--- a/source3/nsswitch/winbindd_idmap.c
+++ b/source3/nsswitch/winbindd_idmap.c
@@ -104,7 +104,7 @@ static BOOL get_id_from_rid(char *domain_name, uint32 rid, uid_t *id,
result = True;
}
- free(data.dptr);
+ SAFE_FREE(data.dptr);
} else {
@@ -187,7 +187,7 @@ BOOL get_rid_from_id(int id, uint32 *rid, struct winbindd_domain **domain,
result = True;
}
done:
- free(data.dptr);
+ SAFE_FREE(data.dptr);
}
return result;
diff --git a/source3/nsswitch/winbindd_misc.c b/source3/nsswitch/winbindd_misc.c
index 618dd6f1c9..620dc9e7d9 100644
--- a/source3/nsswitch/winbindd_misc.c
+++ b/source3/nsswitch/winbindd_misc.c
@@ -55,7 +55,7 @@ static BOOL _get_trust_account_password(char *domain, unsigned char *ret_pwd,
if (pass_last_set_time) *pass_last_set_time = pass->mod_time;
memcpy(ret_pwd, pass->hash, 16);
- free(pass);
+ SAFE_FREE(pass);
return True;
}
@@ -152,7 +152,7 @@ enum winbindd_result winbindd_list_trusted_domains(struct winbindd_cli_state
if (!ted) {
DEBUG(0,("winbindd_list_trusted_domains: failed to enlarge buffer!\n"));
- if (extra_data) free(extra_data);
+ SAFE_FREE(extra_data);
return WINBINDD_ERROR;
}
else extra_data = ted;
diff --git a/source3/nsswitch/winbindd_nss.h b/source3/nsswitch/winbindd_nss.h
index ed7a0d4a28..20667b0a9b 100644
--- a/source3/nsswitch/winbindd_nss.h
+++ b/source3/nsswitch/winbindd_nss.h
@@ -22,6 +22,10 @@
Boston, MA 02111-1307, USA.
*/
+#ifndef SAFE_FREE
+#define SAFE_FREE(x) do { if(x) {free(x); x=NULL;} } while(0)
+#endif
+
#ifndef _WINBINDD_NTDOM_H
#define _WINBINDD_NTDOM_H
diff --git a/source3/nsswitch/winbindd_user.c b/source3/nsswitch/winbindd_user.c
index 9e0c1e8344..aa138cfdeb 100644
--- a/source3/nsswitch/winbindd_user.c
+++ b/source3/nsswitch/winbindd_user.c
@@ -398,12 +398,9 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
/* Free any existing user info */
- if (ent->sam_entries) {
- free(ent->sam_entries);
- ent->sam_entries = NULL;
- ent->num_sam_entries = 0;
- }
-
+ SAFE_FREE(ent->sam_entries);
+ ent->num_sam_entries = 0;
+
/* Call query_dispinfo to get a list of usernames and user rids */
do {
@@ -425,8 +422,7 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
if (!tnl) {
DEBUG(0,("get_sam_user_entries: Realloc failed.\n"));
- if (name_list)
- free(name_list);
+ SAFE_FREE(name_list);
return WINBINDD_ERROR;
} else
name_list = tnl;
@@ -535,13 +531,12 @@ enum winbindd_result winbindd_getpwent(struct winbindd_cli_state *state)
/* Free state information for this domain */
- safe_free(ent->sam_entries);
- ent->sam_entries = NULL;
+ SAFE_FREE(ent->sam_entries);
next_ent = ent->next;
DLIST_REMOVE(state->getpwent_state, ent);
- free(ent);
+ SAFE_FREE(ent);
ent = next_ent;
}
@@ -653,7 +648,7 @@ enum winbindd_result winbindd_list_users(struct winbindd_cli_state *state)
if (!ted) {
DEBUG(0,("winbindd_list_users: failed to enlarge buffer!\n"));
- if (extra_data) free(extra_data);
+ SAFE_FREE(extra_data);
return WINBINDD_ERROR;
}
else extra_data = ted;
diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c
index 7059f268ca..86517c4e2d 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -297,7 +297,7 @@ void winbindd_kill_all_connections(void)
next = domain->next;
DLIST_REMOVE(domain_list, domain);
- free(domain);
+ SAFE_FREE(domain);
domain = next;
}
@@ -326,7 +326,7 @@ static BOOL get_any_dc_name(char *domain, fstring srv_name)
got_ip:
dc_ip = ip_list[i];
- free(ip_list);
+ SAFE_FREE(ip_list);
if (!lookup_pdc_name(global_myname, domain, &dc_ip, srv_name))
return False;
@@ -682,11 +682,11 @@ void free_getent_state(struct getent_state *state)
/* Free sam entries then list entry */
- safe_free(state->sam_entries);
+ SAFE_FREE(state->sam_entries);
DLIST_REMOVE(state, state);
next = temp->next;
- free(temp);
+ SAFE_FREE(temp);
temp = next;
}
}
diff --git a/source3/nsswitch/wins.c b/source3/nsswitch/wins.c
index bfd1835b4e..c4485ca03a 100644
--- a/source3/nsswitch/wins.c
+++ b/source3/nsswitch/wins.c
@@ -167,8 +167,7 @@ _nss_wins_gethostbyname_r(const char *name, struct hostent *he,
host_addresses++;
}
- if (ip_list)
- free(ip_list);
+ SAFE_FREE(ip_list);
memcpy(buffer, name, namelen);
he->h_name = buffer;