s3-rpcclient: add set_job command.
[amitay/samba.git] / source3 / rpcclient / cmd_spoolss.c
index 3dc88af7f152b253c6c47b8387c0d81270380a3f..4bcaa291e186b9d5d881ebbc66841cb108fb4f5d 100644 (file)
@@ -6,6 +6,7 @@
    Copyright (C) Tim Potter                        2000
    Copyright (C) Andrew Tridgell              1992-1999
    Copyright (C) Luke Kenneth Casson Leighton 1996-1999
+   Copyright (C) Guenther Deschner                 2009
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -104,7 +105,7 @@ static WERROR cmd_spoolss_open_printer_ex(struct rpc_pipe_client *cli,
                                             int argc, const char **argv)
 {
        WERROR          werror;
-       POLICY_HND      hnd;
+       struct policy_handle    hnd;
 
        if (argc != 2) {
                printf("Usage: %s <printername>\n", argv[0]);
@@ -256,9 +257,10 @@ static WERROR cmd_spoolss_enum_printers(struct rpc_pipe_client *cli,
        union spoolss_PrinterInfo *info;
        uint32_t                i, count;
        const char *name;
+       uint32_t flags = PRINTER_ENUM_LOCAL;
 
-       if (argc > 3) {
-               printf("Usage: %s [level] [name]\n", argv[0]);
+       if (argc > 4) {
+               printf("Usage: %s [level] [name] [flags]\n", argv[0]);
                return WERR_OK;
        }
 
@@ -266,14 +268,18 @@ static WERROR cmd_spoolss_enum_printers(struct rpc_pipe_client *cli,
                level = atoi(argv[1]);
        }
 
-       if (argc == 3) {
+       if (argc >= 3) {
                name = argv[2];
        } else {
                name = cli->srv_name_slash;
        }
 
+       if (argc == 4) {
+               flags = atoi(argv[3]);
+       }
+
        result = rpccli_spoolss_enumprinters(cli, mem_ctx,
-                                            PRINTER_ENUM_LOCAL,
+                                            flags,
                                             name,
                                             level,
                                             0,
@@ -413,10 +419,10 @@ static WERROR cmd_spoolss_setprinter(struct rpc_pipe_client *cli,
                                        TALLOC_CTX *mem_ctx,
                                        int argc, const char **argv)
 {
-       POLICY_HND      pol;
+       struct policy_handle pol;
        WERROR          result;
        NTSTATUS        status;
-       uint32          info_level = 2;
+       uint32_t        info_level = 2;
        union spoolss_PrinterInfo info;
        struct spoolss_SetPrinterInfoCtr info_ctr;
        const char      *printername, *comment = NULL;
@@ -489,10 +495,10 @@ static WERROR cmd_spoolss_setprintername(struct rpc_pipe_client *cli,
                                        TALLOC_CTX *mem_ctx,
                                        int argc, const char **argv)
 {
-       POLICY_HND      pol;
+       struct policy_handle pol;
        WERROR          result;
        NTSTATUS        status;
-       uint32          info_level = 2;
+       uint32_t        info_level = 2;
        union spoolss_PrinterInfo info;
        const char      *printername,
                        *new_printername = NULL;
@@ -565,7 +571,7 @@ static WERROR cmd_spoolss_getprinter(struct rpc_pipe_client *cli,
                                        TALLOC_CTX *mem_ctx,
                                        int argc, const char **argv)
 {
-       POLICY_HND      pol;
+       struct policy_handle pol;
        WERROR          result;
        uint32_t        level = 1;
        const char      *printername;
@@ -643,7 +649,7 @@ static void display_reg_value(REGISTRY_VALUE value)
        switch(value.type) {
        case REG_DWORD:
                printf("%s: REG_DWORD: 0x%08x\n", value.valuename,
-                      *((uint32 *) value.data_p));
+                      *((uint32_t *) value.data_p));
                break;
        case REG_SZ:
                rpcstr_pull_talloc(talloc_tos(),
@@ -672,7 +678,7 @@ static void display_reg_value(REGISTRY_VALUE value)
                break;
        }
        case REG_MULTI_SZ: {
-               uint32 i, num_values;
+               uint32_t i, num_values;
                char **values;
 
                if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL, value.data_p,
@@ -750,7 +756,7 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli,
                                           TALLOC_CTX *mem_ctx,
                                           int argc, const char **argv)
 {
-       POLICY_HND      pol;
+       struct policy_handle pol;
        WERROR          result;
        fstring         printername;
        const char *valuename;
@@ -810,7 +816,7 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli,
                                             TALLOC_CTX *mem_ctx,
                                             int argc, const char **argv)
 {
-       POLICY_HND      pol;
+       struct policy_handle pol;
        WERROR          result;
        NTSTATUS        status;
        fstring         printername;
@@ -970,7 +976,7 @@ static WERROR cmd_spoolss_getdriver(struct rpc_pipe_client *cli,
                                    TALLOC_CTX *mem_ctx,
                                    int argc, const char **argv)
 {
-       POLICY_HND      pol;
+       struct policy_handle pol;
        WERROR          werror;
        uint32_t        level = 3;
        const char      *printername;
@@ -1337,7 +1343,7 @@ static WERROR cmd_spoolss_addprinterdriver(struct rpc_pipe_client *cli,
 {
        WERROR result;
        NTSTATUS status;
-       uint32                  level = 3;
+       uint32_t                  level = 3;
        struct spoolss_AddDriverInfoCtr info_ctr;
        struct spoolss_AddDriverInfo3 info3;
        const char              *arch;
@@ -1463,10 +1469,10 @@ static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,
                                       TALLOC_CTX *mem_ctx,
                                       int argc, const char **argv)
 {
-       POLICY_HND              pol;
+       struct policy_handle    pol;
        WERROR                  result;
        NTSTATUS                status;
-       uint32                  level = 2;
+       uint32_t                level = 2;
        const char              *printername;
        union spoolss_PrinterInfo info;
        struct spoolss_SetPrinterInfoCtr info_ctr;
@@ -1712,7 +1718,7 @@ static WERROR cmd_spoolss_getprintprocdir(struct rpc_pipe_client *cli,
 static WERROR cmd_spoolss_addform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                    int argc, const char **argv)
 {
-       POLICY_HND handle;
+       struct policy_handle handle;
        WERROR werror;
        NTSTATUS status;
        const char *printername;
@@ -1802,7 +1808,7 @@ static WERROR cmd_spoolss_addform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
 static WERROR cmd_spoolss_setform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                    int argc, const char **argv)
 {
-       POLICY_HND handle;
+       struct policy_handle handle;
        WERROR werror;
        NTSTATUS status;
        const char *printername;
@@ -1916,7 +1922,7 @@ static void display_form_info2(struct spoolss_FormInfo2 *r)
 static WERROR cmd_spoolss_getform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx,
                                    int argc, const char **argv)
 {
-       POLICY_HND handle;
+       struct policy_handle handle;
        WERROR werror;
        NTSTATUS status;
        const char *printername;
@@ -2000,7 +2006,7 @@ static WERROR cmd_spoolss_deleteform(struct rpc_pipe_client *cli,
                                       TALLOC_CTX *mem_ctx, int argc,
                                       const char **argv)
 {
-       POLICY_HND handle;
+       struct policy_handle handle;
        WERROR werror;
        NTSTATUS status;
        const char *printername;
@@ -2047,10 +2053,10 @@ static WERROR cmd_spoolss_enum_forms(struct rpc_pipe_client *cli,
                                       TALLOC_CTX *mem_ctx, int argc,
                                       const char **argv)
 {
-       POLICY_HND handle;
+       struct policy_handle handle;
        WERROR werror;
        const char *printername;
-       uint32 num_forms, level = 1, i;
+       uint32_t num_forms, level = 1, i;
        union spoolss_FormInfo *forms;
 
        /* Parse the command arguments */
@@ -2117,7 +2123,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
        WERROR result;
        NTSTATUS status;
        const char *printername;
-       POLICY_HND pol;
+       struct policy_handle pol;
        union spoolss_PrinterInfo info;
        enum winreg_Type type;
        union spoolss_PrinterData data;
@@ -2308,7 +2314,7 @@ static WERROR cmd_spoolss_enum_jobs(struct rpc_pipe_client *cli,
        WERROR result;
        uint32_t level = 1, count, i;
        const char *printername;
-       POLICY_HND hnd;
+       struct policy_handle hnd;
        union spoolss_JobInfo *info;
 
        if (argc < 2 || argc > 3) {
@@ -2443,6 +2449,60 @@ done:
        return result;
 }
 
+/****************************************************************************
+****************************************************************************/
+
+static WERROR cmd_spoolss_set_job(struct rpc_pipe_client *cli,
+                                 TALLOC_CTX *mem_ctx, int argc,
+                                 const char **argv)
+{
+       WERROR result;
+       NTSTATUS status;
+       const char *printername;
+       struct policy_handle hnd;
+       uint32_t job_id;
+       enum spoolss_JobControl command;
+
+       if (argc != 4) {
+               printf("Usage: %s printername job_id command\n", argv[0]);
+               return WERR_OK;
+       }
+
+       job_id = atoi(argv[2]);
+       command = atoi(argv[3]);
+
+       /* Open printer handle */
+
+       RPCCLIENT_PRINTERNAME(printername, cli, argv[1]);
+
+       result = rpccli_spoolss_openprinter_ex(cli, mem_ctx,
+                                              printername,
+                                              SEC_FLAG_MAXIMUM_ALLOWED,
+                                              &hnd);
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+       /* Set Job */
+
+       status = rpccli_spoolss_SetJob(cli, mem_ctx,
+                                      &hnd,
+                                      job_id,
+                                      NULL,
+                                      command,
+                                      &result);
+
+       if (!W_ERROR_IS_OK(result)) {
+               goto done;
+       }
+
+done:
+       if (is_valid_policy_hnd(&hnd)) {
+               rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
+       }
+
+       return result;
+}
 
 /****************************************************************************
 ****************************************************************************/
@@ -2455,7 +2515,7 @@ static WERROR cmd_spoolss_enum_data(struct rpc_pipe_client *cli,
        NTSTATUS status;
        uint32_t i = 0;
        const char *printername;
-       POLICY_HND hnd;
+       struct policy_handle hnd;
        uint32_t value_offered = 0;
        const char *value_name = NULL;
        uint32_t value_needed;
@@ -2543,9 +2603,9 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli,
                                          const char **argv)
 {
        WERROR result;
-       uint32 i;
+       uint32_t i;
        const char *printername;
-       POLICY_HND hnd;
+       struct policy_handle hnd;
        uint32_t count;
        struct spoolss_PrinterEnumValues *info;
 
@@ -2602,7 +2662,7 @@ static WERROR cmd_spoolss_enum_printerkey(struct rpc_pipe_client *cli,
        WERROR result;
        const char *printername;
        const char *keyname = NULL;
-       POLICY_HND hnd;
+       struct policy_handle hnd;
        const char **key_buffer = NULL;
        int i;
 
@@ -2663,7 +2723,7 @@ static WERROR cmd_spoolss_rffpcnex(struct rpc_pipe_client *cli,
 {
        const char *printername;
        const char *clientname;
-       POLICY_HND hnd;
+       struct policy_handle hnd;
        WERROR result;
        NTSTATUS status;
        struct spoolss_NotifyOption option;
@@ -2705,7 +2765,7 @@ static WERROR cmd_spoolss_rffpcnex(struct rpc_pipe_client *cli,
                result = WERR_NOMEM;
                goto done;
        }
-       option.types[0].fields[0].field = PRINTER_NOTIFY_SERVER_NAME;
+       option.types[0].fields[0].field = PRINTER_NOTIFY_FIELD_SERVER_NAME;
 
        option.types[1].type = JOB_NOTIFY_TYPE;
        option.types[1].count = 1;
@@ -2714,7 +2774,7 @@ static WERROR cmd_spoolss_rffpcnex(struct rpc_pipe_client *cli,
                result = WERR_NOMEM;
                goto done;
        }
-       option.types[1].fields[0].field = JOB_NOTIFY_PRINTER_NAME;
+       option.types[1].fields[0].field = JOB_NOTIFY_FIELD_PRINTER_NAME;
 
        clientname = talloc_asprintf(mem_ctx, "\\\\%s", global_myname());
        if (!clientname) {
@@ -2747,8 +2807,8 @@ done:
 /****************************************************************************
 ****************************************************************************/
 
-static bool compare_printer( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
-                             struct rpc_pipe_client *cli2, POLICY_HND *hnd2 )
+static bool compare_printer( struct rpc_pipe_client *cli1, struct policy_handle *hnd1,
+                             struct rpc_pipe_client *cli2, struct policy_handle *hnd2 )
 {
        union spoolss_PrinterInfo info1, info2;
        WERROR werror;
@@ -2763,7 +2823,7 @@ static bool compare_printer( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
        if ( !W_ERROR_IS_OK(werror) ) {
                printf("failed (%s)\n", win_errstr(werror));
                talloc_destroy(mem_ctx);
-               return False;
+               return false;
        }
        printf("ok\n");
 
@@ -2776,26 +2836,26 @@ static bool compare_printer( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
        if ( !W_ERROR_IS_OK(werror) ) {
                printf("failed (%s)\n", win_errstr(werror));
                talloc_destroy(mem_ctx);
-               return False;
+               return false;
        }
        printf("ok\n");
 
        talloc_destroy(mem_ctx);
 
-       return True;
+       return true;
 }
 
 /****************************************************************************
 ****************************************************************************/
 
-static bool compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
-                                     struct rpc_pipe_client *cli2, POLICY_HND *hnd2 )
+static bool compare_printer_secdesc( struct rpc_pipe_client *cli1, struct policy_handle *hnd1,
+                                     struct rpc_pipe_client *cli2, struct policy_handle *hnd2 )
 {
        union spoolss_PrinterInfo info1, info2;
        WERROR werror;
        TALLOC_CTX *mem_ctx = talloc_init("compare_printer_secdesc");
        SEC_DESC *sd1, *sd2;
-       bool result = True;
+       bool result = true;
 
 
        printf("Retrieving printer security for %s...", cli1->desthost);
@@ -2806,7 +2866,7 @@ static bool compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *h
                                           &info1);
        if ( !W_ERROR_IS_OK(werror) ) {
                printf("failed (%s)\n", win_errstr(werror));
-               result = False;
+               result = false;
                goto done;
        }
        printf("ok\n");
@@ -2819,7 +2879,7 @@ static bool compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *h
                                           &info2);
        if ( !W_ERROR_IS_OK(werror) ) {
                printf("failed (%s)\n", win_errstr(werror));
-               result = False;
+               result = false;
                goto done;
        }
        printf("ok\n");
@@ -2832,13 +2892,13 @@ static bool compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *h
 
        if ( (sd1 != sd2) && ( !sd1 || !sd2 ) ) {
                printf("NULL secdesc!\n");
-               result = False;
+               result = false;
                goto done;
        }
 
        if (!sec_desc_equal( sd1, sd2 ) ) {
                printf("Security Descriptors *not* equal!\n");
-               result = False;
+               result = false;
                goto done;
        }
 
@@ -2863,7 +2923,7 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
        char *printername_path = NULL;
        struct cli_state *cli_server2 = NULL;
        struct rpc_pipe_client *cli2 = NULL;
-       POLICY_HND hPrinter1, hPrinter2;
+       struct policy_handle hPrinter1, hPrinter2;
        NTSTATUS nt_status;
        WERROR werror;
 
@@ -3130,6 +3190,7 @@ struct cmd_set spoolss_commands[] = {
        { "enumkey",            RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_printerkey,    &ndr_table_spoolss.syntax_id, NULL, "Enumerate printer keys",              "" },
        { "enumjobs",           RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_jobs,          &ndr_table_spoolss.syntax_id, NULL, "Enumerate print jobs",                "" },
        { "getjob",             RPC_RTYPE_WERROR, NULL, cmd_spoolss_get_job,            &ndr_table_spoolss.syntax_id, NULL, "Get print job",                       "" },
+       { "setjob",             RPC_RTYPE_WERROR, NULL, cmd_spoolss_set_job,            &ndr_table_spoolss.syntax_id, NULL, "Set print job",                       "" },
        { "enumports",          RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_ports,         &ndr_table_spoolss.syntax_id, NULL, "Enumerate printer ports",             "" },
        { "enumdrivers",        RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_drivers,       &ndr_table_spoolss.syntax_id, NULL, "Enumerate installed printer drivers", "" },
        { "enumprinters",       RPC_RTYPE_WERROR, NULL, cmd_spoolss_enum_printers,      &ndr_table_spoolss.syntax_id, NULL, "Enumerate printers",                  "" },