diff options
-rw-r--r-- | source3/lib/charcnv.c | 2 | ||||
-rw-r--r-- | source3/lib/util_unistr.c | 19 | ||||
-rw-r--r-- | source3/rpc_parse/parse_net.c | 2 | ||||
-rw-r--r-- | source3/rpc_parse/parse_prs.c | 11 | ||||
-rw-r--r-- | source3/rpcclient/cmd_spoolss.c | 156 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 5 |
6 files changed, 136 insertions, 59 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index da972f550f..0dfa88e87e 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -932,7 +932,7 @@ char *strdup_lower(const char *s) return out_buffer; } -static size_t ucs2_align(const void *base_ptr, const void *p, int flags) +size_t ucs2_align(const void *base_ptr, const void *p, int flags) { if (flags & (STR_NOALIGN|STR_ASCII)) return 0; diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 1fef6ab239..45f09da85b 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -319,6 +319,25 @@ int rpcstr_pull(char* dest, void *src, int dest_len, int src_len, int flags) return pull_ucs2(NULL, dest, src, dest_len, src_len, flags|STR_UNICODE|STR_NOALIGN); } +/* Copy a string from little-endian or big-endian unicode source (depending + * on flags) to internal samba format destination. Allocates on talloc ctx. + */ + +int rpcstr_pull_talloc(TALLOC_CTX *ctx, + char **dest, + void *src, + int src_len, + int flags) +{ + return pull_ucs2_base_talloc(ctx, + NULL, + dest, + src, + src_len, + flags|STR_UNICODE|STR_NOALIGN); + +} + /* Copy a string from a unistr2 source to internal samba format destination. Use this instead of direct calls to rpcstr_pull() to avoid having to determine whether the source string is null terminated. */ diff --git a/source3/rpc_parse/parse_net.c b/source3/rpc_parse/parse_net.c index e12d9dda0d..df11c6d75a 100644 --- a/source3/rpc_parse/parse_net.c +++ b/source3/rpc_parse/parse_net.c @@ -1086,7 +1086,7 @@ bool net_io_r_srv_pwset(const char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, static int init_dom_sid2s(TALLOC_CTX *ctx, const char *sids_str, DOM_SID2 **ppsids) { const char *ptr; - pstring s2; + fstring s2; int count = 0; DEBUG(4,("init_dom_sid2s: %s\n", sids_str ? sids_str:"")); diff --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c index a30e96772a..137e0dabac 100644 --- a/source3/rpc_parse/parse_prs.c +++ b/source3/rpc_parse/parse_prs.c @@ -48,14 +48,18 @@ void prs_dump_region(char *name, int v, prs_struct *ps, int from_off, int to_off) { int fd, i; - pstring fname; + char *fname = NULL; ssize_t sz; if (DEBUGLEVEL < 50) return; for (i=1;i<100;i++) { if (v != -1) { - slprintf(fname,sizeof(fname)-1, "/tmp/%s_%d.%d.prs", name, v, i); + if (asprintf(&fname,"/tmp/%s_%d.%d.prs", name, v, i) < 0) { + return; + } } else { - slprintf(fname,sizeof(fname)-1, "/tmp/%s.%d.prs", name, i); + if (asprintf(&fname,"/tmp/%s.%d.prs", name, i) < 0) { + return; + } } fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd != -1 || errno != EEXIST) break; @@ -69,6 +73,7 @@ void prs_dump_region(char *name, int v, prs_struct *ps, DEBUG(0,("created %s\n", fname)); } } + SAFE_FREE(fname); } /******************************************************************* diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c index e573e92648..3bcf1bdcc9 100644 --- a/source3/rpcclient/cmd_spoolss.c +++ b/source3/rpcclient/cmd_spoolss.c @@ -675,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); @@ -2163,16 +2166,16 @@ static WERROR cmd_spoolss_enum_jobs(struct rpc_pipe_client *cli, WERROR result; uint32 level = 1, num_jobs, i; bool got_hnd = False; - pstring printername; + 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]); @@ -2181,17 +2184,25 @@ 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 */ @@ -2233,7 +2244,7 @@ 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; + char *printername = NULL; fstring servername, user; POLICY_HND hnd; @@ -2241,18 +2252,28 @@ 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(mem_ctx, + "%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)) @@ -2293,7 +2314,7 @@ static WERROR cmd_spoolss_enum_data_ex( struct rpc_pipe_client *cli, WERROR result; uint32 i; bool got_hnd = False; - pstring printername; + char *printername = NULL; fstring servername, user; const char *keyname = NULL; POLICY_HND hnd; @@ -2303,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 */ @@ -2311,9 +2332,20 @@ 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(mem_ctx, + "%s", + argv[1]); + if (!printername) { + return WERR_NOMEM; + } result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, @@ -2356,7 +2388,7 @@ static WERROR cmd_spoolss_enum_printerkey( struct rpc_pipe_client *cli, { WERROR result; bool got_hnd = False; - pstring printername; + char *printername = NULL; fstring servername, user; const char *keyname = NULL; POLICY_HND hnd; @@ -2366,7 +2398,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 @@ -2377,9 +2409,21 @@ 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(mem_ctx, + "%s", + argv[1]); + if (!printername) { + return WERR_NOMEM; + } + result = rpccli_spoolss_open_printer_ex(cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, @@ -2399,9 +2443,12 @@ 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; } @@ -2605,38 +2652,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", + cmdline_auth_info.username, lp_workgroup(), - cmdline_auth_info.password, + cmdline_auth_info.password, cmdline_auth_info.use_kerberos ? CLI_FULL_CONNECTION_USE_KERBEROS : 0, cmdline_auth_info.signing_state, NULL); - + if ( !NT_STATUS_IS_OK(nt_status) ) return WERR_GENERAL_FAILURE; @@ -2646,10 +2692,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); @@ -2658,8 +2710,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 ); @@ -2668,8 +2726,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 @@ -2680,15 +2737,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; } diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index 6d318ae7ec..9f59ea6f8c 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -878,12 +878,9 @@ out_free: /* Loop around accepting commands */ while(1) { - pstring prompt; char *line; - slprintf(prompt, sizeof(prompt) - 1, "rpcclient $> "); - - line = smb_readline(prompt, NULL, completion_fn); + line = smb_readline("rpcclient $> ", NULL, completion_fn); if (line == NULL) break; |