summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2002-09-27 03:05:20 +0000
committerAndrew Bartlett <abartlet@samba.org>2002-09-27 03:05:20 +0000
commitce00a3238ed8a82639c4d0ee3e960f7000b1a7b0 (patch)
treeaddd3214ae2f0ffcbed013fc76b08454e61f12c6 /source
parent4636809153987f03b14a27dba175cb1511c2d460 (diff)
downloadsamba-ce00a3238ed8a82639c4d0ee3e960f7000b1a7b0.tar.gz
samba-ce00a3238ed8a82639c4d0ee3e960f7000b1a7b0.tar.xz
samba-ce00a3238ed8a82639c4d0ee3e960f7000b1a7b0.zip
Some small cleanups to the libads code (mainly error checking), and give a
sane prototype for the push_utf8_allocate code. Andrew Bartlett
Diffstat (limited to 'source')
-rw-r--r--source/lib/charcnv.c4
-rw-r--r--source/libads/ads_status.c6
-rw-r--r--source/libads/ldap.c27
3 files changed, 30 insertions, 7 deletions
diff --git a/source/lib/charcnv.c b/source/lib/charcnv.c
index cd8aa4fe55f..d0cef52c923 100644
--- a/source/lib/charcnv.c
+++ b/source/lib/charcnv.c
@@ -522,12 +522,12 @@ int push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src)
*
* @retval The number of bytes occupied by the string in the destination
**/
-int push_utf8_allocate(void **dest, const char *src)
+int push_utf8_allocate(char **dest, const char *src)
{
int src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, dest);
+ return convert_string_allocate(CH_UNIX, CH_UTF8, src, src_len, (void **)dest);
}
/****************************************************************************
diff --git a/source/libads/ads_status.c b/source/libads/ads_status.c
index d85f9c9b58a..80fdb99eac0 100644
--- a/source/libads/ads_status.c
+++ b/source/libads/ads_status.c
@@ -72,6 +72,12 @@ NTSTATUS ads_ntstatus(ADS_STATUS status)
if (status.error_type == ADS_ERROR_NT){
return status.err.nt_status;
}
+#ifdef HAVE_LDAP
+ if ((status.error_type == ADS_ERROR_LDAP)
+ && (status.err.rc == LDAP_NO_MEMORY)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+#endif
if (ADS_ERR_OK(status)) return NT_STATUS_OK;
return NT_STATUS_UNSUCCESSFUL;
}
diff --git a/source/libads/ldap.c b/source/libads/ldap.c
index 7a0afb1a816..b4c7c3970c0 100644
--- a/source/libads/ldap.c
+++ b/source/libads/ldap.c
@@ -741,7 +741,11 @@ ADS_STATUS ads_find_machine_acct(ADS_STRUCT *ads, void **res, const char *host)
/* the easiest way to find a machine account anywhere in the tree
is to look for hostname$ */
- asprintf(&exp, "(samAccountName=%s$)", host);
+ if (asprintf(&exp, "(samAccountName=%s$)", host) == -1) {
+ DEBUG(1, ("asprintf failed!\n"));
+ return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+
status = ads_search(ads, res, exp, attrs);
free(exp);
return status;
@@ -898,13 +902,15 @@ ADS_STATUS ads_gen_mod(ADS_STRUCT *ads, const char *mod_dn, ADS_MODLIST mods)
controls[0] = &PermitModify;
controls[1] = NULL;
- push_utf8_allocate((void **) &utf8_dn, mod_dn);
+ if (push_utf8_allocate(&utf8_dn, mod_dn) == -1) {
+ return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
/* find the end of the list, marked by NULL or -1 */
for(i=0;(mods[i]!=0)&&(mods[i]!=(LDAPMod *) -1);i++);
/* make sure the end of the list is NULL */
mods[i] = NULL;
- ret = ldap_modify_ext_s(ads->ld, utf8_dn ? utf8_dn : mod_dn,
+ ret = ldap_modify_ext_s(ads->ld, utf8_dn,
(LDAPMod **) mods, controls, NULL);
SAFE_FREE(utf8_dn);
return ADS_ERROR(ret);
@@ -922,7 +928,10 @@ ADS_STATUS ads_gen_add(ADS_STRUCT *ads, const char *new_dn, ADS_MODLIST mods)
int ret, i;
char *utf8_dn = NULL;
- push_utf8_allocate((void **) &utf8_dn, new_dn);
+ if (push_utf8_allocate(&utf8_dn, new_dn) == -1) {
+ DEBUG(1, ("ads_gen_add: push_utf8_allocate failed!"));
+ return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
/* find the end of the list, marked by NULL or -1 */
for(i=0;(mods[i]!=0)&&(mods[i]!=(LDAPMod *) -1);i++);
@@ -944,7 +953,11 @@ ADS_STATUS ads_del_dn(ADS_STRUCT *ads, char *del_dn)
{
int ret;
char *utf8_dn = NULL;
- push_utf8_allocate((void **) &utf8_dn, del_dn);
+ if (push_utf8_allocate(&utf8_dn, del_dn) == -1) {
+ DEBUG(1, ("ads_del_dn: push_utf8_allocate failed!"));
+ return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
+ }
+
ret = ldap_delete(ads->ld, utf8_dn ? utf8_dn : del_dn);
return ADS_ERROR(ret);
}
@@ -991,6 +1004,10 @@ static ADS_STATUS ads_add_machine_acct(ADS_STRUCT *ads, const char *hostname,
if (!(host_upn = talloc_asprintf(ctx, "%s@%s", host_spn, ads->config.realm)))
goto done;
ou_str = ads_ou_string(org_unit);
+ if (!ou_str) {
+ DEBUG(1, ("ads_ou_string returned NULL (malloc failure?)\n"));
+ goto done;
+ }
new_dn = talloc_asprintf(ctx, "cn=%s,%s,%s", hostname, ou_str,
ads->config.bind_path);
free(ou_str);