s4:registry: Migrate regdiff to new cmdline option parser
authorAndreas Schneider <asn@samba.org>
Thu, 14 Jan 2021 07:59:34 +0000 (08:59 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 20 Jun 2021 23:26:32 +0000 (23:26 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/lib/registry/tools/regdiff.c
source4/lib/registry/wscript_build

index b5cf4dd2566753c75db73c23f7ff4066c66a8025..299f0e96531beaa8e8c4a74e06ed6acc749378ec 100644 (file)
@@ -22,7 +22,7 @@
 #include "includes.h"
 #include "lib/registry/registry.h"
 #include "lib/events/events.h"
-#include "lib/cmdline/popt_common.h"
+#include "lib/cmdline/cmdline.h"
 #include "lib/registry/tools/common.h"
 #include "param/param.h"
 
@@ -37,6 +37,7 @@ static struct registry_context *open_backend(TALLOC_CTX *mem_ctx,
 {
        WERROR error;
        struct registry_context *ctx;
+       struct cli_credentials *creds = samba_cmdline_get_creds();
 
        switch (backend) {
        case REG_UNKNOWN:
@@ -44,11 +45,11 @@ static struct registry_context *open_backend(TALLOC_CTX *mem_ctx,
                return NULL;
        case REG_LOCAL:
                error = reg_open_samba(mem_ctx, &ctx, ev_ctx, lp_ctx, NULL,
-                               popt_get_cmdline_credentials());
+                               creds);
                break;
        case REG_REMOTE:
                error = reg_open_remote(mem_ctx, &ctx, NULL,
-                               popt_get_cmdline_credentials(), lp_ctx,
+                               creds, lp_ctx,
                                        remote_host, ev_ctx);
                break;
        case REG_NULL:
@@ -64,8 +65,9 @@ static struct registry_context *open_backend(TALLOC_CTX *mem_ctx,
        return ctx;
 }
 
-int main(int argc, const char **argv)
+int main(int argc, char **argv)
 {
+       const char **argv_const = discard_const_p(const char *, argv);
        int opt;
        poptContext pc;
        char *outputfile = NULL;
@@ -88,10 +90,33 @@ int main(int argc, const char **argv)
        void *callback_data;
        struct tevent_context *ev_ctx;
        struct reg_diff_callbacks *callbacks;
+       struct loadparm_context *lp_ctx = NULL;
+       bool ok;
 
        ctx = talloc_init("regdiff");
+       if (ctx == NULL) {
+               exit(ENOMEM);
+       }
+
+       ok = samba_cmdline_init(ctx,
+                               SAMBA_CMDLINE_CONFIG_CLIENT,
+                               false /* require_smbconf */);
+       if (!ok) {
+               DBG_ERR("Failed to init cmdline parser!\n");
+               TALLOC_FREE(ctx);
+               exit(1);
+       }
 
-       pc = poptGetContext(argv[0], argc, argv, long_options,0);
+       pc = samba_popt_get_context(getprogname(),
+                                   argc,
+                                   argv_const,
+                                   long_options,
+                                   0);
+       if (pc == NULL) {
+               DBG_ERR("Failed to setup popt context!\n");
+               TALLOC_FREE(ctx);
+               exit(1);
+       }
 
        while((opt = poptGetNextOpt(pc)) != -1) {
                error = WERR_OK;
@@ -122,16 +147,18 @@ int main(int argc, const char **argv)
        }
 
        ev_ctx = s4_event_context_init(ctx);
+       lp_ctx = samba_cmdline_get_lp_ctx();
 
-       h1 = open_backend(ctx, pc, ev_ctx, cmdline_lp_ctx, backend1, remote1);
+       h1 = open_backend(ctx, pc, ev_ctx, lp_ctx, backend1, remote1);
        if (h1 == NULL)
                return 1;
 
-       h2 = open_backend(ctx, pc, ev_ctx, cmdline_lp_ctx, backend2, remote2);
+       h2 = open_backend(ctx, pc, ev_ctx, lp_ctx, backend2, remote2);
        if (h2 == NULL)
                return 1;
 
        poptFreeContext(pc);
+       samba_cmdline_burn(argc, argv);
 
        error = reg_dotreg_diff_save(ctx, outputfile, &callbacks, &callback_data);
        if (!W_ERROR_IS_OK(error)) {
index 34c39eed370b6236ed9105fecc5ea17550fc9622..775e177629cb359e40a8cdb1e48adc9fa3a088d0 100644 (file)
@@ -28,7 +28,7 @@ bld.SAMBA_SUBSYSTEM('registry_common',
 bld.SAMBA_BINARY('regdiff',
        source='tools/regdiff.c',
        manpages='man/regdiff.1',
-       deps='samba-hostconfig registry popt POPT_SAMBA POPT_CREDENTIALS'
+       deps='samba-hostconfig registry popt CMDLINE_S4'
        )