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,
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"
static void display_print_info_3(PRINTER_INFO_3 *i3)
{
- printf("\tflags:[0x%x]\n", i3->flags);
-
display_sec_desc(i3->secdesc);
printf("\n");
POLICY_HND pol;
WERROR result;
uint32 info_level = 2;
- BOOL opened_hnd = False;
+ bool opened_hnd = False;
PRINTER_INFO_CTR ctr;
fstring printername,
servername,
POLICY_HND pol;
WERROR result;
uint32 info_level = 2;
- BOOL opened_hnd = False;
+ bool opened_hnd = False;
PRINTER_INFO_CTR ctr;
fstring printername,
servername,
POLICY_HND pol;
WERROR result;
uint32 info_level = 1;
- BOOL opened_hnd = False;
+ bool opened_hnd = False;
PRINTER_INFO_CTR ctr;
fstring printername,
servername,
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);
}
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);
}
{
POLICY_HND pol;
WERROR result;
- BOOL opened_hnd = False;
+ bool opened_hnd = False;
fstring printername,
servername,
user;
{
POLICY_HND pol;
WERROR result;
- BOOL opened_hnd = False;
+ bool opened_hnd = False;
fstring printername,
servername,
user;
fstring defaultdatatype = "";
int length=0;
- BOOL valid = True;
+ bool valid = True;
if (i1 == NULL)
return;
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))
{
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
<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);
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.
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,
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 */
WERROR werror;
char *servername = NULL, *printername = NULL;
FORM form;
- BOOL got_handle = False;
+ bool got_handle = False;
/* Parse the command arguements */
WERROR werror;
char *servername = NULL, *printername = NULL;
FORM form;
- BOOL got_handle = False;
+ bool got_handle = False;
/* Parse the command arguements */
WERROR werror;
char *servername = NULL, *printername = NULL;
FORM_1 form;
- BOOL got_handle = False;
+ bool got_handle = False;
/* Parse the command arguements */
POLICY_HND handle;
WERROR werror;
char *servername = NULL, *printername = NULL;
- BOOL got_handle = False;
+ bool got_handle = False;
/* Parse the command arguements */
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 */
/* Enumerate forms */
- offered = needed = 0;
werror = rpccli_spoolss_enumforms(cli, mem_ctx, &handle, level, &num_forms, &forms);
if (!W_ERROR_IS_OK(werror))
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;
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 */
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: {
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:
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]);
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);
{
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;
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))
{
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;
printf("Usage: %s printername <keyname>\n", argv[0]);
return WERR_OK;
}
-
+
keyname = argv[2];
/* 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,
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;
printf("Usage: %s printername [keyname]\n", argv[0]);
return WERR_OK;
}
-
+
if (argc == 3)
keyname = argv[2];
else
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,
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);
{
fstring servername, printername;
POLICY_HND hnd;
- BOOL got_hnd = False;
+ bool got_hnd = False;
WERROR result;
SPOOL_NOTIFY_OPTION option;
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;
/****************************************************************************
****************************************************************************/
-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;
/****************************************************************************
****************************************************************************/
-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);
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;
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;
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);
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 );
goto done;
}
printf("ok\n");
-
-
+
compare_printer( cli, &hPrinter1, cli2, &hPrinter2 );
compare_printer_secdesc( cli, &hPrinter1, cli2, &hPrinter2 );
#if 0
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;
}