Properly display popt errors. Also fix debug to be -d for consistency with other...
authorJim McDonough <jmcd@samba.org>
Tue, 21 Jan 2003 13:58:16 +0000 (13:58 +0000)
committerJim McDonough <jmcd@samba.org>
Tue, 21 Jan 2003 13:58:16 +0000 (13:58 +0000)
(This used to be commit 97133f7168852dc185dbf4492afcaf4b68180f65)

source3/rpcclient/cmd_spoolss.c
source3/rpcclient/rpcclient.c
source3/utils/net.c

index f7a34c2964da3b21ab5ec3482f5953ff7484dfa7..d5051741a75629e60a8d782924eac19be3053b0c 100644 (file)
@@ -1882,6 +1882,88 @@ done:
        return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
 }
 
+static NTSTATUS cmd_spoolss_setprinterdataex(struct cli_state *cli,
+                                           TALLOC_CTX *mem_ctx,
+                                           int argc, char **argv)
+{
+       WERROR result;
+       uint32 needed;
+       fstring servername, printername, user;
+       POLICY_HND pol;
+       BOOL opened_hnd = False;
+       PRINTER_INFO_CTR ctr;
+       PRINTER_INFO_0 info;
+       REGISTRY_VALUE value;
+
+       /* parse the command arguements */
+       if (argc != 5) {
+               printf ("Usage: %s <printer> <key> <value> <data>\n", argv[0]);
+               return NT_STATUS_OK;
+        }
+
+       slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
+       strupper (servername);
+       slprintf (printername, sizeof(fstring)-1, "%s\\%s", servername, argv[1]);
+       fstrcpy  (user, cli->user_name);
+
+       /* get a printer handle */
+       result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
+                                            MAXIMUM_ALLOWED_ACCESS, servername, 
+                                            user, &pol);
+       if (!W_ERROR_IS_OK(result))
+               goto done;
+
+       opened_hnd = True;
+
+       ctr.printers_0 = &info;
+
+        result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed,
+                                        &pol, 0, &ctr);
+
+        if (W_ERROR_V(result) == ERRinsufficientbuffer)
+                result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, 0, &ctr);
+
+        if (!W_ERROR_IS_OK(result))
+                goto done;
+               
+       printf("%s\n", timestring(True));
+       printf("\tchange_id (before set)\t:[0x%x]\n", info.change_id);
+
+       /* Set the printer data */
+       
+       fstrcpy(value.valuename, argv[3]);
+       value.type = REG_SZ;
+       value.size = strlen(argv[4]) + 1;
+       value.data_p = talloc_memdup(mem_ctx, argv[4], value.size);
+
+       result = cli_spoolss_setprinterdataex(cli, mem_ctx, &pol, 
+                                             argv[2], &value);
+               
+       if (!W_ERROR_IS_OK(result)) {
+               printf ("Unable to set [%s=%s]!\n", argv[3], argv[4]);
+               goto done;
+       }
+       printf("\tSetPrinterData succeeded [%s: %s]\n", argv[3], argv[4]);
+
+        result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed, &pol, 0, &ctr);
+
+        if (W_ERROR_V(result) == ERRinsufficientbuffer)
+                result = cli_spoolss_getprinter(cli, mem_ctx, needed, NULL, &pol, 0, &ctr);
+
+        if (!W_ERROR_IS_OK(result))
+                goto done;
+               
+       printf("%s\n", timestring(True));
+       printf("\tchange_id (after set)\t:[0x%x]\n", info.change_id);
+
+done:
+       /* cleanup */
+       if (opened_hnd)
+               cli_spoolss_close_printer(cli, mem_ctx, &pol);
+
+       return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+}
+
 static void display_job_info_1(JOB_INFO_1 *job)
 {
        fstring username = "", document = "", text_status = "";
@@ -2307,6 +2389,7 @@ struct cmd_set spoolss_commands[] = {
        { "enumforms",          cmd_spoolss_enum_forms,         PI_SPOOLSS, "Enumerate forms",                     "" },
        { "setprinter",         cmd_spoolss_setprinter,         PI_SPOOLSS, "Set printer comment",                 "" },
        { "setprinterdata",     cmd_spoolss_setprinterdata,     PI_SPOOLSS, "Set REG_SZ printer data",             "" },
+       { "setprinterdataex",   cmd_spoolss_setprinterdataex,   PI_SPOOLSS, "Set REG_SZ printer data inside key",  "" },
        { "rffpcnex",           cmd_spoolss_rffpcnex,           PI_SPOOLSS, "Rffpcnex test", "" },
 
        { NULL }
index 2609519dc487d7da91818632b1e62245f625d77f..191459a2c99630efb1749cd857ebfd87ac7b23d3 100644 (file)
@@ -720,10 +720,9 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
                get_username(username);
                
        nt_status = cli_full_connection(&cli, global_myname(), server, 
-                                       &server_ip, 0,
-                                       "IPC$", "IPC",  
-                                       username, domain,
-                                       password, 0, NULL);
+                                       &server_ip, 0, "IPC$", "IPC",  
+                                       username, domain, password, 
+                                       CLI_FULL_CONNECTION_USE_KERBEROS,NULL);
        
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0,("Cannot connect to server.  Error was %s\n", nt_errstr(nt_status)));
index 3228b56e270deeb16877ae6c2b6ee332799d874d..33195375f598efa709f1e9bf361e08b9a4fa19e5 100644 (file)
@@ -536,7 +536,7 @@ static struct functable net_func[] = {
                {"force",       'f', POPT_ARG_NONE,   &opt_force},
                {"timeout",     't', POPT_ARG_INT,    &opt_timeout},
                {"machine-pass",'P', POPT_ARG_NONE,   &opt_machine_pass},
-               {"debuglevel",  'D', POPT_ARG_STRING, &debuglevel},
+               {"debuglevel",  'd', POPT_ARG_STRING, &debuglevel},
                { 0, 0, 0, 0}
        };
 
@@ -570,7 +570,8 @@ static struct functable net_func[] = {
                        }
                        break;
                default:
-                       d_printf("\nInvalid option\n");
+                       d_printf("\nInvalid option %s: %s\n", 
+                                poptBadOption(pc, 0), poptStrerror(opt));
                        net_help(argc, argv);
                        exit(1);
                }