profiles... CONFLICT => was 1150460cfcd52357cbc60cd72e8e9bafd71db02f
authorStefan Metzmacher <metze@samba.org>
Wed, 6 Mar 2013 08:41:10 +0000 (09:41 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 4 Oct 2016 12:52:16 +0000 (14:52 +0200)
source3/utils/profiles.c

index aa2bc741aa7eb68853cf79b77c70c091618283e7..d128d6d1d674e88d4857b45c42662707a649cdd6 100644 (file)
@@ -22,9 +22,8 @@
 #include "includes.h"
 #include "system/filesys.h"
 #include "popt_common.h"
-#include "registry/reg_objects.h"
-#include "registry/regfio.h"
 #include "../libcli/security/security.h"
+<<<<<<< HEAD
 
 /* GLOBAL VARIABLES */
 
@@ -197,6 +196,9 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
 
        return True;
 }
+=======
+#include "../librpc/gen_ndr/ndr_security.h"
+>>>>>>> 1150460... profiles...
 
 /*********************************************************************
 *********************************************************************/
@@ -205,9 +207,15 @@ int main( int argc, const char *argv[] )
 {
        TALLOC_CTX *frame = talloc_stackframe();
        int opt;
-       REGF_FILE *infile, *outfile;
-       REGF_NK_REC *nk;
+       int change = 0, new_val = 0;
+       struct dom_sid old_sid, new_sid;
+       DATA_BLOB old_blob, new_blob;
+       enum ndr_err_code ndr_err;
        char *orig_filename, *new_filename;
+       uint8_t *buf;
+       size_t len;
+       size_t ofs;
+       int opt_verbose = False;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
                { "change-sid", 'c', POPT_ARG_STRING, NULL, 'c', "Provides SID to change" },
@@ -279,35 +287,55 @@ int main( int argc, const char *argv[] )
                exit(ENOMEM);
        }
 
-       if (!(infile = regfio_open( orig_filename, O_RDONLY, 0))) {
+       buf = (uint8_t *)file_load(orig_filename, &len, UINT32_MAX, frame);
+       if (buf == NULL) {
                fprintf( stderr, "Failed to open %s!\n", orig_filename );
                fprintf( stderr, "Error was (%s)\n", strerror(errno) );
                exit (1);
        }
 
-       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);
-       }
+       ndr_err = ndr_push_struct_blob(&old_blob, frame, &old_sid,
+                       (ndr_push_flags_fn_t) ndr_push_security_descriptor);
+       ndr_err = ndr_push_struct_blob(&new_blob, frame, &new_sid,
+                       (ndr_push_flags_fn_t) ndr_push_security_descriptor);
 
-       /* actually do the update now */
+       if (new_blob.length > old_blob.length) {
 
-       if ((nk = regfio_rootkey( infile )) == NULL) {
-               fprintf(stderr, "Could not get rootkey\n");
-               exit(3);
        }
 
-       if (!copy_registry_tree( infile, nk, NULL, outfile, "")) {
-               fprintf(stderr, "Failed to write updated registry file!\n");
-               exit(2);
+       if (new_blob.length < old_blob.length) {
+               static const uint8_t pad[1024];
+               size_t pad_len = old_blob.length - new_blob.length;
+               SMB_ASSERT(pad_len <= sizeof(pad));
+               data_blob_append(frame, &new_blob, pad, pad_len);
        }
 
-       /* cleanup */
+       SMB_ASSERT(new_blob.length == old_blob.length);
+
+       for (ofs=0; ofs < len;) {
+               uint8_t *p = &buf[ofs];
+               size_t remaining = len - ofs;
+               int cmp;
+
+               if (remaining < old_blob.length) {
+                       break;
+               }
+
+               cmp = memcmp(p, old_blob.data, old_blob.length);
+               if (cmp != 0) {
+                       ofs += 1;
+                       continue;
+               }
+
+               if (opt_verbose) {
+                       fprintf(stdout, "replace at ofs[%u]\n", (unsigned)ofs);
+               }
+
+               memcpy(p, new_blob.data, new_blob.length);
+               ofs += new_blob.length;
+       }
 
-       regfio_close(infile);
-       regfio_close(outfile);
+       file_save(new_filename, buf, len);
 
        poptFreeContext(pc);