Cleanup size_t return values in callers of convert_string_allocate
[metze/samba/wip.git] / source3 / libads / ldap_printer.c
index f5168b05af0cf45abe98b6d024416e1175f07102..9935e2311a5b9f6d65cb1dd1f2bf7debf62a4630 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -44,7 +43,7 @@
        if (ads_count_replies(ads, *res) != 1) {
                return ADS_ERROR(LDAP_NO_SUCH_OBJECT);
        }
-       srv_dn = ldap_get_dn(ads->ld, *res);
+       srv_dn = ldap_get_dn(ads->ldap.ld, *res);
        if (srv_dn == NULL) {
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
@@ -100,28 +99,34 @@ ADS_STATUS ads_add_printer_entry(ADS_STRUCT *ads, char *prt_dn,
 /*
   map a REG_SZ to an ldap mod
 */
-static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, 
+static bool map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods, 
                            const REGISTRY_VALUE *value)
 {
        char *str_value = NULL;
+       size_t converted_size;
        ADS_STATUS status;
 
        if (value->type != REG_SZ)
-               return False;
+               return false;
 
        if (value->size && *((smb_ucs2_t *) value->data_p)) {
-               pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p);
+               if (!pull_ucs2_talloc(ctx, &str_value,
+                                     (const smb_ucs2_t *) value->data_p,
+                                     &converted_size))
+               {
+                       return false;
+               }
                status = ads_mod_str(ctx, mods, value->valuename, str_value);
                return ADS_ERR_OK(status);
        }
-       return True;
+       return true;
                
 }
 
 /*
   map a REG_DWORD to an ldap mod
 */
-static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, 
+static bool map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods, 
                      const REGISTRY_VALUE *value)
 {
        char *str_value = NULL;
@@ -140,7 +145,7 @@ static BOOL map_dword(TALLOC_CTX *ctx, ADS_MODLIST *mods,
 /*
   map a boolean REG_BINARY to an ldap mod
 */
-static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods,
+static bool map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods,
                     const REGISTRY_VALUE *value)
 {
        char *str_value;
@@ -160,10 +165,11 @@ static BOOL map_bool(TALLOC_CTX *ctx, ADS_MODLIST *mods,
 /*
   map a REG_MULTI_SZ to an ldap mod
 */
-static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
+static bool map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
                         const REGISTRY_VALUE *value)
 {
        char **str_values = NULL;
+       size_t converted_size;
        smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p;
         uint32 size = 0, num_vals = 0, i=0;
        ADS_STATUS status;
@@ -186,9 +192,11 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
                       (num_vals + 1) * sizeof(char *));
 
                cur_str = (smb_ucs2_t *) value->data_p;
-               for (i=0; i < num_vals; i++)
+               for (i=0; i < num_vals; i++) {
                        cur_str += pull_ucs2_talloc(ctx, &str_values[i],
-                                                   cur_str);
+                                                   cur_str, &converted_size) ?
+                           converted_size : (size_t)-1;
+               }
 
                status = ads_mod_strlist(ctx, mods, value->valuename, 
                                         (const char **) str_values);
@@ -199,7 +207,7 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
 
 struct valmap_to_ads {
        const char *valname;
-       BOOL (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *);
+       bool (*fn)(TALLOC_CTX *, ADS_MODLIST *, const REGISTRY_VALUE *);
 };
 
 /*
@@ -289,16 +297,16 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli,
        uint32 i;
        POLICY_HND pol;
 
-       asprintf(&servername, "\\\\%s", cli->cli->desthost);
-       asprintf(&printername, "%s\\%s", servername, printer);
-       if (!servername || !printername) {
+       if ((asprintf(&servername, "\\\\%s", cli->desthost) == -1)
+           || (asprintf(&printername, "%s\\%s", servername, printer) == -1)) {
                DEBUG(3, ("Insufficient memory\n"));
                return WERR_NOMEM;
        }
        
        result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, 
                                             "", MAXIMUM_ALLOWED_ACCESS, 
-                                            servername, cli->cli->user_name, &pol);
+                                            servername, cli->auth->user_name,
+                                            &pol);
        if (!W_ERROR_IS_OK(result)) {
                DEBUG(3, ("Unable to open printer %s, error is %s.\n",
                          printername, dos_errstr(result)));
@@ -348,7 +356,7 @@ WERROR get_remote_printer_publishing_data(struct rpc_pipe_client *cli,
        return result;
 }
 
-BOOL get_local_printer_publishing_data(TALLOC_CTX *mem_ctx,
+bool get_local_printer_publishing_data(TALLOC_CTX *mem_ctx,
                                       ADS_MODLIST *mods,
                                       NT_PRINTER_DATA *data)
 {