r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[samba.git] / source / libmsrpc / libmsrpc_internal.c
index 36e604f90ffac8b199ab520dd5abbc8ae7bdadbc..5c80509659d74ff15c8e9e50679aec09fa4e73d1 100644 (file)
@@ -6,7 +6,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,
  *  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 "libmsrpc.h"
 #include "libmsrpc_internal.h"
 
+char *cac_unistr_to_str( TALLOC_CTX * mem_ctx, uint16 * src, int num_bytes );
+char *talloc_unistr2_to_ascii( TALLOC_CTX * mem_ctx, UNISTR2 str );
+char *cac_unistr_ascii( TALLOC_CTX * mem_ctx, UNISTR src );
+
 /*used to get a struct rpc_pipe_client* to be passed into rpccli* calls*/
 struct rpc_pipe_client *cac_GetPipe( CacServerHandle * hnd, int pi_idx )
 {
@@ -196,7 +199,7 @@ char *cac_unistr_to_str( TALLOC_CTX * mem_ctx, uint16 * src, int num_bytes )
        /*need room for a '\0' */
        str_len++;
 
-       buf = talloc_array( mem_ctx, char, str_len );
+       buf = TALLOC_ARRAY( mem_ctx, char, str_len );
 
        if ( !buf ) {
                return NULL;
@@ -260,13 +263,16 @@ REG_VALUE_DATA *cac_MakeRegValueData( TALLOC_CTX * mem_ctx, uint32 data_type,
 
                data->reg_binary.data_length = size;
 
-               data->reg_binary.data =
-                       ( uint8 * ) talloc_memdup( mem_ctx, buf.buffer,
-                                                  size );
-               if ( !data->reg_binary.data ) {
-                       TALLOC_FREE( data );
-                       errno = ENOMEM;
-                       data = NULL;
+               if (size) {
+                       data->reg_binary.data =
+                               ( uint8 * ) TALLOC_MEMDUP( mem_ctx, buf.buffer, size );
+                       if ( !data->reg_binary.data ) {
+                               TALLOC_FREE( data );
+                               errno = ENOMEM;
+                               data = NULL;
+                       }
+               } else {
+                       data->reg_binary.data = NULL;
                }
                break;
 
@@ -292,12 +298,16 @@ REG_VALUE_DATA *cac_MakeRegValueData( TALLOC_CTX * mem_ctx, uint32 data_type,
                                break;
                }
 
-               strings = talloc_array( mem_ctx, char *, num_strings );
+               if (num_strings) {
+                       strings = TALLOC_ARRAY( mem_ctx, char *, num_strings );
 
-               if ( !strings ) {
-                       errno = ENOMEM;
-                       TALLOC_FREE( data );
-                       break;
+                       if ( !strings ) {
+                               errno = ENOMEM;
+                               TALLOC_FREE( data );
+                               break;
+                       }
+               } else {
+                       strings = NULL;
                }
 
                if ( num_strings == 0 ) /*then our work here is done */
@@ -420,7 +430,7 @@ char *talloc_unistr2_to_ascii( TALLOC_CTX * mem_ctx, UNISTR2 str )
        if ( !mem_ctx )
                return NULL;
 
-       buf = talloc_array( mem_ctx, char, ( str.uni_str_len + 1 ) );
+       buf = TALLOC_ARRAY( mem_ctx, char, ( str.uni_str_len + 1 ) );
        if ( !buf )
                return NULL;
 
@@ -510,7 +520,7 @@ CacUserInfo *cac_MakeUserInfo( TALLOC_CTX * mem_ctx, SAM_USERINFO_CTR * ctr )
        memcpy( info->lm_password, id21->lm_pwd, 8 );
 
        info->logon_hours =
-               ( LOGON_HRS * ) talloc_memdup( mem_ctx, &( id21->logon_hrs ),
+               ( LOGON_HRS * ) TALLOC_MEMDUP( mem_ctx, &( id21->logon_hrs ),
                                               sizeof( LOGON_HRS ) );
        if ( !info->logon_hours )
                return NULL;
@@ -702,9 +712,13 @@ CacService *cac_MakeServiceArray( TALLOC_CTX * mem_ctx,
        if ( !mem_ctx || !svc )
                return NULL;
 
-       services = TALLOC_ZERO_ARRAY( mem_ctx, CacService, num_services );
-       if ( !services )
-               return NULL;
+       if (num_services) {
+               services = TALLOC_ZERO_ARRAY( mem_ctx, CacService, num_services );
+               if ( !services )
+                       return NULL;
+       } else {
+               services = NULL;
+       }
 
        for ( i = 0; i < num_services; i++ ) {
                services[i].service_name =