s3-spoolss: use is_valid_policy_hnd to check for valid policy handles.
authorGünther Deschner <gd@samba.org>
Wed, 25 Feb 2009 11:09:15 +0000 (12:09 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 25 Feb 2009 11:22:31 +0000 (12:22 +0100)
Guenther

source3/rpcclient/cmd_spoolss.c
source3/utils/net_rpc_printer.c

index ba01f7aa8bbf80f5bc7bdf8abe2495afbd5c9726..fe2554e02d2c40f9172a191852376ef2efab7d74 100644 (file)
@@ -469,7 +469,6 @@ static WERROR cmd_spoolss_setprinter(struct rpc_pipe_client *cli,
        WERROR          result;
        NTSTATUS        status;
        uint32          info_level = 2;
-       bool            opened_hnd = False;
        union spoolss_PrinterInfo info;
        struct spoolss_SetPrinterInfoCtr info_ctr;
        const char      *printername, *comment = NULL;
@@ -500,8 +499,6 @@ static WERROR cmd_spoolss_setprinter(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        /* Get printer info */
        result = rpccli_spoolss_getprinter(cli, mem_ctx,
                                           &pol,
@@ -529,7 +526,7 @@ static WERROR cmd_spoolss_setprinter(struct rpc_pipe_client *cli,
                printf("Success in setting comment.\n");
 
  done:
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
@@ -546,7 +543,6 @@ static WERROR cmd_spoolss_setprintername(struct rpc_pipe_client *cli,
        WERROR          result;
        NTSTATUS        status;
        uint32          info_level = 2;
-       bool            opened_hnd = False;
        union spoolss_PrinterInfo info;
        const char      *printername,
                        *new_printername = NULL;
@@ -578,8 +574,6 @@ static WERROR cmd_spoolss_setprintername(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        /* Get printer info */
        result = rpccli_spoolss_getprinter(cli, mem_ctx,
                                           &pol,
@@ -608,7 +602,7 @@ static WERROR cmd_spoolss_setprintername(struct rpc_pipe_client *cli,
                printf("Success in setting printername.\n");
 
  done:
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
@@ -624,7 +618,6 @@ static WERROR cmd_spoolss_getprinter(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          result;
        uint32          info_level = 1;
-       bool            opened_hnd = False;
        const char      *printername;
        union spoolss_PrinterInfo info;
 
@@ -649,8 +642,6 @@ static WERROR cmd_spoolss_getprinter(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        /* Get printer info */
 
        result = rpccli_spoolss_getprinter(cli, mem_ctx,
@@ -685,7 +676,7 @@ static WERROR cmd_spoolss_getprinter(struct rpc_pipe_client *cli,
                break;
        }
  done:
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
@@ -761,7 +752,6 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli,
 {
        POLICY_HND      pol;
        WERROR          result;
-       bool            opened_hnd = False;
        fstring         printername;
        const char *valuename;
        REGISTRY_VALUE value;
@@ -790,8 +780,6 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        /* Get printer info */
 
        result = rpccli_spoolss_getprinterdata(cli, mem_ctx, &pol, valuename, &value);
@@ -806,7 +794,7 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli,
 
 
  done:
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
@@ -822,7 +810,6 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          result;
        NTSTATUS        status;
-       bool            opened_hnd = False;
        fstring         printername;
        const char *valuename, *keyname;
        REGISTRY_VALUE value;
@@ -858,8 +845,6 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        /* Get printer info */
 
        status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx,
@@ -907,7 +892,7 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli,
        display_reg_value(value);
 
  done:
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
@@ -1095,7 +1080,6 @@ static WERROR cmd_spoolss_getdriver(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          werror;
        uint32          info_level = 3;
-       bool            opened_hnd = False;
        const char      *printername;
        uint32          i;
        bool            success = False;
@@ -1127,8 +1111,6 @@ static WERROR cmd_spoolss_getdriver(struct rpc_pipe_client *cli,
                return werror;
        }
 
-       opened_hnd = True;
-
        /* loop through and print driver info level for each architecture */
 
        for (i=0; archi_table[i].long_archi!=NULL; i++) {
@@ -1170,7 +1152,7 @@ static WERROR cmd_spoolss_getdriver(struct rpc_pipe_client *cli,
 
        /* Cleanup */
 
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        if ( success )
@@ -1584,7 +1566,6 @@ static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,
        WERROR                  result;
        NTSTATUS                status;
        uint32                  level = 2;
-       bool                    opened_hnd = False;
        const char              *printername;
        union spoolss_PrinterInfo info;
        struct spoolss_SetPrinterInfoCtr info_ctr;
@@ -1612,8 +1593,6 @@ static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        /* Get printer info */
 
        result = rpccli_spoolss_getprinter(cli, mem_ctx,
@@ -1649,7 +1628,7 @@ static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,
 done:
        /* Cleanup */
 
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
@@ -2191,7 +2170,6 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
        WERROR result;
        const char *printername;
        POLICY_HND pol;
-       bool opened_hnd = False;
        union spoolss_PrinterInfo info;
        REGISTRY_VALUE value;
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
@@ -2240,8 +2218,6 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
        if (!W_ERROR_IS_OK(result))
                goto done;
 
-       opened_hnd = True;
-
        result = rpccli_spoolss_getprinter(cli, mem_ctx,
                                           &pol,
                                           0,
@@ -2345,7 +2321,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
 done:
        /* cleanup */
        TALLOC_FREE(tmp_ctx);
-       if (opened_hnd)
+       if (is_valid_policy_hnd(&pol))
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
 
        return result;
index f4dd824c8459b23f2fbd7e0f990cc4650bd00280..99012ddf2dac55b273ad3f808b3d39a3a5d5adc1 100644 (file)
@@ -1280,7 +1280,6 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
        struct spoolss_DevmodeContainer devmode_ctr;
        struct sec_desc_buf secdesc_ctr;
        POLICY_HND hnd;
-       bool got_hnd = false;
        WERROR result;
        const char *action_str;
 
@@ -1308,8 +1307,6 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
                        PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
                        goto done;
 
-               got_hnd = true;
-
                /* check for existing dst printer */
                if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
                        goto done;
@@ -1357,7 +1354,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_
        nt_status = NT_STATUS_OK;
 
 done:
-       if (got_hnd)
+       if (is_valid_policy_hnd(&hnd))
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
 
        return nt_status;
@@ -1432,7 +1429,6 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
        PRINTER_INFO_CTR ctr, ctr_pub;
        union spoolss_PrinterInfo info;
        POLICY_HND hnd;
-       bool got_hnd = false;
        int state;
 
        if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
@@ -1461,8 +1457,6 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
                        PRINTER_ALL_ACCESS, cli->user_name, &hnd))
                        goto done;
 
-               got_hnd = true;
-
                /* check for existing dst printer */
                if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
                        goto done;
@@ -1493,7 +1487,7 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
        nt_status = NT_STATUS_OK;
 
 done:
-       if (got_hnd)
+       if (is_valid_policy_hnd(&hnd))
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
 
        return nt_status;
@@ -1533,8 +1527,6 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
        uint32 num_printers;
        uint32 level = 2;
        char *printername, *sharename;
-       bool got_hnd_src = false;
-       bool got_hnd_dst = false;
        struct rpc_pipe_client *pipe_hnd_dst = NULL;
        POLICY_HND hnd_src, hnd_dst;
        PRINTER_INFO_CTR ctr_src, ctr_enum;
@@ -1600,15 +1592,11 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
                        MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
                        goto done;
 
-               got_hnd_src = true;
-
                /* open dst printer handle */
                if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
                        PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
                        goto done;
 
-               got_hnd_dst = true;
-
                /* check for existing dst printer */
                if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
                        goto done;
@@ -1633,14 +1621,12 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
 
 
                /* close printer handles here */
-               if (got_hnd_src) {
+               if (is_valid_policy_hnd(&hnd_src)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
-                       got_hnd_src = false;
                }
 
-               if (got_hnd_dst) {
+               if (is_valid_policy_hnd(&hnd_dst)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
-                       got_hnd_dst = false;
                }
 
        }
@@ -1649,11 +1635,11 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
 
 done:
 
-       if (got_hnd_src) {
+       if (is_valid_policy_hnd(&hnd_src)) {
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
        }
 
-       if (got_hnd_dst) {
+       if (is_valid_policy_hnd(&hnd_dst)) {
                rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
        }
 
@@ -1695,8 +1681,6 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
        uint32 num_printers;
        uint32 level = 1;
        char *printername, *sharename;
-       bool got_hnd_src = false;
-       bool got_hnd_dst = false;
        struct rpc_pipe_client *pipe_hnd_dst = NULL;
        POLICY_HND hnd_src, hnd_dst;
        PRINTER_INFO_CTR ctr_enum;
@@ -1757,17 +1741,11 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
                        MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
                        goto done;
 
-               got_hnd_src = true;
-
-
                /* open dst printer handle */
                if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
                        PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
                        goto done;
 
-               got_hnd_dst = true;
-
-
                /* check for existing dst printer */
                if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
                        goto done;
@@ -1829,14 +1807,12 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
 
 
                /* close printer handles here */
-               if (got_hnd_src) {
+               if (is_valid_policy_hnd(&hnd_src)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
-                       got_hnd_src = false;
                }
 
-               if (got_hnd_dst) {
+               if (is_valid_policy_hnd(&hnd_dst)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
-                       got_hnd_dst = false;
                }
        }
 
@@ -1844,10 +1820,10 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
 
 done:
 
-       if (got_hnd_src)
+       if (is_valid_policy_hnd(&hnd_src))
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
 
-       if (got_hnd_dst)
+       if (is_valid_policy_hnd(&hnd_dst))
                rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
 
        if (cli_dst) {
@@ -1887,8 +1863,6 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
        uint32 num_printers;
        uint32 level = 3;
        char *printername, *sharename;
-       bool got_hnd_src = false;
-       bool got_hnd_dst = false;
        bool got_src_driver_share = false;
        bool got_dst_driver_share = false;
        struct rpc_pipe_client *pipe_hnd_dst = NULL;
@@ -1972,8 +1946,6 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
                        PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
                        goto done;
 
-               got_hnd_dst = true;
-
                /* check for existing dst printer */
                if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
                        goto done;
@@ -1986,9 +1958,6 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
                                                 &hnd_src))
                        goto done;
 
-               got_hnd_src = true;
-
-
                /* in a first step call getdriver for each shared printer (per arch)
                   to get a list of all files that have to be copied */
 
@@ -2048,15 +2017,13 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
                        drivername, printername));
 
                /* close dst */
-               if (got_hnd_dst) {
+               if (is_valid_policy_hnd(&hnd_dst)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
-                       got_hnd_dst = false;
                }
 
                /* close src */
-               if (got_hnd_src) {
+               if (is_valid_policy_hnd(&hnd_src)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
-                       got_hnd_src = false;
                }
        }
 
@@ -2064,10 +2031,10 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
 
 done:
 
-       if (got_hnd_src)
+       if (is_valid_policy_hnd(&hnd_src))
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
 
-       if (got_hnd_dst)
+       if (is_valid_policy_hnd(&hnd_dst))
                rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
 
        if (cli_dst) {
@@ -2120,8 +2087,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
        struct cli_state *cli_dst = NULL;
        POLICY_HND hnd_dst, hnd_src;
        char *printername, *sharename;
-       bool got_hnd_src = false;
-       bool got_hnd_dst = false;
        struct rpc_pipe_client *pipe_hnd_dst = NULL;
        struct spoolss_SetPrinterInfoCtr info_ctr;
 
@@ -2174,8 +2139,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
                        PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) {
 
                        DEBUG(1,("could not open printer: %s\n", sharename));
-               } else {
-                       got_hnd_dst = true;
                }
 
                /* check for existing dst printer */
@@ -2184,9 +2147,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
                } else {
                        DEBUG(1,("printer already exists: %s\n", sharename));
                        /* close printer handle here - dst only, not got src yet. */
-                       if (got_hnd_dst) {
+                       if (is_valid_policy_hnd(&hnd_dst)) {
                                rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
-                               got_hnd_dst = false;
                        }
                        continue;
                }
@@ -2199,8 +2161,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
                        MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
                        goto done;
 
-               got_hnd_src = true;
-
                /* getprinter on the src server */
                if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
                        goto done;
@@ -2226,24 +2186,22 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
                }
 
                /* close printer handles here */
-               if (got_hnd_src) {
+               if (is_valid_policy_hnd(&hnd_src)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
-                       got_hnd_src = false;
                }
 
-               if (got_hnd_dst) {
+               if (is_valid_policy_hnd(&hnd_dst)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
-                       got_hnd_dst = false;
                }
        }
 
        nt_status = NT_STATUS_OK;
 
 done:
-       if (got_hnd_src)
+       if (is_valid_policy_hnd(&hnd_src))
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
 
-       if (got_hnd_dst)
+       if (is_valid_policy_hnd(&hnd_dst))
                rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
 
        if (cli_dst) {
@@ -2288,8 +2246,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
        uint32 num_printers, val_needed, data_needed;
        uint32 level = 2;
        char *printername, *sharename;
-       bool got_hnd_src = false;
-       bool got_hnd_dst = false;
        struct rpc_pipe_client *pipe_hnd_dst = NULL;
        POLICY_HND hnd_src, hnd_dst;
        PRINTER_INFO_CTR ctr_enum;
@@ -2363,17 +2319,11 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
                        MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
                        goto done;
 
-               got_hnd_src = true;
-
-
                /* open dst printer handle */
                if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
                        PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
                        goto done;
 
-               got_hnd_dst = true;
-
-
                /* check for existing dst printer */
                if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
                                level, &info_dst))
@@ -2613,14 +2563,12 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
                SAFE_FREE(keylist);
 
                /* close printer handles here */
-               if (got_hnd_src) {
+               if (is_valid_policy_hnd(&hnd_src)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
-                       got_hnd_src = false;
                }
 
-               if (got_hnd_dst) {
+               if (is_valid_policy_hnd(&hnd_dst)) {
                        rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
-                       got_hnd_dst = false;
                }
 
        }
@@ -2632,10 +2580,10 @@ done:
        SAFE_FREE(url);
        SAFE_FREE(unc_name);
 
-       if (got_hnd_src)
+       if (is_valid_policy_hnd(&hnd_src))
                rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
 
-       if (got_hnd_dst)
+       if (is_valid_policy_hnd(&hnd_dst))
                rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
 
        if (cli_dst) {