Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/rpcclient/cmd_spoolss.c

    r596 r745  
    2525#include "includes.h"
    2626#include "rpcclient.h"
    27 #include "../librpc/gen_ndr/cli_spoolss.h"
     27#include "../librpc/gen_ndr/ndr_spoolss_c.h"
     28#include "rpc_client/cli_spoolss.h"
     29#include "rpc_client/init_spoolss.h"
     30#include "registry/reg_objects.h"
     31#include "nt_printing.h"
     32#include "../libcli/security/display_sec.h"
     33#include "../libcli/security/security_descriptor.h"
     34#include "../libcli/registry/util_reg.h"
     35#include "libsmb/libsmb.h"
    2836
    2937#define RPCCLIENT_PRINTERNAME(_printername, _cli, _arg) \
     
    7280        int i=-1;
    7381
    74         DEBUG(107,("Getting architecture dependant directory\n"));
     82        DEBUG(107,("Getting architecture dependent directory\n"));
    7583        do {
    7684                i++;
     
    102110        WERROR          werror;
    103111        struct policy_handle    hnd;
    104 
    105         if (argc != 2) {
    106                 printf("Usage: %s <printername>\n", argv[0]);
     112        uint32_t access_mask = PRINTER_ALL_ACCESS;
     113        struct dcerpc_binding_handle *b = cli->binding_handle;
     114
     115        if (argc < 2) {
     116                printf("Usage: %s <printername> [access_mask]\n", argv[0]);
    107117                return WERR_OK;
    108118        }
    109119
    110         if (!cli)
    111             return WERR_GENERAL_FAILURE;
     120        if (argc >= 3) {
     121                sscanf(argv[2], "%x", &access_mask);
     122        }
    112123
    113124        /* Open the printer handle */
     
    115126        werror = rpccli_spoolss_openprinter_ex(cli, mem_ctx,
    116127                                               argv[1],
    117                                                PRINTER_ALL_ACCESS,
     128                                               access_mask,
    118129                                               &hnd);
    119130        if (W_ERROR_IS_OK(werror)) {
    120131                printf("Printer %s opened successfully\n", argv[1]);
    121                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, &werror);
     132                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werror);
    122133
    123134                if (!W_ERROR_IS_OK(werror)) {
     
    130141}
    131142
     143/****************************************************************************
     144****************************************************************************/
     145
     146static WERROR cmd_spoolss_open_printer(struct rpc_pipe_client *cli,
     147                                       TALLOC_CTX *mem_ctx,
     148                                       int argc, const char **argv)
     149{
     150        WERROR          werror;
     151        struct policy_handle    hnd;
     152        uint32_t access_mask = PRINTER_ALL_ACCESS;
     153        NTSTATUS status;
     154        struct spoolss_DevmodeContainer devmode_ctr;
     155        struct dcerpc_binding_handle *b = cli->binding_handle;
     156
     157        ZERO_STRUCT(devmode_ctr);
     158
     159        if (argc < 2) {
     160                printf("Usage: %s <printername> [access_mask]\n", argv[0]);
     161                return WERR_OK;
     162        }
     163
     164        if (argc >= 3) {
     165                sscanf(argv[2], "%x", &access_mask);
     166        }
     167
     168        /* Open the printer handle */
     169
     170        status = dcerpc_spoolss_OpenPrinter(b, mem_ctx,
     171                                            argv[1],
     172                                            NULL,
     173                                            devmode_ctr,
     174                                            access_mask,
     175                                            &hnd,
     176                                            &werror);
     177        if (!NT_STATUS_IS_OK(status)) {
     178                return ntstatus_to_werror(status);
     179        }
     180        if (W_ERROR_IS_OK(werror)) {
     181                printf("Printer %s opened successfully\n", argv[1]);
     182                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &werror);
     183
     184                if (!W_ERROR_IS_OK(werror)) {
     185                        printf("Error closing printer handle! (%s)\n",
     186                                get_dos_error_msg(werror));
     187                }
     188        }
     189
     190        return werror;
     191}
    132192
    133193/****************************************************************************
     
    467527        struct spoolss_DevmodeContainer devmode_ctr;
    468528        struct sec_desc_buf secdesc_ctr;
     529        struct dcerpc_binding_handle *b = cli->binding_handle;
    469530
    470531        if (argc == 1 || argc > 3) {
     
    509570        info_ctr.info.info2 = &info2;
    510571
    511         status = rpccli_spoolss_SetPrinter(cli, mem_ctx,
     572        status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
    512573                                           &pol,
    513574                                           &info_ctr,
     
    516577                                           0, /* command */
    517578                                           &result);
     579        if (!NT_STATUS_IS_OK(status)) {
     580                result = ntstatus_to_werror(status);
     581                goto done;
     582        }
    518583        if (W_ERROR_IS_OK(result))
    519584                printf("Success in setting comment.\n");
    520585
    521586 done:
    522         if (is_valid_policy_hnd(&pol))
    523                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     587        if (is_valid_policy_hnd(&pol)) {
     588                WERROR _result;
     589                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
     590        }
    524591
    525592        return result;
     
    544611        struct spoolss_DevmodeContainer devmode_ctr;
    545612        struct sec_desc_buf secdesc_ctr;
     613        struct dcerpc_binding_handle *b = cli->binding_handle;
    546614
    547615        ZERO_STRUCT(devmode_ctr);
     
    585653        info_ctr.info.info2 = &info2;
    586654
    587         status = rpccli_spoolss_SetPrinter(cli, mem_ctx,
     655        status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
    588656                                           &pol,
    589657                                           &info_ctr,
     
    592660                                           0, /* command */
    593661                                           &result);
     662        if (!NT_STATUS_IS_OK(status)) {
     663                result = ntstatus_to_werror(status);
     664                goto done;
     665        }
    594666        if (W_ERROR_IS_OK(result))
    595667                printf("Success in setting printername.\n");
    596668
    597669 done:
    598         if (is_valid_policy_hnd(&pol))
    599                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     670        if (is_valid_policy_hnd(&pol)) {
     671                WERROR _result;
     672                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
     673        }
    600674
    601675        return result;
     
    614688        const char      *printername;
    615689        union spoolss_PrinterInfo info;
     690        struct dcerpc_binding_handle *b = cli->binding_handle;
    616691
    617692        if (argc == 1 || argc > 3) {
     
    680755 done:
    681756        if (is_valid_policy_hnd(&pol)) {
    682                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     757                WERROR _result;
     758                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
    683759        }
    684760
     
    689765****************************************************************************/
    690766
    691 static void display_reg_value(struct regval_blob value)
     767static void display_reg_value(struct regval_blob *value)
    692768{
    693769        const char *text = NULL;
    694770        DATA_BLOB blob;
    695771
    696         switch(value.type) {
     772        switch(regval_type(value)) {
    697773        case REG_DWORD:
    698                 printf("%s: REG_DWORD: 0x%08x\n", value.valuename,
    699                        *((uint32_t *) value.data_p));
     774                printf("%s: REG_DWORD: 0x%08x\n", regval_name(value),
     775                       *((uint32_t *) regval_data_p(value)));
    700776                break;
    701777        case REG_SZ:
    702                 blob = data_blob_const(value.data_p, value.size);
     778                blob = data_blob_const(regval_data_p(value), regval_size(value));
    703779                pull_reg_sz(talloc_tos(), &blob, &text);
    704                 printf("%s: REG_SZ: %s\n", value.valuename, text ? text : "");
     780                printf("%s: REG_SZ: %s\n", regval_name(value), text ? text : "");
    705781                break;
    706782        case REG_BINARY: {
    707                 char *hex = hex_encode_talloc(NULL, value.data_p, value.size);
     783                char *hex = hex_encode_talloc(NULL, regval_data_p(value), regval_size(value));
    708784                size_t i, len;
    709                 printf("%s: REG_BINARY:", value.valuename);
     785                printf("%s: REG_BINARY:", regval_name(value));
    710786                len = strlen(hex);
    711787                for (i=0; i<len; i++) {
     
    725801                uint32_t i;
    726802                const char **values;
    727                 blob = data_blob_const(value.data_p, value.size);
     803                blob = data_blob_const(regval_data_p(value), regval_size(value));
    728804
    729805                if (!pull_reg_multi_sz(NULL, &blob, &values)) {
     
    732808                }
    733809
    734                 printf("%s: REG_MULTI_SZ: \n", value.valuename);
     810                printf("%s: REG_MULTI_SZ: \n", regval_name(value));
    735811                for (i=0; values[i] != NULL; i++) {
    736812                        d_printf("%s\n", values[i]);
     
    740816        }
    741817        default:
    742                 printf("%s: unknown type %d\n", value.valuename, value.type);
     818                printf("%s: unknown type %d\n", regval_name(value), regval_type(value));
    743819        }
    744820
     
    816892        uint8_t *data;
    817893        uint32_t needed;
     894        struct dcerpc_binding_handle *b = cli->binding_handle;
    818895
    819896        if (argc != 3) {
     
    858935
    859936 done:
    860         if (is_valid_policy_hnd(&pol))
    861                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     937        if (is_valid_policy_hnd(&pol)) {
     938                WERROR _result;
     939                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
     940        }
    862941
    863942        return result;
     
    881960        uint32_t offered = 0;
    882961        uint32_t needed;
     962        struct dcerpc_binding_handle *b = cli->binding_handle;
    883963
    884964        if (argc != 4) {
     
    915995        }
    916996
    917         status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx,
     997        status = dcerpc_spoolss_GetPrinterDataEx(b, mem_ctx,
    918998                                                 &pol,
    919999                                                 keyname,
     
    9241004                                                 &needed,
    9251005                                                 &result);
     1006        if (!NT_STATUS_IS_OK(status)) {
     1007                result = ntstatus_to_werror(status);
     1008                goto done;
     1009        }
    9261010        if (W_ERROR_EQUAL(result, WERR_MORE_DATA)) {
    9271011                offered = needed;
     
    9301014                        goto done;
    9311015                }
    932                 status = rpccli_spoolss_GetPrinterDataEx(cli, mem_ctx,
     1016                status = dcerpc_spoolss_GetPrinterDataEx(b, mem_ctx,
    9331017                                                         &pol,
    9341018                                                         keyname,
     
    9421026
    9431027        if (!NT_STATUS_IS_OK(status)) {
     1028                result = ntstatus_to_werror(status);
    9441029                goto done;
    9451030        }
     
    9541039
    9551040 done:
    956         if (is_valid_policy_hnd(&pol))
    957                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     1041        if (is_valid_policy_hnd(&pol)) {
     1042                WERROR _result;
     1043                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
     1044        }
    9581045
    9591046        return result;
     
    11871274        uint32_t server_major_version;
    11881275        uint32_t server_minor_version;
     1276        struct dcerpc_binding_handle *b = cli->binding_handle;
    11891277
    11901278        if ((argc == 1) || (argc > 3)) {
     
    12671355
    12681356        if (is_valid_policy_hnd(&pol)) {
    1269                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     1357                WERROR _result;
     1358                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
    12701359        }
    12711360
     
    14291518        union spoolss_DriverDirectoryInfo info;
    14301519        uint32_t needed;
     1520        struct dcerpc_binding_handle *b = cli->binding_handle;
    14311521
    14321522        if (argc > 2) {
     
    14431533        /* Get the directory.  Only use Info level 1 */
    14441534
    1445         status = rpccli_spoolss_GetPrinterDriverDirectory(cli, mem_ctx,
     1535        status = dcerpc_spoolss_GetPrinterDriverDirectory(b, mem_ctx,
    14461536                                                          cli->srv_name_slash,
    14471537                                                          env,
     
    14521542                                                          &needed,
    14531543                                                          &result);
     1544        if (!NT_STATUS_IS_OK(status)) {
     1545                return ntstatus_to_werror(status);
     1546        }
    14541547        if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) {
    14551548                offered = needed;
    14561549                buffer = data_blob_talloc_zero(mem_ctx, needed);
    14571550
    1458                 status = rpccli_spoolss_GetPrinterDriverDirectory(cli, mem_ctx,
     1551                status = dcerpc_spoolss_GetPrinterDriverDirectory(b, mem_ctx,
    14591552                                                                  cli->srv_name_slash,
    14601553                                                                  env,
     
    14651558                                                                  &needed,
    14661559                                                                  &result);
     1560                if (!NT_STATUS_IS_OK(status)) {
     1561                        return ntstatus_to_werror(status);
     1562                }
    14671563        }
    14681564
     
    16101706        const char              *arch;
    16111707        char                    *driver_args;
     1708        struct dcerpc_binding_handle *b = cli->binding_handle;
    16121709
    16131710        /* parse the command arguments */
     
    16281725        arch = cmd_spoolss_get_short_archi(argv[1]);
    16291726        if (!arch) {
    1630                 printf ("Error Unknown architechture [%s]\n", argv[1]);
     1727                printf ("Error Unknown architecture [%s]\n", argv[1]);
    16311728                return WERR_INVALID_PARAM;
    16321729        }
     
    16531750        info_ctr.info.info3     = &info3;
    16541751
    1655         status = rpccli_spoolss_AddPrinterDriver(cli, mem_ctx,
     1752        status = dcerpc_spoolss_AddPrinterDriver(b, mem_ctx,
    16561753                                                 cli->srv_name_slash,
    16571754                                                 &info_ctr,
     
    17411838        struct spoolss_DevmodeContainer devmode_ctr;
    17421839        struct sec_desc_buf secdesc_ctr;
     1840        struct dcerpc_binding_handle *b = cli->binding_handle;
    17431841
    17441842        ZERO_STRUCT(devmode_ctr);
     
    17831881        info_ctr.info.info2 = &info2;
    17841882
    1785         status = rpccli_spoolss_SetPrinter(cli, mem_ctx,
     1883        status = dcerpc_spoolss_SetPrinter(b, mem_ctx,
    17861884                                           &pol,
    17871885                                           &info_ctr,
     
    17901888                                           0, /* command */
    17911889                                           &result);
     1890        if (!NT_STATUS_IS_OK(status)) {
     1891                result = ntstatus_to_werror(status);
     1892                goto done;
     1893        }
    17921894        if (!W_ERROR_IS_OK(result)) {
    17931895                printf("SetPrinter call failed!\n");
    1794                 goto done;;
     1896                goto done;
    17951897        }
    17961898
     
    18001902        /* Cleanup */
    18011903
    1802         if (is_valid_policy_hnd(&pol))
    1803                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     1904        if (is_valid_policy_hnd(&pol)) {
     1905                WERROR _result;
     1906                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
     1907        }
    18041908
    18051909        return result;
     
    18161920        WERROR result, ret = WERR_UNKNOWN_PRINTER_DRIVER;
    18171921        NTSTATUS status;
     1922        struct dcerpc_binding_handle *b = cli->binding_handle;
    18181923
    18191924        int   i;
     
    18481953
    18491954                /* make the call to remove the driver */
    1850                 status = rpccli_spoolss_DeletePrinterDriverEx(cli, mem_ctx,
     1955                status = dcerpc_spoolss_DeletePrinterDriverEx(b, mem_ctx,
    18511956                                                              cli->srv_name_slash,
    18521957                                                              archi_table[i].long_archi,
     
    18551960                                                              archi_table[i].version,
    18561961                                                              &result);
    1857 
     1962                if (!NT_STATUS_IS_OK(status)) {
     1963                        return ntstatus_to_werror(status);
     1964                }
    18581965                if ( !W_ERROR_IS_OK(result) )
    18591966                {
     
    18851992        NTSTATUS status;
    18861993        int                     i;
     1994        struct dcerpc_binding_handle *b = cli->binding_handle;
    18871995
    18881996        /* parse the command arguments */
     
    18972005
    18982006                /* make the call to remove the driver */
    1899                 status = rpccli_spoolss_DeletePrinterDriver(cli, mem_ctx,
     2007                status = dcerpc_spoolss_DeletePrinterDriver(b, mem_ctx,
    19002008                                                            cli->srv_name_slash,
    19012009                                                            archi_table[i].long_archi,
     
    19032011                                                            &result);
    19042012                if (!NT_STATUS_IS_OK(status)) {
    1905                         if (W_ERROR_IS_OK(result)) {
    1906                                 result = ntstatus_to_werror(status);
    1907                         }
     2013                        result = ntstatus_to_werror(status);
     2014                        continue;
    19082015                }
    19092016                if ( !W_ERROR_IS_OK(result) ) {
    19102017                        if ( !W_ERROR_EQUAL(result, WERR_UNKNOWN_PRINTER_DRIVER) ) {
    1911                                 printf ("Failed to remove driver %s for arch [%s] - error 0x%x!\n",
     2018                                printf ("Failed to remove driver %s for arch [%s] - error %s!\n",
    19122019                                        argv[1], archi_table[i].long_archi,
    1913                                         W_ERROR_V(result));
     2020                                        win_errstr(result));
    19142021                        }
    19152022                } else {
     
    19362043        union spoolss_PrintProcessorDirectoryInfo info;
    19372044        uint32_t needed;
     2045        struct dcerpc_binding_handle *b = cli->binding_handle;
    19382046
    19392047        /* parse the command arguments */
     
    19472055        }
    19482056
    1949         status = rpccli_spoolss_GetPrintProcessorDirectory(cli, mem_ctx,
     2057        status = dcerpc_spoolss_GetPrintProcessorDirectory(b, mem_ctx,
    19502058                                                           cli->srv_name_slash,
    19512059                                                           environment,
     
    19562064                                                           &needed,
    19572065                                                           &result);
     2066        if (!NT_STATUS_IS_OK(status)) {
     2067                return ntstatus_to_werror(status);
     2068        }
    19582069        if (W_ERROR_EQUAL(result, WERR_INSUFFICIENT_BUFFER)) {
    19592070                offered = needed;
    19602071                buffer = data_blob_talloc_zero(mem_ctx, needed);
    19612072
    1962                 status = rpccli_spoolss_GetPrintProcessorDirectory(cli, mem_ctx,
     2073                status = dcerpc_spoolss_GetPrintProcessorDirectory(b, mem_ctx,
    19632074                                                                   cli->srv_name_slash,
    19642075                                                                   environment,
     
    19692080                                                                   &needed,
    19702081                                                                   &result);
     2082                if (!NT_STATUS_IS_OK(status)) {
     2083                        return ntstatus_to_werror(status);
     2084                }
    19712085        }
    19722086
     
    19922106        struct spoolss_AddFormInfo2 info2;
    19932107        uint32_t level = 1;
     2108        struct dcerpc_binding_handle *b = cli->binding_handle;
    19942109
    19952110        /* Parse the command arguments */
     
    20502165
    20512166                break;
     2167        default:
     2168                werror = WERR_INVALID_PARAM;
     2169                goto done;
    20522170        }
    20532171
     
    20552173
    20562174
    2057         status = rpccli_spoolss_AddForm(cli, mem_ctx,
     2175        status = dcerpc_spoolss_AddForm(b, mem_ctx,
    20582176                                        &handle,
    20592177                                        level,
    20602178                                        info,
    20612179                                        &werror);
    2062 
     2180        if (!NT_STATUS_IS_OK(status)) {
     2181                werror = ntstatus_to_werror(status);
     2182                goto done;
     2183        }
    20632184 done:
    2064         if (is_valid_policy_hnd(&handle))
    2065                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL);
     2185        if (is_valid_policy_hnd(&handle)) {
     2186                WERROR _result;
     2187                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result);
     2188        }
    20662189
    20672190        return werror;
     
    20802203        union spoolss_AddFormInfo info;
    20812204        struct spoolss_AddFormInfo1 info1;
     2205        struct dcerpc_binding_handle *b = cli->binding_handle;
    20822206
    20832207        /* Parse the command arguments */
     
    21142238        /* Set the form */
    21152239
    2116         status = rpccli_spoolss_SetForm(cli, mem_ctx,
     2240        status = dcerpc_spoolss_SetForm(b, mem_ctx,
    21172241                                        &handle,
    21182242                                        argv[2],
     
    21202244                                        info,
    21212245                                        &werror);
    2122 
     2246        if (!NT_STATUS_IS_OK(status)) {
     2247                werror = ntstatus_to_werror(status);
     2248                goto done;
     2249        }
    21232250 done:
    2124         if (is_valid_policy_hnd(&handle))
    2125                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL);
     2251        if (is_valid_policy_hnd(&handle)) {
     2252                WERROR _result;
     2253                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result);
     2254        }
    21262255
    21272256        return werror;
     
    21972326        uint32_t needed;
    21982327        uint32_t level = 1;
     2328        struct dcerpc_binding_handle *b = cli->binding_handle;
    21992329
    22002330        /* Parse the command arguments */
     
    22222352        /* Get the form */
    22232353
    2224         status = rpccli_spoolss_GetForm(cli, mem_ctx,
     2354        status = dcerpc_spoolss_GetForm(b, mem_ctx,
    22252355                                        &handle,
    22262356                                        argv[2],
     
    22312361                                        &needed,
    22322362                                        &werror);
     2363        if (!NT_STATUS_IS_OK(status)) {
     2364                werror = ntstatus_to_werror(status);
     2365                goto done;
     2366        }
    22332367        if (W_ERROR_EQUAL(werror, WERR_INSUFFICIENT_BUFFER)) {
    22342368                buffer = data_blob_talloc_zero(mem_ctx, needed);
    22352369                offered = needed;
    2236                 status = rpccli_spoolss_GetForm(cli, mem_ctx,
     2370                status = dcerpc_spoolss_GetForm(b, mem_ctx,
    22372371                                                &handle,
    22382372                                                argv[2],
     
    22432377                                                &needed,
    22442378                                                &werror);
    2245         }
    2246 
    2247         if (!NT_STATUS_IS_OK(status)) {
    2248                 return werror;
     2379                if (!NT_STATUS_IS_OK(status)) {
     2380                        werror = ntstatus_to_werror(status);
     2381                        goto done;
     2382                }
     2383        }
     2384
     2385        if (!W_ERROR_IS_OK(werror)) {
     2386                goto done;
    22492387        }
    22502388
     
    22592397
    22602398 done:
    2261         if (is_valid_policy_hnd(&handle))
    2262                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL);
     2399        if (is_valid_policy_hnd(&handle)) {
     2400                WERROR _result;
     2401                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result);
     2402        }
    22632403
    22642404        return werror;
     
    22762416        NTSTATUS status;
    22772417        const char *printername;
     2418        struct dcerpc_binding_handle *b = cli->binding_handle;
    22782419
    22792420        /* Parse the command arguments */
     
    22972438        /* Delete the form */
    22982439
    2299         status = rpccli_spoolss_DeleteForm(cli, mem_ctx,
     2440        status = dcerpc_spoolss_DeleteForm(b, mem_ctx,
    23002441                                           &handle,
    23012442                                           argv[2],
    23022443                                           &werror);
    23032444        if (!NT_STATUS_IS_OK(status)) {
    2304                 return ntstatus_to_werror(status);
     2445                werror = ntstatus_to_werror(status);
     2446                goto done;
    23052447        }
    23062448
    23072449 done:
    2308         if (is_valid_policy_hnd(&handle))
    2309                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL);
     2450        if (is_valid_policy_hnd(&handle)) {
     2451                WERROR _result;
     2452                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result);
     2453        }
    23102454
    23112455        return werror;
     
    23242468        uint32_t num_forms, level = 1, i;
    23252469        union spoolss_FormInfo *forms;
     2470        struct dcerpc_binding_handle *b = cli->binding_handle;
    23262471
    23272472        /* Parse the command arguments */
     
    23732518
    23742519 done:
    2375         if (is_valid_policy_hnd(&handle))
    2376                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL);
     2520        if (is_valid_policy_hnd(&handle)) {
     2521                WERROR _result;
     2522                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result);
     2523        }
    23772524
    23782525        return werror;
     
    23942541        union spoolss_PrinterData data;
    23952542        DATA_BLOB blob;
     2543        struct dcerpc_binding_handle *b = cli->binding_handle;
    23962544
    23972545        /* parse the command arguments */
     
    24002548                        " <value> <data>\n",
    24012549                        argv[0]);
    2402                 result = WERR_INVALID_PARAM;
    2403                 goto done;
     2550                return WERR_OK;
    24042551        }
    24052552
     
    25012648        }
    25022649
    2503         status = rpccli_spoolss_SetPrinterData(cli, mem_ctx,
     2650        status = dcerpc_spoolss_SetPrinterData(b, mem_ctx,
    25042651                                               &pol,
    25052652                                               argv[3], /* value_name */
     
    25082655                                               blob.length,
    25092656                                               &result);
     2657        if (!NT_STATUS_IS_OK(status)) {
     2658                printf ("Unable to set [%s=%s]!\n", argv[3], argv[4]);
     2659                result = ntstatus_to_werror(status);
     2660                goto done;
     2661        }
    25102662        if (!W_ERROR_IS_OK(result)) {
    25112663                printf ("Unable to set [%s=%s]!\n", argv[3], argv[4]);
     
    25292681        /* cleanup */
    25302682        if (is_valid_policy_hnd(&pol)) {
    2531                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &pol, NULL);
     2683                WERROR _result;
     2684                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &pol, &_result);
    25322685        }
    25332686
     
    25882741        struct policy_handle hnd;
    25892742        union spoolss_JobInfo *info;
     2743        struct dcerpc_binding_handle *b = cli->binding_handle;
    25902744
    25912745        if (argc < 2 || argc > 3) {
     
    26392793done:
    26402794        if (is_valid_policy_hnd(&hnd)) {
    2641                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     2795                WERROR _result;
     2796                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
    26422797        }
    26432798
     
    26582813        uint32_t level = 1;
    26592814        union spoolss_JobInfo info;
     2815        struct dcerpc_binding_handle *b = cli->binding_handle;
    26602816
    26612817        if (argc < 3 || argc > 4) {
     
    27152871done:
    27162872        if (is_valid_policy_hnd(&hnd)) {
    2717                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     2873                WERROR _result;
     2874                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
    27182875        }
    27192876
     
    27232880/****************************************************************************
    27242881****************************************************************************/
     2882
     2883static struct {
     2884        const char *name;
     2885        enum spoolss_JobControl val;
     2886} cmdvals[] = {
     2887        {"PAUSE", SPOOLSS_JOB_CONTROL_PAUSE},
     2888        {"RESUME", SPOOLSS_JOB_CONTROL_RESUME},
     2889        {"CANCEL", SPOOLSS_JOB_CONTROL_CANCEL},
     2890        {"RESTART", SPOOLSS_JOB_CONTROL_RESTART},
     2891        {"DELETE", SPOOLSS_JOB_CONTROL_DELETE},
     2892        {"SEND_TO_PRINTER", SPOOLSS_JOB_CONTROL_SEND_TO_PRINTER},
     2893        {"EJECTED", SPOOLSS_JOB_CONTROL_LAST_PAGE_EJECTED},
     2894        {"RETAIN", SPOOLSS_JOB_CONTROL_RETAIN},
     2895        {"RELEASE", SPOOLSS_JOB_CONTROL_RELEASE}
     2896};
     2897
     2898static enum spoolss_JobControl parse_setjob_command(const char *cmd)
     2899{
     2900        int i;
     2901
     2902        for (i = 0; i < sizeof(cmdvals)/sizeof(cmdvals[0]); i++) {
     2903                if (strequal(cmdvals[i].name, cmd)) {
     2904                        return cmdvals[i].val;
     2905                }
     2906        }
     2907        return (enum spoolss_JobControl)atoi(cmd);
     2908}
    27252909
    27262910static WERROR cmd_spoolss_set_job(struct rpc_pipe_client *cli,
     
    27342918        uint32_t job_id;
    27352919        enum spoolss_JobControl command;
     2920        struct dcerpc_binding_handle *b = cli->binding_handle;
    27362921
    27372922        if (argc != 4) {
    27382923                printf("Usage: %s printername job_id command\n", argv[0]);
     2924                printf("command = [PAUSE|RESUME|CANCEL|RESTART|DELETE|"
     2925                        "SEND_TO_PRINTER|EJECTED|RETAIN|RELEASE]\n");
    27392926                return WERR_OK;
    27402927        }
    27412928
    27422929        job_id = atoi(argv[2]);
    2743         command = atoi(argv[3]);
     2930        command = parse_setjob_command(argv[3]);
    27442931
    27452932        /* Open printer handle */
     
    27572944        /* Set Job */
    27582945
    2759         status = rpccli_spoolss_SetJob(cli, mem_ctx,
     2946        status = dcerpc_spoolss_SetJob(b, mem_ctx,
    27602947                                       &hnd,
    27612948                                       job_id,
     
    27632950                                       command,
    27642951                                       &result);
    2765 
     2952        if (!NT_STATUS_IS_OK(status)) {
     2953                result = ntstatus_to_werror(status);
     2954                goto done;
     2955        }
    27662956        if (!W_ERROR_IS_OK(result)) {
    27672957                goto done;
     
    27702960done:
    27712961        if (is_valid_policy_hnd(&hnd)) {
    2772                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     2962                WERROR _result;
     2963                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
    27732964        }
    27742965
     
    27852976        WERROR result;
    27862977        NTSTATUS status;
    2787         uint32_t i = 0;
    27882978        const char *printername;
    27892979        struct policy_handle hnd;
    2790         uint32_t value_offered = 0;
    2791         const char *value_name = NULL;
    27922980        uint32_t value_needed;
    27932981        enum winreg_Type type;
    2794         uint8_t *data = NULL;
    2795         uint32_t data_offered = 0;
    27962982        uint32_t data_needed;
     2983        struct dcerpc_binding_handle *b = cli->binding_handle;
     2984        struct spoolss_EnumPrinterData r;
    27972985
    27982986        if (argc != 2) {
     
    28153003        /* Enumerate data */
    28163004
    2817         status = rpccli_spoolss_EnumPrinterData(cli, mem_ctx,
    2818                                                 &hnd,
    2819                                                 i,
    2820                                                 value_name,
    2821                                                 value_offered,
    2822                                                 &value_needed,
    2823                                                 &type,
    2824                                                 data,
    2825                                                 data_offered,
    2826                                                 &data_needed,
    2827                                                 &result);
    2828 
    2829         data_offered    = data_needed;
    2830         value_offered   = value_needed;
    2831         data            = talloc_zero_array(mem_ctx, uint8_t, data_needed);
    2832         value_name      = talloc_zero_array(mem_ctx, char, value_needed);
    2833 
    2834         while (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
    2835 
    2836                 status = rpccli_spoolss_EnumPrinterData(cli, mem_ctx,
    2837                                                         &hnd,
    2838                                                         i++,
    2839                                                         value_name,
    2840                                                         value_offered,
    2841                                                         &value_needed,
    2842                                                         &type,
    2843                                                         data,
    2844                                                         data_offered,
    2845                                                         &data_needed,
    2846                                                         &result);
    2847                 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(result)) {
    2848                         struct regval_blob v;
    2849                         fstrcpy(v.valuename, value_name);
    2850                         v.type = type;
    2851                         v.size = data_offered;
    2852                         v.data_p = data;
     3005        r.in.handle = &hnd;
     3006        r.in.enum_index = 0;
     3007        r.in.value_offered = 0;
     3008        r.in.data_offered = 0;
     3009        r.out.value_name = NULL;
     3010        r.out.value_needed = &value_needed;
     3011        r.out.type = &type;
     3012        r.out.data = NULL;
     3013        r.out.data_needed = &data_needed;
     3014
     3015        status = dcerpc_spoolss_EnumPrinterData_r(b, mem_ctx, &r);
     3016        if (!NT_STATUS_IS_OK(status)) {
     3017                result = ntstatus_to_werror(status);
     3018                goto done;
     3019        }
     3020
     3021        if (!W_ERROR_IS_OK(r.out.result)) {
     3022                result = r.out.result;
     3023                goto done;
     3024        }
     3025
     3026        r.in.data_offered       = *r.out.data_needed;
     3027        r.in.value_offered      = *r.out.value_needed;
     3028        r.out.data              = talloc_zero_array(mem_ctx, uint8_t, r.in.data_offered);
     3029        r.out.value_name        = talloc_zero_array(mem_ctx, char, r.in.value_offered);
     3030
     3031        do {
     3032
     3033                status = dcerpc_spoolss_EnumPrinterData_r(b, mem_ctx, &r);
     3034                if (!NT_STATUS_IS_OK(status)) {
     3035                        result = ntstatus_to_werror(status);
     3036                        goto done;
     3037                }
     3038
     3039                if (W_ERROR_EQUAL(r.out.result, WERR_NO_MORE_ITEMS)) {
     3040                        result = WERR_OK;
     3041                        break;
     3042                }
     3043
     3044                r.in.enum_index++;
     3045
     3046                {
     3047                        struct regval_blob *v;
     3048
     3049                        v = regval_compose(talloc_tos(),
     3050                                           r.out.value_name,
     3051                                           *r.out.type,
     3052                                           r.out.data,
     3053                                           r.in.data_offered);
     3054                        if (v == NULL) {
     3055                                result = WERR_NOMEM;
     3056                                goto done;
     3057                        }
     3058
    28533059                        display_reg_value(v);
    2854                 }
    2855         }
    2856 
    2857         if (W_ERROR_V(result) == ERRnomoreitems) {
    2858                 result = W_ERROR(ERRsuccess);
    2859         }
     3060                        talloc_free(v);
     3061                }
     3062
     3063        } while (W_ERROR_IS_OK(r.out.result));
    28603064
    28613065done:
    28623066        if (is_valid_policy_hnd(&hnd)) {
    2863                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     3067                WERROR _result;
     3068                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
    28643069        }
    28653070
     
    28803085        uint32_t count;
    28813086        struct spoolss_PrinterEnumValues *info;
     3087        struct dcerpc_binding_handle *b = cli->binding_handle;
    28823088
    28833089        if (argc != 3) {
     
    29193125 done:
    29203126        if (is_valid_policy_hnd(&hnd)) {
    2921                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     3127                WERROR _result;
     3128                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
    29223129        }
    29233130
     
    29393146        int i;
    29403147        uint32_t offered = 0;
     3148        struct dcerpc_binding_handle *b = cli->binding_handle;
    29413149
    29423150        if (argc < 2 || argc > 4) {
     
    29863194
    29873195        if (is_valid_policy_hnd(&hnd)) {
    2988                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     3196                WERROR _result;
     3197                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
    29893198        }
    29903199
     
    30053214        NTSTATUS status;
    30063215        struct spoolss_NotifyOption option;
     3216        struct dcerpc_binding_handle *b = cli->binding_handle;
    30073217
    30083218        if (argc != 2) {
     
    30623272        /* Send rffpcnex */
    30633273
    3064         status = rpccli_spoolss_RemoteFindFirstPrinterChangeNotifyEx(cli, mem_ctx,
     3274        status = dcerpc_spoolss_RemoteFindFirstPrinterChangeNotifyEx(b, mem_ctx,
    30653275                                                                     &hnd,
    30663276                                                                     0,
     
    30703280                                                                     &option,
    30713281                                                                     &result);
     3282        if (!NT_STATUS_IS_OK(status)) {
     3283                result = ntstatus_to_werror(status);
     3284                goto done;
     3285        }
    30723286        if (!W_ERROR_IS_OK(result)) {
    30733287                printf("Error rffpcnex %s\n", argv[1]);
     
    30763290
    30773291done:
    3078         if (is_valid_policy_hnd(&hnd))
    3079                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
     3292        if (is_valid_policy_hnd(&hnd)) {
     3293                WERROR _result;
     3294                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &hnd, &_result);
     3295        }
    30803296
    30813297        return result;
     
    31323348        WERROR werror;
    31333349        TALLOC_CTX *mem_ctx = talloc_init("compare_printer_secdesc");
    3134         SEC_DESC *sd1, *sd2;
     3350        struct security_descriptor *sd1, *sd2;
    31353351        bool result = true;
    31363352
     
    32213437                                        get_cmdline_auth_info_password(rpcclient_auth_info),
    32223438                                        get_cmdline_auth_info_use_kerberos(rpcclient_auth_info) ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
    3223                                         get_cmdline_auth_info_signing_state(rpcclient_auth_info), NULL);
     3439                                        get_cmdline_auth_info_signing_state(rpcclient_auth_info));
    32243440
    32253441        if ( !NT_STATUS_IS_OK(nt_status) )
     
    32743490
    32753491        printf("Closing printers...");
    3276         rpccli_spoolss_ClosePrinter( cli, mem_ctx, &hPrinter1, NULL );
    3277         rpccli_spoolss_ClosePrinter( cli2, mem_ctx, &hPrinter2, NULL );
     3492        {
     3493                WERROR _result;
     3494                dcerpc_spoolss_ClosePrinter(cli->binding_handle, mem_ctx, &hPrinter1, &_result);
     3495                dcerpc_spoolss_ClosePrinter(cli2->binding_handle, mem_ctx, &hPrinter2, &_result);
     3496        }
    32783497        printf("ok\n");
    32793498
     
    34633682        const char *printername;
    34643683        struct spoolss_DevmodeContainer devmode_ctr;
     3684        struct dcerpc_binding_handle *b = cli->binding_handle;
    34653685
    34663686        RPCCLIENT_PRINTERNAME(printername, cli, argv[1]);
     
    34763696        ZERO_STRUCT(devmode_ctr);
    34773697
    3478         status = rpccli_spoolss_CreatePrinterIC(cli, mem_ctx,
     3698        status = dcerpc_spoolss_CreatePrinterIC(b, mem_ctx,
    34793699                                                &handle,
    34803700                                                &gdi_handle,
    34813701                                                &devmode_ctr,
    34823702                                                &result);
     3703        if (!NT_STATUS_IS_OK(status)) {
     3704                result = ntstatus_to_werror(status);
     3705                goto done;
     3706        }
    34833707        if (!W_ERROR_IS_OK(result)) {
    34843708                goto done;
     
    34873711 done:
    34883712        if (is_valid_policy_hnd(&gdi_handle)) {
    3489                 rpccli_spoolss_DeletePrinterIC(cli, mem_ctx, &gdi_handle, NULL);
     3713                WERROR _result;
     3714                dcerpc_spoolss_DeletePrinterIC(b, mem_ctx, &gdi_handle, &_result);
    34903715        }
    34913716        if (is_valid_policy_hnd(&handle)) {
    3492                 rpccli_spoolss_ClosePrinter(cli, mem_ctx, &handle, NULL);
     3717                WERROR _result;
     3718                dcerpc_spoolss_ClosePrinter(b, mem_ctx, &handle, &_result);
    34933719        }
    34943720
     
    35193745        { "getdriverdir",       RPC_RTYPE_WERROR, NULL, cmd_spoolss_getdriverdir,       &ndr_table_spoolss.syntax_id, NULL, "Get print driver upload directory",   "" },
    35203746        { "getprinter",         RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprinter,         &ndr_table_spoolss.syntax_id, NULL, "Get printer info",                    "" },
    3521         { "openprinter",        RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer_ex,    &ndr_table_spoolss.syntax_id, NULL, "Open printer handle",                 "" },
     3747        { "openprinter",        RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer,       &ndr_table_spoolss.syntax_id, NULL, "Open printer handle",                 "" },
     3748        { "openprinter_ex",     RPC_RTYPE_WERROR, NULL, cmd_spoolss_open_printer_ex,    &ndr_table_spoolss.syntax_id, NULL, "Open printer handle",                 "" },
    35223749        { "setdriver",          RPC_RTYPE_WERROR, NULL, cmd_spoolss_setdriver,          &ndr_table_spoolss.syntax_id, NULL, "Set printer driver",                  "" },
    35233750        { "getprintprocdir",    RPC_RTYPE_WERROR, NULL, cmd_spoolss_getprintprocdir,    &ndr_table_spoolss.syntax_id, NULL, "Get print processor directory",       "" },
Note: See TracChangeset for help on using the changeset viewer.