Merge commit 'origin/v3-2-test' into v3-2-stable
[ira/wip.git] / source3 / rpcclient / cmd_spoolss.c
index afca3e747f2728531ebbb0d0db1ffb1a28932945..e923302f4e8c3abc1d0a97edbc8c81408522e855 100644 (file)
@@ -9,7 +9,7 @@
  
    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
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -276,8 +275,6 @@ static void display_print_info_2(PRINTER_INFO_2 *i2)
 
 static void display_print_info_3(PRINTER_INFO_3 *i3)
 {
-       printf("\tflags:[0x%x]\n", i3->flags);
-
        display_sec_desc(i3->secdesc);
 
        printf("\n");
@@ -473,7 +470,7 @@ static WERROR cmd_spoolss_setprinter(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          result;
        uint32          info_level = 2;
-       BOOL            opened_hnd = False;
+       bool            opened_hnd = False;
        PRINTER_INFO_CTR ctr;
        fstring         printername,
                        servername,
@@ -539,7 +536,7 @@ static WERROR cmd_spoolss_setprintername(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          result;
        uint32          info_level = 2;
-       BOOL            opened_hnd = False;
+       bool            opened_hnd = False;
        PRINTER_INFO_CTR ctr;
        fstring         printername,
                        servername,
@@ -604,7 +601,7 @@ static WERROR cmd_spoolss_getprinter(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          result;
        uint32          info_level = 1;
-       BOOL            opened_hnd = False;
+       bool            opened_hnd = False;
        PRINTER_INFO_CTR ctr;
        fstring         printername,
                        servername,
@@ -678,17 +675,20 @@ static WERROR cmd_spoolss_getprinter(struct rpc_pipe_client *cli,
 
 static void display_reg_value(REGISTRY_VALUE value)
 {
-       pstring text;
+       char *text = NULL;
 
        switch(value.type) {
        case REG_DWORD:
-               printf("%s: REG_DWORD: 0x%08x\n", value.valuename, 
+               printf("%s: REG_DWORD: 0x%08x\n", value.valuename,
                       *((uint32 *) value.data_p));
                break;
        case REG_SZ:
-               rpcstr_pull(text, value.data_p, sizeof(text), value.size,
-                           STR_TERMINATE);
-               printf("%s: REG_SZ: %s\n", value.valuename, text);
+               rpcstr_pull_talloc(talloc_tos(),
+                               &text,
+                               value.data_p,
+                               value.size,
+                               STR_TERMINATE);
+               printf("%s: REG_SZ: %s\n", value.valuename, text ? text : "");
                break;
        case REG_BINARY: {
                char *hex = hex_encode(NULL, value.data_p, value.size);
@@ -704,22 +704,27 @@ static void display_reg_value(REGISTRY_VALUE value)
                        }
                        putchar(hex[i]);
                }
-               talloc_free(hex);
+               TALLOC_FREE(hex);
                putchar('\n');
                break;
        }
        case REG_MULTI_SZ: {
-               uint16 *curstr = (uint16 *) value.data_p;
-               uint8 *start = value.data_p;
-               printf("%s: REG_MULTI_SZ:\n", value.valuename);
-               while (((uint8 *) curstr < start + value.size)) {
-                       rpcstr_pull(text, curstr, sizeof(text), -1, 
-                                   STR_TERMINATE);
-                       printf("  %s\n", *text != 0 ? text : "NULL");
-                       curstr += strlen(text) + 1;
+               uint32 i, num_values;
+               char **values;
+
+               if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL, value.data_p,
+                                                    value.size, &num_values,
+                                                    &values))) {
+                       d_printf("reg_pull_multi_sz failed\n");
+                       break;
+               }
+
+               for (i=0; i<num_values; i++) {
+                       d_printf("%s\n", values[i]);
                }
+               TALLOC_FREE(values);
+               break;
        }
-       break;
        default:
                printf("%s: unknown type %d\n", value.valuename, value.type);
        }
@@ -735,7 +740,7 @@ static WERROR cmd_spoolss_getprinterdata(struct rpc_pipe_client *cli,
 {
        POLICY_HND      pol;
        WERROR          result;
-       BOOL            opened_hnd = False;
+       bool            opened_hnd = False;
        fstring         printername,
                        servername,
                        user;
@@ -800,7 +805,7 @@ static WERROR cmd_spoolss_getprinterdataex(struct rpc_pipe_client *cli,
 {
        POLICY_HND      pol;
        WERROR          result;
-       BOOL            opened_hnd = False;
+       bool            opened_hnd = False;
        fstring         printername,
                        servername,
                        user;
@@ -922,7 +927,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1)
        fstring defaultdatatype = "";
        
        int length=0;
-       BOOL valid = True;
+       bool valid = True;
        
        if (i1 == NULL)
                return;
@@ -979,13 +984,13 @@ static WERROR cmd_spoolss_getdriver(struct rpc_pipe_client *cli,
        POLICY_HND      pol;
        WERROR          werror;
        uint32          info_level = 3;
-       BOOL            opened_hnd = False;
+       bool            opened_hnd = False;
        PRINTER_DRIVER_CTR      ctr;
        fstring         printername, 
                        servername, 
                        user;
        uint32          i;
-       BOOL            success = False;
+       bool            success = False;
 
        if ((argc == 1) || (argc > 3)) 
        {
@@ -1217,9 +1222,10 @@ void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch)
 static char* get_driver_3_param (char* str, const char* delim, UNISTR* dest)
 {
        char    *ptr;
+       char *saveptr;
 
        /* get the next token */
-       ptr = strtok(str, delim);
+       ptr = strtok_r(str, delim, &saveptr);
 
        /* a string of 'NULL' is used to represent an empty
           parameter because two consecutive delimiters
@@ -1241,12 +1247,13 @@ static char* get_driver_3_param (char* str, const char* delim, UNISTR* dest)
             <Config File Name>:<Help File Name>:<Language Monitor Name>:\
             <Default Data Type>:<Comma Separated list of Files> 
  *******************************************************************************/
-static BOOL init_drv_info_3_members ( TALLOC_CTX *mem_ctx, DRIVER_INFO_3 *info, 
+static bool init_drv_info_3_members ( TALLOC_CTX *mem_ctx, DRIVER_INFO_3 *info, 
                                       char *args )
 {
        char    *str, *str2;
        uint32  len, i;
-       
+       char *saveptr = NULL;
+
        /* fill in the UNISTR fields */
        str = get_driver_3_param (args, ":", &info->name);
        str = get_driver_3_param (NULL, ":", &info->driverpath);
@@ -1261,13 +1268,13 @@ static BOOL init_drv_info_3_members ( TALLOC_CTX *mem_ctx, DRIVER_INFO_3 *info,
        str = str2;                     
 
        /* begin to strip out each filename */
-       str = strtok(str, ",");         
+       str = strtok_r(str, ",", &saveptr);
        len = 0;
        while (str != NULL)
        {
                /* keep a cumlative count of the str lengths */
                len += strlen(str)+1;
-               str = strtok(NULL, ",");
+               str = strtok_r(NULL, ",", &saveptr);
        }
 
        /* allocate the space; add one extra slot for a terminating NULL.
@@ -1423,7 +1430,7 @@ static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,
        POLICY_HND              pol;
        WERROR                  result;
        uint32                  level = 2;
-       BOOL                    opened_hnd = False;
+       bool                    opened_hnd = False;
        PRINTER_INFO_CTR        ctr;
        PRINTER_INFO_2          info2;
        fstring                 servername,
@@ -1476,7 +1483,7 @@ static WERROR cmd_spoolss_setdriver(struct rpc_pipe_client *cli,
                goto done;;
        }
 
-       printf("Succesfully set %s to driver %s.\n", argv[1], argv[2]);
+       printf("Successfully set %s to driver %s.\n", argv[1], argv[2]);
 
 done:
        /* Cleanup */
@@ -1636,7 +1643,7 @@ static WERROR cmd_spoolss_addform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
        WERROR werror;
        char *servername = NULL, *printername = NULL;
        FORM form;
-       BOOL got_handle = False;
+       bool got_handle = False;
        
        /* Parse the command arguements */
 
@@ -1696,7 +1703,7 @@ static WERROR cmd_spoolss_setform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
        WERROR werror;
        char *servername = NULL, *printername = NULL;
        FORM form;
-       BOOL got_handle = False;
+       bool got_handle = False;
        
        /* Parse the command arguements */
 
@@ -1793,7 +1800,7 @@ static WERROR cmd_spoolss_getform(struct rpc_pipe_client *cli, TALLOC_CTX *mem_c
        WERROR werror;
        char *servername = NULL, *printername = NULL;
        FORM_1 form;
-       BOOL got_handle = False;
+       bool got_handle = False;
        
        /* Parse the command arguements */
 
@@ -1846,7 +1853,7 @@ static WERROR cmd_spoolss_deleteform(struct rpc_pipe_client *cli,
        POLICY_HND handle;
        WERROR werror;
        char *servername = NULL, *printername = NULL;
-       BOOL got_handle = False;
+       bool got_handle = False;
        
        /* Parse the command arguements */
 
@@ -1894,8 +1901,8 @@ static WERROR cmd_spoolss_enum_forms(struct rpc_pipe_client *cli,
        POLICY_HND handle;
        WERROR werror;
        char *servername = NULL, *printername = NULL;
-       BOOL got_handle = False;
-       uint32 needed, offered, num_forms, level = 1, i;
+       bool got_handle = False;
+       uint32 num_forms, level = 1, i;
        FORM_1 *forms;
        
        /* Parse the command arguements */
@@ -1922,7 +1929,6 @@ static WERROR cmd_spoolss_enum_forms(struct rpc_pipe_client *cli,
 
        /* Enumerate forms */
 
-       offered = needed = 0;
        werror = rpccli_spoolss_enumforms(cli, mem_ctx, &handle, level, &num_forms, &forms);
 
        if (!W_ERROR_IS_OK(werror))
@@ -1956,7 +1962,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
        WERROR result;
        fstring servername, printername, user;
        POLICY_HND pol;
-       BOOL opened_hnd = False;
+       bool opened_hnd = False;
        PRINTER_INFO_CTR ctr;
        PRINTER_INFO_0 info;
        REGISTRY_VALUE value;
@@ -2013,7 +2019,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
         if (!W_ERROR_IS_OK(result))
                 goto done;
                
-       printf("%s\n", timestring(True));
+       printf("%s\n", current_timestring(True));
        printf("\tchange_id (before set)\t:[0x%x]\n", info.change_id);
 
        /* Set the printer data */
@@ -2025,13 +2031,23 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
                UNISTR2 data;
                init_unistr2(&data, argv[4], UNI_STR_TERMINATE);
                value.size = data.uni_str_len * 2;
-               value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
+               if (value.size) {
+                       value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer,
+                                                     value.size);
+               } else {
+                       value.data_p = NULL;
+               }
                break;
        }
        case REG_DWORD: {
                uint32 data = strtoul(argv[4], NULL, 10);
                value.size = sizeof(data);
-               value.data_p = TALLOC_MEMDUP(mem_ctx, &data, sizeof(data));
+               if (sizeof(data)) {
+                       value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, &data,
+                                                     sizeof(data));
+               } else {
+                       value.data_p = NULL;
+               }
                break;
        }
        case REG_BINARY: {
@@ -2089,7 +2105,7 @@ static WERROR cmd_spoolss_setprinterdata(struct rpc_pipe_client *cli,
         if (!W_ERROR_IS_OK(result))
                 goto done;
                
-       printf("%s\n", timestring(True));
+       printf("%s\n", current_timestring(True));
        printf("\tchange_id (after set)\t:[0x%x]\n", info.change_id);
 
 done:
@@ -2150,18 +2166,18 @@ static WERROR cmd_spoolss_enum_jobs(struct rpc_pipe_client *cli,
                                      const char **argv)
 {
        WERROR result;
-       uint32 needed, offered, level = 1, num_jobs, i;
-       BOOL got_hnd = False;
-       pstring printername;
+       uint32 level = 1, num_jobs, i;
+       bool got_hnd = False;
+       char *printername = NULL;
        fstring servername, user;
        POLICY_HND hnd;
        JOB_INFO_CTR ctr;
-       
+
        if (argc < 2 || argc > 3) {
                printf("Usage: %s printername [level]\n", argv[0]);
                return WERR_OK;
        }
-       
+
        if (argc == 3)
                level = atoi(argv[2]);
 
@@ -2170,22 +2186,29 @@ static WERROR cmd_spoolss_enum_jobs(struct rpc_pipe_client *cli,
        slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);
        strupper_m(servername);
        fstrcpy(user, cli->user_name);
-       slprintf(printername, sizeof(servername)-1, "\\\\%s\\", cli->cli->desthost);
+       printername = talloc_asprintf(mem_ctx,
+                               "\\\\%s\\",
+                               cli->cli->desthost);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
        strupper_m(printername);
-       pstrcat(printername, argv[1]);
+       printername = talloc_asprintf_append(printername, "%s", argv[1]);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
 
-       result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, 
-                                            "", MAXIMUM_ALLOWED_ACCESS, 
+       result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername,
+                                            "", MAXIMUM_ALLOWED_ACCESS,
                                             servername, user, &hnd);
 
        if (!W_ERROR_IS_OK(result))
                goto done;
+
        got_hnd = True;
 
        /* Enumerate ports */
 
-       offered = needed = 0;
        result = rpccli_spoolss_enumjobs(cli, mem_ctx, &hnd, level, 0, 1000,
                &num_jobs, &ctr);
 
@@ -2222,8 +2245,8 @@ static WERROR cmd_spoolss_enum_data( struct rpc_pipe_client *cli,
 {
        WERROR result;
        uint32 i=0, val_needed, data_needed;
-       BOOL got_hnd = False;
-       pstring printername;
+       bool got_hnd = False;
+       char *printername = NULL;
        fstring servername, user;
        POLICY_HND hnd;
 
@@ -2231,18 +2254,26 @@ static WERROR cmd_spoolss_enum_data( struct rpc_pipe_client *cli,
                printf("Usage: %s printername\n", argv[0]);
                return WERR_OK;
        }
-       
+
        /* Open printer handle */
 
        slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);
        strupper_m(servername);
        fstrcpy(user, cli->user_name);
-       slprintf(printername, sizeof(printername)-1, "\\\\%s\\", cli->cli->desthost);
+       printername = talloc_asprintf(mem_ctx,
+                               "\\\\%s\\",
+                               cli->cli->desthost);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
        strupper_m(printername);
-       pstrcat(printername, argv[1]);
+       printername = talloc_asprintf_append(printername, "%s", argv[1]);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
 
-       result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, 
-                                            "", MAXIMUM_ALLOWED_ACCESS, 
+       result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername,
+                                            "", MAXIMUM_ALLOWED_ACCESS,
                                             servername, user, &hnd);
 
        if (!W_ERROR_IS_OK(result))
@@ -2282,8 +2313,8 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli,
 {
        WERROR result;
        uint32 i;
-       BOOL got_hnd = False;
-       pstring printername;
+       bool got_hnd = False;
+       char *printername = NULL;
        fstring servername, user;
        const char *keyname = NULL;
        POLICY_HND hnd;
@@ -2293,7 +2324,7 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli,
                printf("Usage: %s printername <keyname>\n", argv[0]);
                return WERR_OK;
        }
-       
+
        keyname = argv[2];
 
        /* Open printer handle */
@@ -2301,9 +2332,18 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli,
        slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);
        strupper_m(servername);
        fstrcpy(user, cli->user_name);
-       slprintf(printername, sizeof(printername)-1, "\\\\%s\\", cli->cli->desthost);
+
+       printername = talloc_asprintf(mem_ctx,
+                               "\\\\%s\\",
+                               cli->cli->desthost);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
        strupper_m(printername);
-       pstrcat(printername, argv[1]);
+       printername = talloc_asprintf_append(printername, "%s", argv[1]);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
 
        result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, 
                                             "", MAXIMUM_ALLOWED_ACCESS, 
@@ -2345,8 +2385,8 @@ static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli,
                                             const char **argv)
 {
        WERROR result;
-       BOOL got_hnd = False;
-       pstring printername;
+       bool got_hnd = False;
+       char *printername = NULL;
        fstring servername, user;
        const char *keyname = NULL;
        POLICY_HND hnd;
@@ -2356,7 +2396,7 @@ static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli,
                printf("Usage: %s printername [keyname]\n", argv[0]);
                return WERR_OK;
        }
-               
+
        if (argc == 3)
                keyname = argv[2];
        else
@@ -2367,9 +2407,19 @@ static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli,
        slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->cli->desthost);
        strupper_m(servername);
        fstrcpy(user, cli->user_name);
-       slprintf(printername, sizeof(printername)-1, "\\\\%s\\", cli->cli->desthost);
+
+       printername = talloc_asprintf(mem_ctx,
+                               "\\\\%s\\",
+                               cli->cli->desthost);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
        strupper_m(printername);
-       pstrcat(printername, argv[1]);
+       printername = talloc_asprintf_append(printername, "%s", argv[1]);
+       if (!printername) {
+               return WERR_NOMEM;
+       }
+
 
        result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, 
                                             "", MAXIMUM_ALLOWED_ACCESS, 
@@ -2389,16 +2439,20 @@ static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli,
 
        curkey = keylist;
        while (*curkey != 0) {
-               pstring subkey;
-               rpcstr_pull(subkey, curkey, sizeof(subkey), -1, 
+               char *subkey = NULL;
+               rpcstr_pull_talloc(mem_ctx, &subkey, curkey, -1,
                            STR_TERMINATE);
+               if (!subkey) {
+                       break;
+               }
                printf("%s\n", subkey);
                curkey += strlen(subkey) + 1;
        }
 
-       safe_free(keylist);
-
 done:
+
+       SAFE_FREE(keylist);
+
        if (got_hnd)
                rpccli_spoolss_close_printer(cli, mem_ctx, &hnd);
 
@@ -2414,7 +2468,7 @@ static WERROR cmd_spoolss_rffpcnex(struct rpc_pipe_client *cli,
 {
        fstring servername, printername;
        POLICY_HND hnd;
-       BOOL got_hnd = False;
+       bool got_hnd = False;
        WERROR result;
        SPOOL_NOTIFY_OPTION option;
 
@@ -2453,6 +2507,10 @@ static WERROR cmd_spoolss_rffpcnex(struct rpc_pipe_client *cli,
        option.count = option.ctr.count = 2;
 
        option.ctr.type = TALLOC_ARRAY(mem_ctx, SPOOL_NOTIFY_OPTION_TYPE, 2);
+       if (option.ctr.type == NULL) {
+               result = WERR_NOMEM;
+               goto done;
+       }
 
        ZERO_STRUCT(option.ctr.type[0]);
        option.ctr.type[0].type = PRINTER_NOTIFY_TYPE;
@@ -2489,7 +2547,7 @@ done:
 /****************************************************************************
 ****************************************************************************/
 
-static BOOL compare_printer( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
+static bool compare_printer( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
                              struct rpc_pipe_client *cli2, POLICY_HND *hnd2 )
 {
        PRINTER_INFO_CTR ctr1, ctr2;
@@ -2522,14 +2580,14 @@ static BOOL compare_printer( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
 /****************************************************************************
 ****************************************************************************/
 
-static BOOL compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
+static bool compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *hnd1,
                                      struct rpc_pipe_client *cli2, POLICY_HND *hnd2 )
 {
        PRINTER_INFO_CTR ctr1, ctr2;
        WERROR werror;
        TALLOC_CTX *mem_ctx = talloc_init("compare_printer_secdesc");
        SEC_DESC *sd1, *sd2;
-       BOOL result = True;
+       bool result = True;
 
 
        printf("Retreiving printer security for %s...", cli1->cli->desthost);
@@ -2568,7 +2626,7 @@ static BOOL compare_printer_secdesc( struct rpc_pipe_client *cli1, POLICY_HND *h
                goto done;
        }
        
-       if ( (ctr1.printers_3->flags != ctr1.printers_3->flags ) || !sec_desc_equal( sd1, sd2 ) ) {
+       if (!sec_desc_equal( sd1, sd2 ) ) {
                printf("Security Descriptors *not* equal!\n");
                result = False;
                goto done;
@@ -2590,38 +2648,37 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
                                     const char **argv)
 {
        fstring printername, servername1, servername2;
-       pstring printername_path;
+       char *printername_path = NULL;
        struct cli_state *cli_server1 = cli->cli;
        struct cli_state *cli_server2 = NULL;
        struct rpc_pipe_client *cli2 = NULL;
        POLICY_HND hPrinter1, hPrinter2;
        NTSTATUS nt_status;
        WERROR werror;
-       
+
        if ( argc != 3 )  {
                printf("Usage: %s <printer> <server>\n", argv[0]);
                return WERR_OK;
        }
-       
+
        fstrcpy( printername, argv[1] );
-       
+
        fstr_sprintf( servername1, cli->cli->desthost );
        fstrcpy( servername2, argv[2] );
        strupper_m( servername1 );
        strupper_m( servername2 );
-       
-       
+
        /* first get the connection to the remote server */
-       
+
        nt_status = cli_full_connection(&cli_server2, global_myname(), servername2, 
                                        NULL, 0,
-                                       "IPC$", "IPC",  
-                                       cmdline_auth_info.username, 
+                                       "IPC$", "IPC",
+                                       get_cmdline_auth_info_username(),
                                        lp_workgroup(),
-                                       cmdline_auth_info.password, 
-                                       cmdline_auth_info.use_kerberos ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
-                                       cmdline_auth_info.signing_state, NULL);
-                                       
+                                       get_cmdline_auth_info_password(),
+                                       get_cmdline_auth_info_use_kerberos() ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
+                                       get_cmdline_auth_info_signing_state(), NULL);
+
        if ( !NT_STATUS_IS_OK(nt_status) )
                return WERR_GENERAL_FAILURE;
 
@@ -2631,10 +2688,16 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
                        servername2, nt_errstr(nt_status));
                return WERR_GENERAL_FAILURE;
        }
-                                       
+
        /* now open up both printers */
 
-       pstr_sprintf( printername_path, "\\\\%s\\%s", servername1, printername );
+       printername_path = talloc_asprintf(mem_ctx,
+                               "\\\\%s\\%s",
+                               servername1,
+                               printername);
+       if (!printername_path) {
+               return WERR_NOMEM;
+       }
        printf("Opening %s...", printername_path);
        werror = rpccli_spoolss_open_printer_ex( cli, mem_ctx, printername_path, 
                "", PRINTER_ALL_ACCESS, servername1, cli_server1->user_name, &hPrinter1);
@@ -2643,8 +2706,14 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
                goto done;
        }
        printf("ok\n");
-       
-       pstr_sprintf( printername_path, "\\\\%s\\%s", servername2, printername );
+
+       printername_path = talloc_asprintf(mem_ctx,
+                                       "\\\\%s\\%s",
+                                       servername2,
+                                       printername);
+       if (!printername_path) {
+               return WERR_NOMEM;
+       }
        printf("Opening %s...", printername_path);
        werror = rpccli_spoolss_open_printer_ex( cli2, mem_ctx, printername_path,  
                "", PRINTER_ALL_ACCESS, servername2, cli_server2->user_name, &hPrinter2 );
@@ -2653,8 +2722,7 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
                goto done;
        }
        printf("ok\n");
-       
-       
+
        compare_printer( cli, &hPrinter1, cli2, &hPrinter2 );
        compare_printer_secdesc( cli, &hPrinter1, cli2, &hPrinter2 );
 #if 0
@@ -2665,15 +2733,14 @@ static WERROR cmd_spoolss_printercmp(struct rpc_pipe_client *cli,
 done:
        /* cleanup */
 
-       printf("Closing printers...");  
+       printf("Closing printers...");
        rpccli_spoolss_close_printer( cli, mem_ctx, &hPrinter1 );
        rpccli_spoolss_close_printer( cli2, mem_ctx, &hPrinter2 );
        printf("ok\n");
-       
+
        /* close the second remote connection */
-       
+
        cli_shutdown( cli_server2 );
-       
        return WERR_OK;
 }