s3/profiles: improve copy_registry_tree() errors
[samba.git] / source3 / utils / profiles.c
index faec8e2c3b8e6eeddd275e7a7f10aa9e9dc60308..0f274ad604a2aa94cf2cbcc29ee2f138ea58d9ae 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "popt_common.h"
 #include "registry/reg_objects.h"
-#include "regfio.h"
-#include "../libcli/security/dom_sid.h"
+#include "registry/regfio.h"
+#include "../libcli/security/security.h"
 
 /* GLOBAL VARIABLES */
 
@@ -128,8 +129,15 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
 
        /* swap out the SIDs in the security descriptor */
 
-       if ( !(new_sd = dup_sec_desc( outfile->mem_ctx, nk->sec_desc->sec_desc )) ) {
-               fprintf( stderr, "Failed to copy security descriptor!\n" );
+       if (nk->sec_desc->sec_desc == NULL) {
+               fprintf(stderr, "Invalid (NULL) security descriptor!\n");
+               return false;
+       }
+
+       new_sd = security_descriptor_copy(outfile->mem_ctx,
+                                         nk->sec_desc->sec_desc);
+       if (new_sd == NULL) {
+               fprintf(stderr, "Failed to copy security descriptor!\n");
                return False;
        }
 
@@ -193,7 +201,7 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
 /*********************************************************************
 *********************************************************************/
 
-int main( int argc, char *argv[] )
+int main( int argc, const char *argv[] )
 {
        TALLOC_CTX *frame = talloc_stackframe();
        int opt;
@@ -215,11 +223,9 @@ int main( int argc, char *argv[] )
 
        /* setup logging options */
 
-       setup_logging( "profiles", True );
-       dbf = x_stderr;
-       x_setbuf( x_stderr, NULL );
+       setup_logging( "profiles", DEBUG_STDERR);
 
-       pc = poptGetContext("profiles", argc, (const char **)argv, long_options,
+       pc = poptGetContext("profiles", argc, argv, long_options,
                POPT_CONTEXT_KEEP_FIRST);
 
        poptSetOtherOptionHelp(pc, "<profilefile>");
@@ -279,7 +285,8 @@ int main( int argc, char *argv[] )
                exit (1);
        }
 
-       if ( !(outfile = regfio_open( new_filename, (O_RDWR|O_CREAT|O_TRUNC), (S_IREAD|S_IWRITE) )) ) {
+       if ( !(outfile = regfio_open( new_filename, (O_RDWR|O_CREAT|O_TRUNC),
+                                     (S_IRUSR|S_IWUSR) )) ) {
                fprintf( stderr, "Failed to open new file %s!\n", new_filename );
                fprintf( stderr, "Error was (%s)\n", strerror(errno) );
                exit (1);