summaryrefslogtreecommitdiffstats
path: root/source3/printing/nt_printing.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/printing/nt_printing.c')
-rw-r--r--source3/printing/nt_printing.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c
index ba1fb4352c..3a81f27ad6 100644
--- a/source3/printing/nt_printing.c
+++ b/source3/printing/nt_printing.c
@@ -3187,7 +3187,9 @@ static bool map_nt_printer_info2_to_dsspooler(NT_PRINTER_INFO_LEVEL_2 *info2)
map_sz_into_ctr(ctr, SPOOL_REG_SERVERNAME, longname);
- asprintf(&allocated_string, "\\\\%s\\%s", longname, info2->sharename);
+ if (asprintf(&allocated_string, "\\\\%s\\%s", longname, info2->sharename) == -1) {
+ return false;
+ }
map_sz_into_ctr(ctr, SPOOL_REG_UNCNAME, allocated_string);
SAFE_FREE(allocated_string);
@@ -3267,6 +3269,7 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
struct GUID guid;
WERROR win_rc = WERR_OK;
size_t converted_size;
+ int ret;
DEBUG(5, ("publishing printer %s\n", printer->info_2->printername));
@@ -3278,27 +3281,23 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res);
if (!srv_dn_utf8) {
- ads_destroy(&ads);
return WERR_SERVER_UNAVAILABLE;
}
ads_msgfree(ads, res);
srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1);
if (!srv_cn_utf8) {
ldap_memfree(srv_dn_utf8);
- ads_destroy(&ads);
return WERR_SERVER_UNAVAILABLE;
}
/* Now convert to CH_UNIX. */
if (!pull_utf8_allocate(&srv_dn, srv_dn_utf8, &converted_size)) {
ldap_memfree(srv_dn_utf8);
ldap_memfree(srv_cn_utf8);
- ads_destroy(&ads);
return WERR_SERVER_UNAVAILABLE;
}
if (!pull_utf8_allocate(&srv_cn_0, srv_cn_utf8[0], &converted_size)) {
ldap_memfree(srv_dn_utf8);
ldap_memfree(srv_cn_utf8);
- ads_destroy(&ads);
SAFE_FREE(srv_dn);
return WERR_SERVER_UNAVAILABLE;
}
@@ -3309,27 +3308,28 @@ static WERROR nt_printer_publish_ads(ADS_STRUCT *ads,
srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0);
if (!srv_cn_escaped) {
SAFE_FREE(srv_cn_0);
- ldap_memfree(srv_dn_utf8);
- ads_destroy(&ads);
+ SAFE_FREE(srv_dn);
return WERR_SERVER_UNAVAILABLE;
}
sharename_escaped = escape_rdn_val_string_alloc(printer->info_2->sharename);
if (!sharename_escaped) {
SAFE_FREE(srv_cn_escaped);
SAFE_FREE(srv_cn_0);
- ldap_memfree(srv_dn_utf8);
- ads_destroy(&ads);
+ SAFE_FREE(srv_dn);
return WERR_SERVER_UNAVAILABLE;
}
-
- asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn);
+ ret = asprintf(&prt_dn, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn);
SAFE_FREE(srv_dn);
SAFE_FREE(srv_cn_0);
SAFE_FREE(srv_cn_escaped);
SAFE_FREE(sharename_escaped);
+ if (ret == -1) {
+ return WERR_NOMEM;
+ }
+
/* build the ads mods */
ctx = talloc_init("nt_printer_publish_ads");
if (ctx == NULL) {
@@ -3381,7 +3381,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
NT_PRINTER_INFO_LEVEL *printer)
{
ADS_STATUS ads_rc;
- LDAPMessage *res;
+ LDAPMessage *res = NULL;
char *prt_dn = NULL;
DEBUG(5, ("unpublishing printer %s\n", printer->info_2->printername));
@@ -3390,7 +3390,7 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
ads_rc = ads_find_printer_on_server(ads, &res,
printer->info_2->sharename, global_myname());
- if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) {
+ if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) {
prt_dn = ads_get_dn(ads, res);
if (!prt_dn) {
ads_msgfree(ads, res);
@@ -3400,7 +3400,9 @@ static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads,
ads_memfree(ads, prt_dn);
}
- ads_msgfree(ads, res);
+ if (res) {
+ ads_msgfree(ads, res);
+ }
return WERR_OK;
}