s3-rpcclient: use rpccli_spoolss_enumprinterkey wrapper.
authorGünther Deschner <gd@samba.org>
Mon, 16 Mar 2009 21:07:00 +0000 (22:07 +0100)
committerGünther Deschner <gd@samba.org>
Tue, 17 Mar 2009 11:18:37 +0000 (12:18 +0100)
Guenther

source3/rpcclient/cmd_spoolss.c

index 1043a78248d4b7c8d8c66a151dd15add2a916edb..aba2939343fbdb48f58e60406fd6f12840ab51f1 100644 (file)
@@ -2592,25 +2592,27 @@ done:
 /****************************************************************************
 ****************************************************************************/
 
-static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli,
-                                            TALLOC_CTX *mem_ctx, int argc,
-                                            const char **argv)
+static WERROR cmd_spoolss_enum_printerkey(struct rpc_pipe_client *cli,
+                                         TALLOC_CTX *mem_ctx, int argc,
+                                         const char **argv)
 {
        WERROR result;
        const char *printername;
        const char *keyname = NULL;
        POLICY_HND hnd;
-       uint16 *keylist = NULL, *curkey;
+       const char **key_buffer = NULL;
+       int i;
 
        if (argc < 2 || argc > 3) {
                printf("Usage: %s printername [keyname]\n", argv[0]);
                return WERR_OK;
        }
 
-       if (argc == 3)
+       if (argc == 3) {
                keyname = argv[2];
-       else
+       } else {
                keyname = "";
+       }
 
        /* Open printer handle */
 
@@ -2620,34 +2622,31 @@ static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli,
                                               printername,
                                               SEC_FLAG_MAXIMUM_ALLOWED,
                                               &hnd);
-       if (!W_ERROR_IS_OK(result))
+       if (!W_ERROR_IS_OK(result)) {
                goto done;
+       }
 
        /* Enumerate subkeys */
 
-       result = rpccli_spoolss_enumprinterkey(cli, mem_ctx, &hnd, keyname, &keylist, NULL);
+       result = rpccli_spoolss_enumprinterkey(cli, mem_ctx,
+                                              &hnd,
+                                              keyname,
+                                              &key_buffer,
+                                              0);
 
-       if (!W_ERROR_IS_OK(result))
+       if (!W_ERROR_IS_OK(result)) {
                goto done;
-
-       curkey = keylist;
-       while (*curkey != 0) {
-               char *subkey = NULL;
-               rpcstr_pull_talloc(mem_ctx, &subkey, curkey, -1,
-                           STR_TERMINATE);
-               if (!subkey) {
-                       break;
-               }
-               printf("%s\n", subkey);
-               curkey += strlen(subkey) + 1;
        }
 
-done:
+       for (i=0; key_buffer && key_buffer[i]; i++) {
+               printf("%s\n", key_buffer[i]);
+       }
 
-       SAFE_FREE(keylist);
+ done:
 
-       if (is_valid_policy_hnd(&hnd))
+       if (is_valid_policy_hnd(&hnd)) {
                rpccli_spoolss_ClosePrinter(cli, mem_ctx, &hnd, NULL);
+       }
 
        return result;
 }