s3:net: Allow to load ODJ blob from stdin
authorSamuel Cabrero <scabrero@samba.org>
Wed, 30 Aug 2023 18:53:18 +0000 (20:53 +0200)
committerJule Anger <janger@samba.org>
Wed, 29 Nov 2023 14:52:09 +0000 (14:52 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13577

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit c14a4f51443f67bc46a670a342eed8cb9e81f37d)

source3/utils/net_offlinejoin.c

index 456f331140c6d1c7dfbc7998e844169611e76c72..35de74e2df9b238f474a952afb3f626cf11f7da8 100644 (file)
@@ -244,6 +244,7 @@ static int net_offlinejoin_requestodj_usage(struct net_context *c, int argc, con
        d_printf(_("\nnet offlinejoin requestodj [misc. options]\n"
                   "\tRequests offline domain join\n"));
        d_printf(_("Valid options:\n"));
+       d_printf(_("\t-i\t\t\t\t\tRead ODJ data from STDIN\n"));
        d_printf(_("\tloadfile=<FILENAME>\t\t\tFile that provides the ODJ data\n"));
        /*d_printf(_("\tlocalos\t\t\t\t\tModify the local machine\n"));*/
        net_common_flags_usage(c, argc, argv);
@@ -260,7 +261,7 @@ int net_offlinejoin_requestodj(struct net_context *c,
        const char *windows_path = NULL;
        int i;
 
-       if (c->display_usage || argc == 1) {
+       if (c->display_usage) {
                return net_offlinejoin_requestodj_usage(c, argc, argv);
        }
 
@@ -294,8 +295,29 @@ int net_offlinejoin_requestodj(struct net_context *c,
 #endif
        }
 
+       if (c->opt_stdin) {
+               if (isatty(STDIN_FILENO) == 1) {
+                       d_fprintf(stderr,
+                                 "hint: stdin waiting for ODJ blob, end "
+                                 "with <crtl-D>.\n");
+               }
+               provision_bin_data =
+                       (uint8_t *)fd_load(STDIN_FILENO,
+                                          &provision_bin_data_size, 0, c);
+               if (provision_bin_data == NULL) {
+                       d_printf("Failed to read ODJ blob from stdin\n");
+                       return -1;
+               }
+
+               /* Strip last newline */
+               if (provision_bin_data[provision_bin_data_size - 1] == '\n') {
+                       provision_bin_data[provision_bin_data_size - 1] = '\0';
+               }
+       }
+
        if (provision_bin_data == NULL || provision_bin_data_size == 0) {
-               d_printf("Please provide provision data\n");
+               d_printf("Please provide provision data either from file "
+                        "(using loadfile parameter) of from stdin (-i)\n");
                return -1;
        }
        if (provision_bin_data_size > UINT32_MAX) {