WERROR(*fn) (NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed);
};
+/********************************************************************
+ * Canonicalize servername.
+ ********************************************************************/
+
+static const char *canon_servername(const char *servername)
+{
+ const char *pservername = servername;
+ while (*pservername == '\\') {
+ pservername++;
+ }
+ return pservername;
+}
/* translate between internal status numbers and NT status numbers */
static int nt_printj_status(int v)
return;
}
- result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, handle);
+ result = rpccli_spoolss_reply_close_printer(notify_cli_pipe,
+ talloc_tos(),
+ handle);
if (!W_ERROR_IS_OK(result))
DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
/* if it's the last connection, deconnect the IPC$ share */
if (smb_connections==1) {
- cli_shutdown( notify_cli_pipe->cli );
+ cli_shutdown( rpc_pipe_np_smb_conn(notify_cli_pipe) );
notify_cli_pipe = NULL; /* The above call shuts downn the pipe also. */
messaging_deregister(smbd_messaging_context(),
/****************************************************************************
Delete a printer given a handle.
****************************************************************************/
-WERROR delete_printer_hook( NT_USER_TOKEN *token, const char *sharename )
+
+WERROR delete_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *sharename )
{
char *cmd = lp_deleteprinter_cmd();
- pstring command;
+ char *command = NULL;
int ret;
SE_PRIV se_printop = SE_PRINT_OPERATOR;
bool is_print_op = False;
if ( !*cmd )
return WERR_OK;
- pstr_sprintf(command, "%s \"%s\"", cmd, sharename);
-
+ command = talloc_asprintf(ctx,
+ "%s \"%s\"",
+ cmd, sharename);
+ if (!command) {
+ return WERR_NOMEM;
+ }
if ( token )
is_print_op = user_has_privileges( token, &se_printop );
DEBUGADD(10,("returned [%d]\n", ret));
+ TALLOC_FREE(command);
+
if (ret != 0)
return WERR_BADFID; /* What to return here? */
return WERR_BADFID;
}
- return delete_printer_hook( p->pipe_user.nt_user_token, Printer->sharename );
+ return delete_printer_hook(p->mem_ctx, p->pipe_user.nt_user_token, Printer->sharename );
}
/****************************************************************************
aprinter = handlename;
if ( *handlename == '\\' ) {
- servername = handlename + 2;
- if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) {
+ servername = canon_servername(handlename);
+ if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
*aprinter = '\0';
aprinter++;
}
- }
- else {
+ } else {
servername = "";
}
fstrcpy(sname, lp_servicename(snum));
printer = NULL;
- result = get_a_printer( NULL, &printer, 2, sname );
+
+ /* This call doesn't fill in the location or comment from
+ * a CUPS server for efficiency with large numbers of printers.
+ * JRA.
+ */
+
+ result = get_a_printer_search( NULL, &printer, 2, sname );
if ( !W_ERROR_IS_OK(result) ) {
DEBUG(0,("set_printer_hnd_name: failed to lookup printer [%s] -- result [%s]\n",
sname, dos_errstr(result)));
memcpy(r_u, &r_u_ex, sizeof(*r_u));
+ if (W_ERROR_EQUAL(r_u->status, WERR_INVALID_PARAM)) {
+ /* OpenPrinterEx returns this for a bad
+ * printer name. We must return WERR_INVALID_PRINTER_NAME
+ * instead.
+ */
+ r_u->status = WERR_INVALID_PRINTER_NAME;
+ }
return r_u->status;
}
int snum;
Printer_entry *Printer=NULL;
- if ( !q_u->printername )
- return WERR_INVALID_PRINTER_NAME;
+ if (!q_u->printername) {
+ return WERR_INVALID_PARAM;
+ }
/* some sanity check because you can open a printer or a print server */
/* aka: \\server\printer or \\server */
DEBUGADD(3,("checking name: %s\n",name));
- if (!open_printer_hnd(p, handle, name, 0))
- return WERR_INVALID_PRINTER_NAME;
+ if (!open_printer_hnd(p, handle, name, 0)) {
+ return WERR_INVALID_PARAM;
+ }
Printer=find_printer_index_by_hnd(p, handle);
if ( !Printer ) {
DEBUG(0,(" _spoolss_open_printer_ex: logic error. Can't find printer "
"handle we created for printer %s\n", name ));
close_printer_handle(p,handle);
- return WERR_INVALID_PRINTER_NAME;
+ return WERR_INVALID_PARAM;
}
/*
!user_has_privileges(p->pipe_user.nt_user_token,
&se_printop ) &&
!token_contains_name_in_list(
- uidtoname(p->pipe_user.ut.uid), NULL,
+ uidtoname(p->pipe_user.ut.uid),
+ NULL, NULL,
p->pipe_user.nt_user_token,
lp_printer_admin(snum))) {
close_printer_handle(p, handle);
return WERR_ACCESS_DENIED;
}
- if (!user_ok_token(uidtoname(p->pipe_user.ut.uid),
+ if (!user_ok_token(uidtoname(p->pipe_user.ut.uid), NULL,
p->pipe_user.nt_user_token, snum) ||
- !print_access_check(&p->pipe_user, snum,
+ !print_access_check(p->server_info, snum,
printer_default->access_required)) {
DEBUG(3, ("access DENIED for printer open\n"));
close_printer_handle(p, handle);
if ( (p->pipe_user.ut.uid != 0)
&& !user_has_privileges(p->pipe_user.nt_user_token, &se_printop )
- && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid),
- NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) )
+ && !token_contains_name_in_list(
+ uidtoname(p->pipe_user.ut.uid), NULL,
+ NULL, p->pipe_user.nt_user_token,
+ lp_printer_admin(-1)) )
{
return WERR_ACCESS_DENIED;
}
if ( (p->pipe_user.ut.uid != 0)
&& !user_has_privileges(p->pipe_user.nt_user_token, &se_printop )
- && !token_contains_name_in_list( uidtoname(p->pipe_user.ut.uid),
- NULL, p->pipe_user.nt_user_token, lp_printer_admin(-1)) )
+ && !token_contains_name_in_list(
+ uidtoname(p->pipe_user.ut.uid), NULL, NULL,
+ p->pipe_user.nt_user_token, lp_printer_admin(-1)) )
{
return WERR_ACCESS_DENIED;
}
* Now start the NT Domain stuff :-).
*/
- if ( !(*pp_pipe = cli_rpc_pipe_open_noauth(the_cli, PI_SPOOLSS, &ret)) ) {
+ ret = cli_rpc_pipe_open_noauth(the_cli, &syntax_spoolss, pp_pipe);
+ if (!NT_STATUS_IS_OK(ret)) {
DEBUG(2,("spoolss_connect_to_client: unable to open the spoolss pipe on machine %s. Error was : %s.\n",
remote_machine, nt_errstr(ret)));
cli_shutdown(the_cli);
return False;
}
- /* make sure to save the cli_state pointer. Keep its own talloc_ctx */
-
- (*pp_pipe)->cli = the_cli;
-
return True;
}
smb_connections++;
- result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter,
- type, handle);
+ result = rpccli_spoolss_reply_open_printer(notify_cli_pipe,
+ talloc_tos(),
+ printer,
+ localprinter,
+ type,
+ handle);
if (!W_ERROR_IS_OK(result))
DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
!get_printer_snum(p, handle, &snum, NULL) )
return WERR_BADFID;
- if (!interpret_string_addr(&client_ss,
- p->conn->client_address,
- AI_NUMERICHOST)) {
+ if (!interpret_string_addr(&client_ss, p->client_address,
+ AI_NUMERICHOST)) {
return WERR_SERVER_UNAVAILABLE;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->servername);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
/* the notify name should not contain the \\server\ part */
p++;
}
- len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, p);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, lp_servicename(snum));
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
/* even if it's strange, that's consistant in all the code */
- len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->portname);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->drivername);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
if (*printer->info_2->comment == '\0')
- len = rpcstr_push(temp, lp_comment(snum), sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, lp_comment(snum));
else
- len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->comment);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->location);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->sepfile);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->printprocessor);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->parameters);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, printer->info_2->datatype);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, queue->fs_user);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
- len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, queue->fs_file);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
*/
const char *p = "";
- pstring temp;
+ smb_ucs2_t *temp = NULL;
uint32 len;
#if 0 /* NO LONGER NEEDED - JRA. 02/22/2001 */
}
#endif /* NO LONGER NEEDED. */
- len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE);
+ len = rpcstr_push_talloc(mem_ctx, &temp, p);
+ if (len == (uint32)-1) {
+ len = 0;
+ }
data->notify_data.data.length = len;
if (len) {
- data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
-
- if (!data->notify_data.data.string) {
- data->notify_data.data.length = 0;
- return;
- }
-
- memcpy(data->notify_data.data.string, temp, len);
+ data->notify_data.data.string = (uint16 *)temp;
} else {
data->notify_data.data.string = NULL;
}
static bool construct_printer_info_0(Printer_entry *print_hnd, PRINTER_INFO_0 *printer, int snum)
{
- pstring chaine;
+ char *chaine = NULL;
int count;
NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
counter_printer_0 *session_counter;
struct tm *t;
time_t setuptime;
print_status_struct status;
+ TALLOC_CTX *ctx = talloc_tos();
if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
return False;
+ init_unistr(&printer->printername, ntprinter->info_2->printername);
+
+ chaine = talloc_asprintf(ctx, "\\\\%s", get_server_name(print_hnd));
+ if (!chaine) {
+ free_a_printer(&ntprinter,2);
+ return false;
+ }
+
count = print_queue_length(snum, &status);
/* check if we already have a counter for this printer */
break;
}
+ init_unistr(&printer->servername, chaine);
+
/* it's the first time, add it to the list */
if (session_counter==NULL) {
if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) {
* and should be zeroed on samba startup
*/
global_counter=session_counter->counter;
-
- pstrcpy(chaine,ntprinter->info_2->printername);
-
- init_unistr(&printer->printername, chaine);
-
- slprintf(chaine,sizeof(chaine)-1,"\\\\%s", get_server_name(print_hnd));
- init_unistr(&printer->servername, chaine);
-
printer->cjobs = count;
printer->total_jobs = 0;
printer->total_bytes = 0;
********************************************************************/
static bool construct_printer_info_1(Printer_entry *print_hnd, uint32 flags, PRINTER_INFO_1 *printer, int snum)
{
- pstring chaine;
- pstring chaine2;
+ char *chaine = NULL;
NT_PRINTER_INFO_LEVEL *ntprinter = NULL;
+ TALLOC_CTX *ctx = talloc_tos();
if (!W_ERROR_IS_OK(get_a_printer(print_hnd, &ntprinter, 2, lp_const_servicename(snum))))
- return False;
+ return false;
printer->flags=flags;
if (*ntprinter->info_2->comment == '\0') {
init_unistr(&printer->comment, lp_comment(snum));
- slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername,
- ntprinter->info_2->drivername, lp_comment(snum));
+ chaine = talloc_asprintf(ctx,
+ "%s,%s,%s", ntprinter->info_2->printername,
+ ntprinter->info_2->drivername, lp_comment(snum));
}
else {
init_unistr(&printer->comment, ntprinter->info_2->comment); /* saved comment. */
- slprintf(chaine,sizeof(chaine)-1,"%s,%s,%s", ntprinter->info_2->printername,
- ntprinter->info_2->drivername, ntprinter->info_2->comment);
+ chaine = talloc_asprintf(ctx,
+ "%s,%s,%s", ntprinter->info_2->printername,
+ ntprinter->info_2->drivername, ntprinter->info_2->comment);
}
- slprintf(chaine2,sizeof(chaine)-1,"%s", ntprinter->info_2->printername);
+ if (!chaine) {
+ free_a_printer(&ntprinter,2);
+ return false;
+ }
init_unistr(&printer->description, chaine);
- init_unistr(&printer->name, chaine2);
+ init_unistr(&printer->name, ntprinter->info_2->printername);
free_a_printer(&ntprinter,2);
struct GUID guid;
if (is_printer_published(print_hnd, snum, &guid)) {
- asprintf(&guid_str, "{%s}",
- smb_uuid_string(talloc_tos(), guid));
+ if (asprintf(&guid_str, "{%s}",
+ GUID_string(talloc_tos(), &guid)) == -1) {
+ return false;
+ }
strupper_m(guid_str);
init_unistr(&printer->guid, guid_str);
+ SAFE_FREE(guid_str);
printer->action = SPOOL_DS_PUBLISH;
} else {
init_unistr(&printer->guid, "");
* handle enumeration of printers at level 2
********************************************************************/
-static WERROR enumprinters_level2( uint32 flags, fstring servername,
+static WERROR enumprinters_level2( uint32 flags, const char *servername,
RPC_BUFFER *buffer, uint32 offered,
uint32 *needed, uint32 *returned)
{
- char *s = servername;
-
if (flags & PRINTER_ENUM_LOCAL) {
return enum_all_printers_info_2(buffer, offered, needed, returned);
}
if (flags & PRINTER_ENUM_NAME) {
- if ((servername[0] == '\\') && (servername[1] == '\\'))
- s = servername + 2;
- if (is_myname_or_ipaddr(s))
+ if (is_myname_or_ipaddr(canon_servername(servername)))
return enum_all_printers_info_2(buffer, offered, needed, returned);
else
return WERR_INVALID_NAME;
* handle enumeration of printers at level 5
********************************************************************/
-static WERROR enumprinters_level5( uint32 flags, fstring servername,
+static WERROR enumprinters_level5( uint32 flags, const char *servername,
RPC_BUFFER *buffer, uint32 offered,
uint32 *needed, uint32 *returned)
{
if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL)
return WERR_NOMEM;
- if (!construct_printer_info_7(print_hnd, printer, snum))
- return WERR_NOMEM;
+ if (!construct_printer_info_7(print_hnd, printer, snum)) {
+ result = WERR_NOMEM;
+ goto out;
+ }
/* check the required size. */
*needed += spoolss_size_printer_info_7(printer);
* fill a DRIVER_INFO_1 struct
********************************************************************/
-static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture)
+static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername, fstring architecture)
{
init_unistr( &info->name, driver.info_3->name);
}
* construct_printer_driver_info_1
********************************************************************/
-static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version)
+static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, const char *servername, fstring architecture, uint32 version)
{
NT_PRINTER_INFO_LEVEL *printer = NULL;
NT_PRINTER_DRIVER_INFO_LEVEL driver;
* fill a printer_info_2 struct
********************************************************************/
-static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername)
+static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername)
{
- pstring temp;
+ TALLOC_CTX *ctx = talloc_tos();
+ char *temp = NULL;
+ const char *cservername = canon_servername(servername);
info->version=driver.info_3->cversion;
init_unistr( &info->name, driver.info_3->name );
init_unistr( &info->architecture, driver.info_3->environment );
-
- if (strlen(driver.info_3->driverpath)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath);
+ if (strlen(driver.info_3->driverpath)) {
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->driverpath);
init_unistr( &info->driverpath, temp );
- } else
- init_unistr( &info->driverpath, "" );
+ } else {
+ init_unistr( &info->driverpath, "" );
+ }
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->datafile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->datafile);
init_unistr( &info->datafile, temp );
} else
init_unistr( &info->datafile, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->configfile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->configfile);
init_unistr( &info->configfile, temp );
} else
init_unistr( &info->configfile, "" );
* fill a printer_info_2 struct
********************************************************************/
-static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version)
+static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, const char *servername, fstring architecture, uint32 version)
{
NT_PRINTER_INFO_LEVEL *printer = NULL;
NT_PRINTER_DRIVER_INFO_LEVEL driver;
int i=0;
int j=0;
const char *v;
- pstring line;
+ char *line = NULL;
+ TALLOC_CTX *ctx = talloc_tos();
DEBUG(6,("init_unistr_array\n"));
*uni_array=NULL;
- while (True)
- {
- if ( !char_array )
+ while (true) {
+ if ( !char_array ) {
v = "";
- else
- {
+ } else {
v = char_array[i];
if (!v)
v = ""; /* hack to handle null lists */
/* hack to allow this to be used in places other than when generating
the list of dependent files */
-
- if ( servername )
- slprintf( line, sizeof(line)-1, "\\\\%s%s", servername, v );
- else
- pstrcpy( line, v );
+ TALLOC_FREE(line);
+ if ( servername ) {
+ line = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ canon_servername(servername),
+ v);
+ } else {
+ line = talloc_strdup(ctx, v);
+ }
+
+ if (!line) {
+ SAFE_FREE(*uni_array);
+ return 0;
+ }
DEBUGADD(6,("%d:%s:%lu\n", i, line, (unsigned long)strlen(line)));
/* add one extra unit16 for the second terminating NULL */
* fill a printer_info_3 struct
********************************************************************/
-static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername)
+static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername)
{
- pstring temp;
+ char *temp = NULL;
+ TALLOC_CTX *ctx = talloc_tos();
+ const char *cservername = canon_servername(servername);
ZERO_STRUCTP(info);
init_unistr( &info->architecture, driver.info_3->environment );
if (strlen(driver.info_3->driverpath)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->driverpath);
init_unistr( &info->driverpath, temp );
} else
init_unistr( &info->driverpath, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->datafile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->datafile);
init_unistr( &info->datafile, temp );
} else
init_unistr( &info->datafile, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->configfile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->configfile);
init_unistr( &info->configfile, temp );
} else
init_unistr( &info->configfile, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->helpfile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->helpfile);
init_unistr( &info->helpfile, temp );
} else
init_unistr( &info->helpfile, "" );
+ TALLOC_FREE(temp);
init_unistr( &info->monitorname, driver.info_3->monitorname );
init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
info->dependentfiles=NULL;
- init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername);
+ init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, cservername);
}
/********************************************************************
* fill a printer_info_3 struct
********************************************************************/
-static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version)
+static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, const char *servername, fstring architecture, uint32 version)
{
NT_PRINTER_INFO_LEVEL *printer = NULL;
NT_PRINTER_DRIVER_INFO_LEVEL driver;
* fill a printer_info_6 struct - we know that driver is really level 3. This sucks. JRA.
********************************************************************/
-static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername)
+static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername)
{
- pstring temp;
+ char *temp = NULL;
fstring nullstr;
+ TALLOC_CTX *ctx = talloc_tos();
+ const char *cservername = canon_servername(servername);
ZERO_STRUCTP(info);
memset(&nullstr, '\0', sizeof(fstring));
init_unistr( &info->architecture, driver.info_3->environment );
if (strlen(driver.info_3->driverpath)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->driverpath);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->driverpath);
init_unistr( &info->driverpath, temp );
} else
init_unistr( &info->driverpath, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->datafile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->datafile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->datafile);
init_unistr( &info->datafile, temp );
} else
init_unistr( &info->datafile, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->configfile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->configfile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->configfile);
init_unistr( &info->configfile, temp );
} else
init_unistr( &info->configfile, "" );
+ TALLOC_FREE(temp);
if (strlen(driver.info_3->helpfile)) {
- slprintf(temp, sizeof(temp)-1, "\\\\%s%s", servername, driver.info_3->helpfile);
+ temp = talloc_asprintf(ctx,
+ "\\\\%s%s",
+ cservername,
+ driver.info_3->helpfile);
init_unistr( &info->helpfile, temp );
} else
init_unistr( &info->helpfile, "" );
+ TALLOC_FREE(temp);
init_unistr( &info->monitorname, driver.info_3->monitorname );
init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype );
********************************************************************/
static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum,
- fstring servername, fstring architecture, uint32 version)
+ const char *servername, fstring architecture, uint32 version)
{
NT_PRINTER_INFO_LEVEL *printer = NULL;
NT_PRINTER_DRIVER_INFO_LEVEL driver;
/****************************************************************************
****************************************************************************/
-static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
+static WERROR getprinterdriver2_level1(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
{
DRIVER_INFO_1 *info=NULL;
WERROR result;
/****************************************************************************
****************************************************************************/
-static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
+static WERROR getprinterdriver2_level2(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
{
DRIVER_INFO_2 *info=NULL;
WERROR result;
/****************************************************************************
****************************************************************************/
-static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
+static WERROR getprinterdriver2_level3(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
{
DRIVER_INFO_3 info;
WERROR result;
/****************************************************************************
****************************************************************************/
-static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
+static WERROR getprinterdriver2_level6(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
{
DRIVER_INFO_6 info;
WERROR result;
POLICY_HND *handle = &q_u->handle;
DOC_INFO *docinfo = &q_u->doc_info_container.docinfo;
uint32 *jobid = &r_u->jobid;
-
+ TALLOC_CTX *ctx = p->mem_ctx;
DOC_INFO_1 *info_1 = &docinfo->doc_info_1;
int snum;
- pstring jobname;
+ char *jobname = NULL;
fstring datatype;
Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
return WERR_BADFID;
}
- unistr2_to_ascii(jobname, &info_1->docname, sizeof(jobname));
+ jobname = unistr2_to_ascii_talloc(ctx, &info_1->docname);
- Printer->jobid = print_job_start(&p->pipe_user, snum, jobname, Printer->nt_devmode);
+ Printer->jobid = print_job_start(p->server_info, snum, jobname,
+ Printer->nt_devmode);
/* An error occured in print_job_start() so return an appropriate
NT error code. */
switch (command) {
case PRINTER_CONTROL_PAUSE:
- if (print_queue_pause(&p->pipe_user, snum, &errcode)) {
+ if (print_queue_pause(p->server_info, snum, &errcode)) {
errcode = WERR_OK;
}
break;
case PRINTER_CONTROL_RESUME:
case PRINTER_CONTROL_UNPAUSE:
- if (print_queue_resume(&p->pipe_user, snum, &errcode)) {
+ if (print_queue_resume(p->server_info, snum, &errcode)) {
errcode = WERR_OK;
}
break;
case PRINTER_CONTROL_PURGE:
- if (print_queue_purge(&p->pipe_user, snum, &errcode)) {
+ if (print_queue_purge(p->server_info, snum, &errcode)) {
errcode = WERR_OK;
}
break;
if (!get_printer_snum(p, handle, &snum, NULL))
return WERR_BADFID;
- print_job_delete( &p->pipe_user, snum, Printer->jobid, &errcode );
+ print_job_delete(p->server_info, snum, Printer->jobid, &errcode );
return errcode;
}
/* NT seems to like setting the security descriptor even though
nothing may have actually changed. */
- nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr);
+ if ( !nt_printing_getsec(p->mem_ctx, Printer->sharename, &old_secdesc_ctr)) {
+ DEBUG(2,("update_printer_sec: nt_printing_getsec() failed\n"));
+ result = WERR_BADFID;
+ goto done;
+ }
if (DEBUGLEVEL >= 10) {
SEC_ACL *the_acl;
PRINTERNAME(snum), the_acl->num_aces));
for (i = 0; i < the_acl->num_aces; i++) {
- fstring sid_str;
-
- sid_to_string(sid_str, &the_acl->aces[i].trustee);
-
- DEBUG(10, ("%s 0x%08x\n", sid_str,
+ DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
+ &the_acl->aces[i].trustee),
the_acl->aces[i].access_mask));
}
PRINTERNAME(snum), the_acl->num_aces));
for (i = 0; i < the_acl->num_aces; i++) {
- fstring sid_str;
-
- sid_to_string(sid_str, &the_acl->aces[i].trustee);
-
- DEBUG(10, ("%s 0x%08x\n", sid_str,
+ DEBUG(10, ("%s 0x%08x\n", sid_string_dbg(
+ &the_acl->aces[i].trustee),
the_acl->aces[i].access_mask));
}
} else {
/****************************************************************************
****************************************************************************/
-WERROR add_port_hook(NT_USER_TOKEN *token, const char *portname, const char *uri )
+WERROR add_port_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, const char *portname, const char *uri )
{
char *cmd = lp_addport_cmd();
- pstring command;
+ char *command = NULL;
int ret;
- int fd;
SE_PRIV se_printop = SE_PRINT_OPERATOR;
bool is_print_op = False;
return WERR_ACCESS_DENIED;
}
- slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"", cmd, portname, uri );
+ command = talloc_asprintf(ctx,
+ "%s \"%s\" \"%s\"", cmd, portname, uri );
+ if (!command) {
+ return WERR_NOMEM;
+ }
if ( token )
is_print_op = user_has_privileges( token, &se_printop );
if ( is_print_op )
become_root();
- ret = smbrun(command, &fd);
+ ret = smbrun(command, NULL);
if ( is_print_op )
unbecome_root();
DEBUGADD(10,("returned [%d]\n", ret));
+ TALLOC_FREE(command);
+
if ( ret != 0 ) {
- if (fd != -1)
- close(fd);
return WERR_ACCESS_DENIED;
}
/****************************************************************************
****************************************************************************/
-bool add_printer_hook(NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
+bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEVEL *printer)
{
char *cmd = lp_addprinter_cmd();
char **qlines;
- pstring command;
+ char *command = NULL;
int numlines;
int ret;
int fd;
- fstring remote_machine = "%m";
SE_PRIV se_printop = SE_PRINT_OPERATOR;
bool is_print_op = False;
+ char *remote_machine = talloc_strdup(ctx, "%m");
- standard_sub_basic(current_user_info.smb_name,
- current_user_info.domain,
- remote_machine,sizeof(remote_machine));
+ if (!remote_machine) {
+ return false;
+ }
+ remote_machine = talloc_sub_basic(ctx,
+ current_user_info.smb_name,
+ current_user_info.domain,
+ remote_machine);
+ if (!remote_machine) {
+ return false;
+ }
- slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
+ command = talloc_asprintf(ctx,
+ "%s \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
cmd, printer->info_2->printername, printer->info_2->sharename,
printer->info_2->portname, printer->info_2->drivername,
printer->info_2->location, printer->info_2->comment, remote_machine);
+ if (!command) {
+ return false;
+ }
if ( token )
is_print_op = user_has_privileges( token, &se_printop );
DEBUGADD(10,("returned [%d]\n", ret));
+ TALLOC_FREE(command);
+ TALLOC_FREE(remote_machine);
+
if ( ret != 0 ) {
if (fd != -1)
close(fd);
numlines = 0;
/* Get lines and convert them back to dos-codepage */
- qlines = fd_lines_load(fd, &numlines, 0);
+ qlines = fd_lines_load(fd, &numlines, 0, NULL);
DEBUGADD(10,("Lines returned = [%d]\n", numlines));
close(fd);
DEBUGADD(6,("Line[0] = [%s]\n", qlines[0]));
}
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
return True;
}
{
/* add_printer_hook() will call reload_services() */
- if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) {
+ if ( !add_printer_hook(p->mem_ctx, p->pipe_user.nt_user_token, printer) ) {
result = WERR_ACCESS_DENIED;
goto done;
}
switch (command) {
case JOB_CONTROL_CANCEL:
case JOB_CONTROL_DELETE:
- if (print_job_delete(&p->pipe_user, snum, jobid, &errcode)) {
+ if (print_job_delete(p->server_info, snum, jobid, &errcode)) {
errcode = WERR_OK;
}
break;
case JOB_CONTROL_PAUSE:
- if (print_job_pause(&p->pipe_user, snum, jobid, &errcode)) {
+ if (print_job_pause(p->server_info, snum, jobid, &errcode)) {
errcode = WERR_OK;
}
break;
case JOB_CONTROL_RESTART:
case JOB_CONTROL_RESUME:
- if (print_job_resume(&p->pipe_user, snum, jobid, &errcode)) {
+ if (print_job_resume(p->server_info, snum, jobid, &errcode)) {
errcode = WERR_OK;
}
break;
Enumerates all printer drivers at level 1.
****************************************************************************/
-static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
+static WERROR enumprinterdrivers_level1(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
{
int i;
int ndrivers;
Enumerates all printer drivers at level 2.
****************************************************************************/
-static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
+static WERROR enumprinterdrivers_level2(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
{
int i;
int ndrivers;
Enumerates all printer drivers at level 3.
****************************************************************************/
-static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
+static WERROR enumprinterdrivers_level3(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
{
int i;
int ndrivers;
uint32 offered = q_u->offered;
uint32 *needed = &r_u->needed;
uint32 *returned = &r_u->returned;
-
+ const char *cservername;
fstring servername;
fstring architecture;
unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture));
unistr2_to_ascii(servername, &q_u->name, sizeof(servername));
- if ( !is_myname_or_ipaddr( servername ) )
+ cservername = canon_servername(servername);
+
+ if (!is_myname_or_ipaddr(cservername))
return WERR_UNKNOWN_PRINTER_DRIVER;
switch (level) {
case 1:
- return enumprinterdrivers_level1(servername, architecture, buffer, offered, needed, returned);
+ return enumprinterdrivers_level1(cservername, architecture, buffer, offered, needed, returned);
case 2:
- return enumprinterdrivers_level2(servername, architecture, buffer, offered, needed, returned);
+ return enumprinterdrivers_level2(cservername, architecture, buffer, offered, needed, returned);
case 3:
- return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned);
+ return enumprinterdrivers_level3(cservername, architecture, buffer, offered, needed, returned);
default:
return WERR_UNKNOWN_LEVEL;
}
wrapper around the enumer ports command
****************************************************************************/
-WERROR enumports_hook( int *count, char ***lines )
+WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
{
char *cmd = lp_enumports_cmd();
- char **qlines;
- pstring command;
+ char **qlines = NULL;
+ char *command = NULL;
int numlines;
int ret;
int fd;
else {
/* we have a valid enumport command */
- slprintf(command, sizeof(command)-1, "%s \"%d\"", cmd, 1);
+ command = talloc_asprintf(ctx, "%s \"%d\"", cmd, 1);
+ if (!command) {
+ return WERR_NOMEM;
+ }
DEBUG(10,("Running [%s]\n", command));
ret = smbrun(command, &fd);
DEBUG(10,("Returned [%d]\n", ret));
+ TALLOC_FREE(command);
if (ret != 0) {
if (fd != -1) {
close(fd);
}
numlines = 0;
- qlines = fd_lines_load(fd, &numlines, 0);
+ qlines = fd_lines_load(fd, &numlines, 0, NULL);
DEBUGADD(10,("Lines returned = [%d]\n", numlines));
close(fd);
}
char **qlines = NULL;
int numlines = 0;
- result = enumports_hook( &numlines, &qlines );
+ result = enumports_hook(talloc_tos(), &numlines, &qlines );
if (!W_ERROR_IS_OK(result)) {
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
return result;
}
if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
DEBUG(10,("Returning WERR_NOMEM [%s]\n",
dos_errstr(WERR_NOMEM)));
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
return WERR_NOMEM;
}
fill_port_1(&ports[i], qlines[i]);
}
}
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
*returned = numlines;
char **qlines = NULL;
int numlines = 0;
- result = enumports_hook( &numlines, &qlines );
+ result = enumports_hook(talloc_tos(), &numlines, &qlines );
if ( !W_ERROR_IS_OK(result)) {
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
return result;
}
if(numlines) {
if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) {
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
return WERR_NOMEM;
}
}
}
- file_lines_free(qlines);
+ TALLOC_FREE(qlines);
*returned = numlines;
trying to add a printer like this --jerry */
if (*lp_addprinter_cmd() ) {
- if ( !add_printer_hook(p->pipe_user.nt_user_token, printer) ) {
+ if ( !add_printer_hook(p->mem_ctx, p->pipe_user.nt_user_token, printer) ) {
free_a_printer(&printer,2);
return WERR_ACCESS_DENIED;
}
goto done;
}
+ switch(level) {
+ case 3:
+ fstrcpy(driver_name,
+ driver.info_3->name ? driver.info_3->name : "");
+ break;
+ case 6:
+ fstrcpy(driver_name,
+ driver.info_6->name ? driver.info_6->name : "");
+ break;
+ }
+
/*
* I think this is where he DrvUpgradePrinter() hook would be
* be called in a driver's interface DLL on a Windows NT 4.0/2k
static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environment, RPC_BUFFER *buffer, uint32 offered, uint32 *needed)
{
- pstring path;
- pstring long_archi;
- fstring servername;
- char *pservername;
+ char *path = NULL;
+ char *long_archi = NULL;
+ char *servername = NULL;
+ const char *pservername = NULL;
const char *short_archi;
DRIVER_DIRECTORY_1 *info=NULL;
WERROR result = WERR_OK;
+ TALLOC_CTX *ctx = talloc_tos();
- unistr2_to_ascii(servername, name, sizeof(servername));
- unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi));
-
- /* check for beginning double '\'s and that the server
- long enough */
-
- pservername = servername;
- if ( *pservername == '\\' && strlen(servername)>2 ) {
- pservername += 2;
+ servername = unistr2_to_ascii_talloc(ctx, name);
+ if (!servername) {
+ return WERR_NOMEM;
+ }
+ long_archi = unistr2_to_ascii_talloc(ctx, uni_environment);
+ if (!long_archi) {
+ return WERR_NOMEM;
}
- if ( !is_myname_or_ipaddr( pservername ) )
+ pservername = canon_servername(servername);
+
+ if ( !is_myname_or_ipaddr(pservername))
return WERR_INVALID_PARAM;
if (!(short_archi = get_short_archi(long_archi)))
if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL)
return WERR_NOMEM;
- slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi);
+ path = talloc_asprintf(ctx,
+ "\\\\%s\\print$\\%s", pservername, short_archi);
+ if (!path) {
+ result = WERR_NOMEM;
+ goto out;
+ }
DEBUG(4,("printer driver directory: [%s]\n", path));
int snum=0;
WERROR status = WERR_OK;
Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
- pstring valuename;
+ char *valuename = NULL;
+ TALLOC_CTX *ctx = p->mem_ctx;
DEBUG(5,("spoolss_deleteprinterdata\n"));
if (!W_ERROR_IS_OK(status))
return status;
- unistr2_to_ascii(valuename, value, sizeof(valuename));
+ valuename = unistr2_to_ascii_talloc(ctx, value);
+ if (!valuename) {
+ free_a_printer(&printer, 2);
+ return WERR_NOMEM;
+ }
status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename );
mod_a_printer( printer, 2 );
free_a_printer(&printer, 2);
+ TALLOC_FREE(valuename);
return status;
}
/* can't add if builtin */
if (get_a_builtin_ntform(&form->name,&tmpForm)) {
- status = WERR_ALREADY_EXISTS;
+ status = WERR_FILE_EXISTS;
goto done;
}
int snum=0;
WERROR status = WERR_OK;
Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
- pstring valuename, keyname;
+ char *valuename = NULL;
+ char *keyname = NULL;
+ TALLOC_CTX *ctx = p->mem_ctx;
DEBUG(5,("spoolss_deleteprinterdataex\n"));
return WERR_ACCESS_DENIED;
}
+ valuename = unistr2_to_ascii_talloc(ctx, value);
+ keyname = unistr2_to_ascii_talloc(ctx, key);
+ if (!valuename || !keyname) {
+ return WERR_NOMEM;
+ }
+
status = get_a_printer(Printer, &printer, 2, lp_const_servicename(snum));
if (!W_ERROR_IS_OK(status))
return status;
- unistr2_to_ascii(valuename, value, sizeof(valuename));
- unistr2_to_ascii(keyname, key, sizeof(keyname));
-
status = delete_printer_dataex( printer, keyname, valuename );
if ( W_ERROR_IS_OK(status) )
/* copy data into the reply */
- r_u->ctr.size = r_u->needed;
+ /* mz: Vista x64 returns 0x6f7 (The stub received bad data), if the
+ response buffer size is != the offered buffer size
+
+ r_u->ctr.size = r_u->needed;
+ */
+ r_u->ctr.size = in_size;
r_u->ctr.size_of_array = r_u->returned;
r_u->ctr.values = enum_values;
-
-
done:
if ( printer )
free_a_printer(&printer, 2);
/****************************************************************************
****************************************************************************/
-static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, char *name)
+static void fill_printprocessordirectory_1(PRINTPROCESSOR_DIRECTORY_1 *info, const char *name)
{
init_unistr(&info->name, name);
}
uint32 offered,
uint32 *needed)
{
- pstring path;
- pstring long_archi;
+ char *long_archi = NULL;
PRINTPROCESSOR_DIRECTORY_1 *info=NULL;
WERROR result = WERR_OK;
+ TALLOC_CTX *ctx = talloc_tos();
- unistr2_to_ascii(long_archi, environment, sizeof(long_archi));
+ long_archi = unistr2_to_ascii_talloc(ctx, environment);
+ if (!long_archi) {
+ return WERR_NOMEM;
+ }
if (!get_short_archi(long_archi))
return WERR_INVALID_ENVIRONMENT;
if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL)
return WERR_NOMEM;
- pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
-
- fill_printprocessordirectory_1(info, path);
+ fill_printprocessordirectory_1(info, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
*needed += spoolss_size_printprocessordirectory_info_1(info);
RPC_BUFFER *out, uint32 *needed )
{
NT_PORT_DATA_1 port1;
- pstring device_uri;
+ TALLOC_CTX *ctx = talloc_tos();
+ char *device_uri = NULL;
ZERO_STRUCT( port1 );
switch ( port1.protocol ) {
case PORT_PROTOCOL_DIRECT:
- pstr_sprintf( device_uri, "socket://%s:%d/", port1.hostaddr, port1.port );
+ device_uri = talloc_asprintf(ctx,
+ "socket://%s:%d/", port1.hostaddr, port1.port );
break;
case PORT_PROTOCOL_LPR:
- pstr_sprintf( device_uri, "lpr://%s/%s", port1.hostaddr, port1.queue );
+ device_uri = talloc_asprintf(ctx,
+ "lpr://%s/%s", port1.hostaddr, port1.queue );
break;
default:
return WERR_UNKNOWN_PORT;
}
- return add_port_hook( token, port1.name, device_uri );
+ if (!device_uri) {
+ return WERR_NOMEM;
+ }
+
+ return add_port_hook(ctx, token, port1.name, device_uri );
}
/*******************************************************************