r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[ira/wip.git] / source3 / libmsrpc / cac_samr.c
index e50fb474f51ca99d27ab2bccab034cd6e26d85a4..4c25f95288a708d1f539121f46ab31d3dae4ab2d 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,
@@ -15,8 +15,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 "libmsrpc.h"
@@ -557,10 +556,14 @@ int cac_SamGetNamesFromRids( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
             && !NT_STATUS_EQUAL( hnd->status, STATUS_SOME_UNMAPPED ) )
                return CAC_FAILURE;
 
-       map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_names_out );
-       if ( !map_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
+       if (num_names_out) {
+               map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_names_out );
+               if ( !map_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+       } else {
+               map_out = NULL;
        }
 
        for ( i = 0; i < num_names_out; i++ ) {
@@ -643,10 +646,14 @@ int cac_SamGetRidsFromNames( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
             && !NT_STATUS_EQUAL( hnd->status, STATUS_SOME_UNMAPPED ) )
                return CAC_FAILURE;
 
-       map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_rids_out );
-       if ( !map_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
+       if (num_rids_out) {
+               map_out = TALLOC_ARRAY( mem_ctx, CacLookupRidsRecord, num_rids_out );
+               if ( !map_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+       } else {
+               map_out = NULL;
        }
 
        for ( i = 0; i < num_rids_out; i++ ) {
@@ -718,16 +725,20 @@ int cac_SamGetGroupsForUser( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
                return CAC_FAILURE;
 
 
-       rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
-       if ( !rids_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
-       }
-
-       attr_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
-       if ( !attr_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               return CAC_FAILURE;
+       if (num_groups_out) {
+               rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
+               if ( !rids_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+               attr_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
+               if ( !attr_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       return CAC_FAILURE;
+               }
+       } else {
+               rids_out = NULL;
+               attr_out = NULL;
        }
 
        for ( i = 0; i < num_groups_out; i++ ) {
@@ -1153,28 +1164,34 @@ int cac_SamEnumGroups( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
                return CAC_FAILURE;
        }
 
-       names_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
-       if ( !names_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               return CAC_FAILURE;
-       }
+       if (num_groups_out) {
+               names_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
+               if ( !names_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       return CAC_FAILURE;
+               }
 
-       desc_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
-       if ( !desc_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               return CAC_FAILURE;
-       }
+               desc_out = TALLOC_ARRAY( mem_ctx, char *, num_groups_out );
+               if ( !desc_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       return CAC_FAILURE;
+               }
 
-       rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
-       if ( !rids_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               TALLOC_FREE( desc_out );
-               return CAC_FAILURE;
+               rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_groups_out );
+               if ( !rids_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       TALLOC_FREE( desc_out );
+                       return CAC_FAILURE;
+               }
+       } else {
+               names_out = NULL;
+               desc_out = NULL;
+               rids_out = NULL;
        }
 
        for ( i = 0; i < num_groups_out; i++ ) {
@@ -1256,28 +1273,34 @@ int cac_SamEnumAliases( CacServerHandle * hnd, TALLOC_CTX * mem_ctx,
             NT_STATUS_V( STATUS_MORE_ENTRIES ) )
                return CAC_FAILURE;
 
-       names_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
-       if ( !names_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               return CAC_FAILURE;
-       }
+       if (num_als_out) {
+               names_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
+               if ( !names_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       return CAC_FAILURE;
+               }
 
-       desc_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
-       if ( !desc_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               return CAC_FAILURE;
-       }
+               desc_out = TALLOC_ARRAY( mem_ctx, char *, num_als_out );
+               if ( !desc_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       return CAC_FAILURE;
+               }
 
-       rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_als_out );
-       if ( !rids_out ) {
-               hnd->status = NT_STATUS_NO_MEMORY;
-               TALLOC_FREE( acct_buf );
-               TALLOC_FREE( names_out );
-               TALLOC_FREE( desc_out );
-               return CAC_FAILURE;
+               rids_out = TALLOC_ARRAY( mem_ctx, uint32, num_als_out );
+               if ( !rids_out ) {
+                       hnd->status = NT_STATUS_NO_MEMORY;
+                       TALLOC_FREE( acct_buf );
+                       TALLOC_FREE( names_out );
+                       TALLOC_FREE( desc_out );
+                       return CAC_FAILURE;
+               }
+       } else {
+               names_out = NULL;
+               desc_out = NULL;
+               rids_out = NULL;
        }
 
        for ( i = 0; i < num_als_out; i++ ) {