printing: Make winreg_get_printer() a bit easier to understand
authorVolker Lendecke <vl@samba.org>
Wed, 7 Apr 2021 15:37:35 +0000 (15:37 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 19 Apr 2021 18:18:31 +0000 (18:18 +0000)
This is more lines, but the FILL_STRING macro did not really gain much
in clarity for me.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/rpc_client/cli_winreg_spoolss.c

index 051b6665fde9a6c8d936fa2d64742df5f6b90914..b84bbae2ceb089015b3a374b0d8a96f8b1d42e80 100644 (file)
 #define TOP_LEVEL_CONTROL_KEY "SYSTEM\\CurrentControlSet\\Control\\Print"
 #define TOP_LEVEL_CONTROL_FORMS_KEY TOP_LEVEL_CONTROL_KEY "\\Forms"
 
-#define FILL_STRING(mem_ctx, in, out) \
-       do { \
-               if (in && strlen(in)) { \
-                       out = talloc_strdup(mem_ctx, in); \
-               } else { \
-                       out = talloc_strdup(mem_ctx, ""); \
-               } \
-               W_ERROR_HAVE_NO_MEMORY(out); \
-       } while (0);
-
 #define CHECK_ERROR(result) \
        if (W_ERROR_IS_OK(result)) continue; \
        if (W_ERROR_EQUAL(result, WERR_NOT_FOUND)) result = WERR_OK; \
@@ -1549,23 +1539,57 @@ WERROR winreg_get_printer(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
+       result = WERR_NOT_ENOUGH_MEMORY;
+
        info2 = talloc_zero(tmp_ctx, struct spoolss_PrinterInfo2);
        if (info2 == NULL) {
-               result = WERR_NOT_ENOUGH_MEMORY;
                goto done;
        }
 
-       FILL_STRING(info2, "", info2->servername);
-       FILL_STRING(info2, "", info2->printername);
-       FILL_STRING(info2, "", info2->sharename);
-       FILL_STRING(info2, "", info2->portname);
-       FILL_STRING(info2, "", info2->drivername);
-       FILL_STRING(info2, "", info2->comment);
-       FILL_STRING(info2, "", info2->location);
-       FILL_STRING(info2, "", info2->sepfile);
-       FILL_STRING(info2, "", info2->printprocessor);
-       FILL_STRING(info2, "", info2->datatype);
-       FILL_STRING(info2, "", info2->parameters);
+       info2->servername = talloc_strdup(info2, "");
+       if (info2->servername == NULL) {
+               goto done;
+       }
+       info2->printername = talloc_strdup(info2, "");
+       if (info2->printername == NULL) {
+               goto done;
+       }
+       info2->sharename = talloc_strdup(info2, "");
+       if (info2->sharename == NULL) {
+               goto done;
+       }
+       info2->portname = talloc_strdup(info2, "");
+       if (info2->portname == NULL) {
+               goto done;
+       }
+       info2->drivername = talloc_strdup(info2, "");
+       if (info2->drivername == NULL) {
+               goto done;
+       }
+       info2->comment = talloc_strdup(info2, "");
+       if (info2->comment == NULL) {
+               goto done;
+       }
+       info2->location = talloc_strdup(info2, "");
+       if (info2->location == NULL) {
+               goto done;
+       }
+       info2->sepfile = talloc_strdup(info2, "");
+       if (info2->sepfile == NULL) {
+               goto done;
+       }
+       info2->printprocessor = talloc_strdup(info2, "");
+       if (info2->printprocessor == NULL) {
+               goto done;
+       }
+       info2->datatype = talloc_strdup(info2, "");
+       if (info2->datatype == NULL) {
+               goto done;
+       }
+       info2->parameters = talloc_strdup(info2, "");
+       if (info2->parameters == NULL) {
+               goto done;
+       }
 
        for (i = 0; i < num_values; i++) {
                enum_value.value_name = enum_names[i];