s3:pylibsmb: Make .list() work for SMBv2
[samba.git] / source3 / utils / profiles.c
index 6c6c7fdb0137b1591f315aff439561dacd886396..3451c0b80524e85b93ceaaeb272aa0d549491031 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "popt_common.h"
 #include "registry/reg_objects.h"
 #include "registry/regfio.h"
-#include "../libcli/security/dom_sid.h"
+#include "../libcli/security/security.h"
 
 /* GLOBAL VARIABLES */
 
@@ -63,34 +64,40 @@ static bool swap_sid_in_acl( struct security_descriptor *sd, struct dom_sid *s1,
        struct security_acl *theacl;
        int i;
        bool update = False;
+       struct dom_sid_buf buf;
 
-       verbose_output("  Owner SID: %s\n", sid_string_tos(sd->owner_sid));
+       verbose_output("  Owner SID: %s\n",
+                      dom_sid_str_buf(sd->owner_sid, &buf));
        if ( dom_sid_equal( sd->owner_sid, s1 ) ) {
                sid_copy( sd->owner_sid, s2 );
                update = True;
                verbose_output("  New Owner SID: %s\n",
-                       sid_string_tos(sd->owner_sid));
+                              dom_sid_str_buf(sd->owner_sid, &buf));
 
        }
 
-       verbose_output("  Group SID: %s\n", sid_string_tos(sd->group_sid));
+       verbose_output("  Group SID: %s\n",
+                      dom_sid_str_buf(sd->group_sid, &buf));
        if ( dom_sid_equal( sd->group_sid, s1 ) ) {
                sid_copy( sd->group_sid, s2 );
                update = True;
                verbose_output("  New Group SID: %s\n",
-                       sid_string_tos(sd->group_sid));
+                              dom_sid_str_buf(sd->group_sid, &buf));
        }
 
        theacl = sd->dacl;
        verbose_output("  DACL: %d entries:\n", theacl->num_aces);
        for ( i=0; i<theacl->num_aces; i++ ) {
                verbose_output("    Trustee SID: %s\n",
-                       sid_string_tos(&theacl->aces[i].trustee));
+                              dom_sid_str_buf(&theacl->aces[i].trustee,
+                                              &buf));
                if ( dom_sid_equal( &theacl->aces[i].trustee, s1 ) ) {
                        sid_copy( &theacl->aces[i].trustee, s2 );
                        update = True;
-                       verbose_output("    New Trustee SID: %s\n",
-                               sid_string_tos(&theacl->aces[i].trustee));
+                       verbose_output(
+                               "    New Trustee SID: %s\n",
+                               dom_sid_str_buf(&theacl->aces[i].trustee,
+                                               &buf));
                }
        }
 
@@ -99,12 +106,15 @@ static bool swap_sid_in_acl( struct security_descriptor *sd, struct dom_sid *s1,
        verbose_output("  SACL: %d entries: \n", theacl->num_aces);
        for ( i=0; i<theacl->num_aces; i++ ) {
                verbose_output("    Trustee SID: %s\n",
-                       sid_string_tos(&theacl->aces[i].trustee));
+                              dom_sid_str_buf(&theacl->aces[i].trustee,
+                                              &buf));
                if ( dom_sid_equal( &theacl->aces[i].trustee, s1 ) ) {
                        sid_copy( &theacl->aces[i].trustee, s2 );
                        update = True;
-                       verbose_output("    New Trustee SID: %s\n",
-                               sid_string_tos(&theacl->aces[i].trustee));
+                       verbose_output(
+                               "    New Trustee SID: %s\n",
+                               dom_sid_str_buf(&theacl->aces[i].trustee,
+                                               &buf));
                }
        }
 #endif
@@ -128,8 +138,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;
        }
 
@@ -181,19 +198,19 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
                }
        }
 
-       /* values is a talloc()'d child of subkeys here so just throw it all away */
-
-       TALLOC_FREE( subkeys );
 
        verbose_output("[%s]\n", path);
 
+       /* values is a talloc()'d child of subkeys here so just throw it all away */
+       TALLOC_FREE(subkeys);
+
        return True;
 }
 
 /*********************************************************************
 *********************************************************************/
 
-int main( int argc, char *argv[] )
+int main( int argc, const char *argv[] )
 {
        TALLOC_CTX *frame = talloc_stackframe();
        int opt;
@@ -211,15 +228,13 @@ int main( int argc, char *argv[] )
        };
        poptContext pc;
 
-       load_case_tables();
+       smb_init_locale();
 
        /* 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>");