-#define OLD_NTDOMAIN 1
/*
* Unix SMB/Netbios implementation.
* Version 1.9.
/* and the notify info asked about */
/* that's the central struct */
typedef struct _Printer{
- ubi_dlNode Next;
- ubi_dlNode Prev;
-
- BOOL open;
BOOL document_started;
BOOL page_started;
int jobid; /* jobid in printing backend */
- POLICY_HND printer_hnd;
BOOL printer_type;
union {
fstring handlename;
uint32 counter;
} counter_printer_0;
-static ubi_dlList Printer_list;
static ubi_dlList counter_list;
static struct cli_state cli;
static uint32 smb_connections=0;
-#define OPEN_HANDLE(pnum) ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data,16)==(uint32)sys_getpid()))
-#define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data,16)==sys_getpid()?"OURS":"OTHER"))
+#define OUR_HANDLE(hnd) ((hnd==NULL)?"NULL":(IVAL(hnd->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER"))
/* translate between internal status numbers and NT status numbers */
static int nt_printj_status(int v)
safe_free(sp->ctr.type);
free(sp);
+}
+
+/***************************************************************************
+ Disconnect from the client
+****************************************************************************/
+
+static void srv_spoolss_replycloseprinter(POLICY_HND *handle)
+{
+ uint32 status;
+
+ /* weird if the test succeds !!! */
+ if (smb_connections==0) {
+ DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
+ return;
+ }
+
+ if(!cli_spoolss_reply_close_printer(&cli, handle, &status))
+ DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed.\n"));
+
+ /* if it's the last connection, deconnect the IPC$ share */
+ if (smb_connections==1) {
+ if(!spoolss_disconnect_from_client(&cli))
+ return;
+
+ message_deregister(MSG_PRINTER_NOTIFY);
+ }
+
+ smb_connections--;
+}
+
+/****************************************************************************
+ Functions to free a printer entry datastruct.
+****************************************************************************/
+
+static void free_printer_entry(void *ptr)
+{
+ Printer_entry *Printer = (Printer_entry *)ptr;
+
+ if (Printer->notify.client_connected==True)
+ srv_spoolss_replycloseprinter(&Printer->notify.client_hnd);
+ Printer->notify.flags=0;
+ Printer->notify.options=0;
+ Printer->notify.localmachine[0]='\0';
+ Printer->notify.printerlocal=0;
+ free_spool_notify_option(&Printer->notify.option);
+ Printer->notify.option=NULL;
+ Printer->notify.client_connected=False;
+
+ safe_free(Printer);
}
/****************************************************************************
return new_sp;
}
-/****************************************************************************
- initialise printer handle states...
-****************************************************************************/
-void init_printer_hnd(void)
-{
- ubi_dlInitList(&Printer_list);
- ubi_dlInitList(&counter_list);
-}
-
/****************************************************************************
Return a user struct for a pipe user.
****************************************************************************/
return user;
}
-/****************************************************************************
- create a unique printer handle
-****************************************************************************/
-static void create_printer_hnd(POLICY_HND *hnd)
-{
- static uint32 prt_hnd_low = 0;
- static uint32 prt_hnd_high = 0;
-
- if (hnd == NULL) return;
-
- /* i severely doubt that prt_hnd_high will ever be non-zero... */
- prt_hnd_low++;
- if (prt_hnd_low == 0) prt_hnd_high++;
-
- SIVAL(hnd->data, 0 , 0x0); /* first bit must be null */
- SIVAL(hnd->data, 4 , prt_hnd_low ); /* second bit is incrementing */
- SIVAL(hnd->data, 8 , prt_hnd_high); /* second bit is incrementing */
- SIVAL(hnd->data, 12, time(NULL)); /* something random */
- SIVAL(hnd->data, 16, sys_getpid()); /* something more random */
-}
-
/****************************************************************************
find printer index by handle
****************************************************************************/
-static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
-{
- Printer_entry *find_printer;
-
- find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
- for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
-
- if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) {
- DEBUG(4,("Found printer handle \n"));
- /*dump_data(4, hnd->data, sizeof(hnd->data));*/
- return find_printer;
- }
- }
-
- DEBUG(3,("Whoops, Printer handle not found: "));
- /*dump_data(4, hnd->data, sizeof(hnd->data));*/
- return NULL;
-}
-
-/****************************************************************************
- clear an handle
-****************************************************************************/
-static void clear_handle(POLICY_HND *hnd)
+static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd)
{
- ZERO_STRUCTP(hnd);
-}
-
-/***************************************************************************
- Disconnect from the client
-****************************************************************************/
-static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle)
-{
- uint32 status;
-
- /* weird if the test succeds !!! */
- if (smb_connections==0) {
- DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
- return False;
- }
-
- if(!cli_spoolss_reply_close_printer(&cli, handle, &status))
- return False;
+ Printer_entry *find_printer = NULL;
- /* if it's the last connection, deconnect the IPC$ share */
- if (smb_connections==1) {
- if(!spoolss_disconnect_from_client(&cli))
- return False;
-
- message_deregister(MSG_PRINTER_NOTIFY);
+ if(!find_policy_by_hnd(p,hnd,(void **)&find_printer)) {
+ DEBUG(3,("find_printer_index_by_hnd: Printer handle not found: "));
+ return NULL;
}
- smb_connections--;
-
- return True;
+ return find_printer;
}
/****************************************************************************
close printer index by handle
****************************************************************************/
-static BOOL close_printer_handle(POLICY_HND *hnd)
+static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd)
{
- Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("close_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd)));
return False;
}
- if (Printer->notify.client_connected==True)
- if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd))
- return ERROR_INVALID_HANDLE;
-
- Printer->open=False;
- Printer->notify.flags=0;
- Printer->notify.options=0;
- Printer->notify.localmachine[0]='\0';
- Printer->notify.printerlocal=0;
- free_spool_notify_option(&Printer->notify.option);
- Printer->notify.client_connected=False;
-
- clear_handle(hnd);
-
- ubi_dlRemThis(&Printer_list, Printer);
-
- safe_free(Printer);
+ close_policy_hnd(p, hnd);
return True;
}
/****************************************************************************
delete a printer given a handle
****************************************************************************/
-static uint32 delete_printer_handle(POLICY_HND *hnd)
+static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
{
- Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd)));
return ERROR_INVALID_HANDLE;
}
/****************************************************************************
return the snum of a printer corresponding to an handle
****************************************************************************/
-static BOOL get_printer_snum(POLICY_HND *hnd, int *number)
+static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number)
{
- Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("get_printer_snum: Invalid handle (%s)\n", OUR_HANDLE(hnd)));
return False;
}
/****************************************************************************
set printer handle type.
****************************************************************************/
-static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
+static BOOL set_printer_hnd_accesstype(pipes_struct *p, POLICY_HND *hnd, uint32 access_required)
{
- Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("set_printer_hnd_accesstype: Invalid handle (%s)", OUR_HANDLE(hnd)));
return False;
}
find first available printer slot. creates a printer handle for you.
****************************************************************************/
-static BOOL open_printer_hnd(POLICY_HND *hnd, char *name)
+static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name)
{
Printer_entry *new_printer;
DEBUG(10,("open_printer_hnd: name [%s]\n", name));
- clear_handle(hnd);
- create_printer_hnd(hnd);
if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
return False;
ZERO_STRUCTP(new_printer);
- new_printer->open = True;
new_printer->notify.option=NULL;
- memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd));
-
- ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
+ if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) {
+ safe_free(new_printer);
+ return False;
+ }
if (!set_printer_hnd_printertype(new_printer, name)) {
- close_printer_handle(hnd);
+ close_printer_handle(p, hnd);
return False;
}
if (!set_printer_hnd_name(new_printer, name)) {
- close_printer_handle(hnd);
+ close_printer_handle(p, hnd);
return False;
}
- DEBUG(5, ("%d printer handles active\n",
- (int)ubi_dlCount(&Printer_list)));
+ DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles.count ));
return True;
}
/********************************************************************
Return True is the handle is a print server.
********************************************************************/
-static BOOL handle_is_printserver(const POLICY_HND *handle)
+
+static BOOL handle_is_printserver(pipes_struct *p, POLICY_HND *handle)
{
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p,handle);
- if (!OPEN_HANDLE(Printer))
+ if (!Printer)
return False;
if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
/***************************************************************************
receive the notify message
****************************************************************************/
+
void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len)
{
fstring printer;
uint32 status;
- Printer_entry *find_printer;
+ struct pipes_struct *p;
*printer = '\0';
fstrcpy(printer,buf);
DEBUG(10,("srv_spoolss_receive_message: Got message about printer %s\n", printer ));
- find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
+ /* We need to enumerate all our pipes and all printers on them. */
+ for ( p = get_first_pipe(); p; get_next_pipe(p)) {
+ struct policy *pol;
- /* Iterate the printer list. */
- for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
+ if (!strequal(p->name, "spoolss"))
+ continue;
- /*
- * if the entry is the given printer or if it's a printerserver
- * we send the message
- */
+ /* Iterate the printer list on this pipe. */
+ for (pol = p->pipe_handles.Policy; pol; pol = pol->next ) {
+ Printer_entry *find_printer = (Printer_entry *)pol->data_ptr;
- if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER)
- if (strcmp(find_printer->dev.handlename, printer))
+ if (!find_printer)
continue;
- if (find_printer->notify.client_connected==True)
- cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status);
+ /*
+ * if the entry is the given printer or if it's a printerserver
+ * we send the message
+ */
+
+ if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER)
+ if (strcmp(find_printer->dev.handlename, printer))
+ continue;
+ if (find_printer->notify.client_connected==True)
+ cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status);
+ }
}
}
/***************************************************************************
send a notify event
****************************************************************************/
-static BOOL srv_spoolss_sendnotify(POLICY_HND *handle)
+static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle)
{
fstring printer;
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("srv_spoolss_sendnotify: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return False;
}
DEBUGADD(3,("checking name: %s\n",name));
- if (!open_printer_hnd(handle, name))
+ if (!open_printer_hnd(p, handle, name))
return ERROR_INVALID_PRINTER_NAME;
/*
set_printer_hnd_datatype(handle, "");
*/
- if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
- close_printer_handle(handle);
+ if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) {
+ close_printer_handle(p, handle);
return ERROR_ACCESS_DENIED;
}
get_current_user(&user, p);
- if (handle_is_printserver(handle)) {
+ if (handle_is_printserver(p, handle)) {
if (printer_default->access_required == 0) {
return NT_STATUS_NO_PROBLEMO;
}
snum = -1;
if (!lp_ms_add_printer_wizard()) {
- close_printer_handle(handle);
+ close_printer_handle(p, handle);
return ERROR_ACCESS_DENIED;
}
else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) {
return NT_STATUS_NO_PROBLEMO;
}
else {
- close_printer_handle(handle);
+ close_printer_handle(p, handle);
return ERROR_ACCESS_DENIED;
}
}
/* NT doesn't let us connect to a printer if the connecting user
doesn't have print permission. */
+ if (!get_printer_snum(p, handle, &snum))
+ return ERROR_INVALID_HANDLE;
+
/* map an empty access mask to the minimum access mask */
if (printer_default->access_required == 0x0)
printer_default->access_required = PRINTER_ACCESS_USE;
- if (!get_printer_snum(handle, &snum))
- return ERROR_INVALID_HANDLE;
-
if (!print_access_check(&user, snum, printer_default->access_required)) {
DEBUG(3, ("access DENIED for printer open\n"));
- close_printer_handle(handle);
+ close_printer_handle(p, handle);
return ERROR_ACCESS_DENIED;
}
if (printer_default->devmode_cont.devmode != NULL) {
result = printer_write_default_dev( snum, printer_default);
if (result != 0) {
- close_printer_handle(handle);
+ close_printer_handle(p, handle);
return result;
}
}
* _spoolss_enddocprinter_internal.
********************************************************************/
-static uint32 _spoolss_enddocprinter_internal(POLICY_HND *handle)
+static uint32 _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle)
{
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
{
POLICY_HND *handle = &q_u->handle;
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
if (Printer && Printer->document_started)
- _spoolss_enddocprinter_internal(handle); /* print job was not closed */
+ _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle));
- if (!close_printer_handle(handle))
+ if (!close_printer_handle(p, handle))
return ERROR_INVALID_HANDLE;
return NT_STATUS_NO_PROBLEMO;
{
POLICY_HND *handle = &q_u->handle;
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
uint32 result;
if (Printer && Printer->document_started)
- _spoolss_enddocprinter_internal(handle); /* print job was not closed */
+ _spoolss_enddocprinter_internal(p, handle); /* print job was not closed */
memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle));
- result = delete_printer_handle(handle);
+ result = delete_printer_handle(p, handle);
if (result == ERROR_SUCCESS) {
- srv_spoolss_sendnotify(handle);
+ srv_spoolss_sendnotify(p, handle);
}
return result;
/********************************************************************
GetPrinterData on a printer server Handle.
********************************************************************/
-
static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32 *type, uint8 **data, uint32 *needed, uint32 in_size)
{
int i;
pstring string="You are using a Samba server";
*type = 0x1;
*needed = 2*(strlen(string)+1);
- if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+ if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
return False;
+ memset(*data, 0, (*needed > in_size) ? *needed:in_size);
/* it's done by hand ready to go on the wire */
for (i=0; i<strlen(string); i++) {
pstring string="Windows NT x86";
*type = 0x1;
*needed = 2*(strlen(string)+1);
- if((*data = (uint8 *)talloc_zero( ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+ if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
return False;
+ memset(*data, 0, (*needed > in_size) ? *needed:in_size);
for (i=0; i<strlen(string); i++) {
(*data)[2*i]=string[i];
(*data)[2*i+1]='\0';
/********************************************************************
GetPrinterData on a printer Handle.
********************************************************************/
-static BOOL getprinterdata_printer(TALLOC_CTX *ctx, POLICY_HND *handle,
+static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND *handle,
fstring value, uint32 *type,
uint8 **data, uint32 *needed, uint32 in_size )
{
int snum=0;
uint8 *idata=NULL;
uint32 len;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
DEBUG(5,("getprinterdata_printer\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("getprinterdata_printer: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return False;
}
- if(!get_printer_snum(handle, &snum))
+ if(!get_printer_snum(p, handle, &snum))
return False;
if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
DEBUG(5,("getprinterdata_printer:allocating %d\n", in_size));
if (in_size) {
- if((*data = (uint8 *)talloc_zero(ctx, in_size *sizeof(uint8) )) == NULL) {
+ if((*data = (uint8 *)talloc(ctx, in_size *sizeof(uint8) )) == NULL) {
return False;
}
+ memset(*data, 0, in_size *sizeof(uint8));
/* copy the min(in_size, len) */
memcpy(*data, idata, (len>in_size)?in_size:len *sizeof(uint8));
} else {
fstring value;
BOOL found=False;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
/*
* Reminder: when it's a string, the length is in BYTES
DEBUG(4,("_spoolss_getprinterdata\n"));
- if (!OPEN_HANDLE(Printer)) {
- if((*data=(uint8 *)talloc_zero(p->mem_ctx, 4*sizeof(uint8))) == NULL)
+ if (!Printer) {
+ if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
unistr2_to_ascii(value, valuename, sizeof(value)-1);
- if (handle_is_printserver(handle))
+ if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER)
found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size);
else
- found= getprinterdata_printer(p->mem_ctx, handle, value, type, data, needed, *out_size);
+ found= getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size);
if (found==False) {
DEBUG(5, ("value not found, allocating %d\n", *out_size));
/* store the notify value in the printer struct */
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
Printer->notify.flags=flags;
+ Printer->notify.options=options;
Printer->notify.printerlocal=printerlocal;
if (Printer->notify.option)
free_spool_notify_option(&Printer->notify.option);
- Printer->notify.options=options;
Printer->notify.option=dup_spool_notify_option(option);
unistr2_to_ascii(Printer->notify.localmachine, localmachine, sizeof(Printer->notify.localmachine)-1);
NT_PRINTER_INFO_LEVEL *printer,
TALLOC_CTX *mem_ctx)
{
- int count;
-
print_queue_struct *q=NULL;
print_status_struct status;
memset(&status, 0, sizeof(status));
- count = print_queue_status(snum, &q, &status);
+ print_queue_status(snum, &q, &status);
data->notify_data.value[0]=(uint32) status.status;
safe_free(q);
}
{
struct tm *t;
uint32 len;
+ SYSTEMTIME st;
t=gmtime(&queue->time);
len = sizeof(SYSTEMTIME);
- data->notify_data.data.length = len;
+ data->notify_data.data.length = len/2 - 1;
data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
if (!data->notify_data.data.string) {
return;
}
- make_systemtime((SYSTEMTIME*)(data->notify_data.data.string), t);
+ make_systemtime(&st, t);
+ memcpy(data->notify_data.data.string,&st,len);
}
#define END 65535
SPOOL_NOTIFY_INFO_DATA *current_data;
NT_PRINTER_INFO_LEVEL *printer = NULL;
print_queue_struct *queue=NULL;
- size_t realloc_size = 0;
- SPOOL_NOTIFY_INFO_DATA *info_data_ptr = NULL;
type=option_type->type;
if (!search_notify(type, field, &j) )
continue;
- realloc_size = (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA);
- if((info_data_ptr=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info_data_ptr, realloc_size)) == NULL) {
+ if((info->data=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
return False;
}
- current_data=&info_data_ptr[info->count];
+ current_data=&info->data[info->count];
construct_info_data(current_data, type, field, id);
info->count++;
}
- if (realloc_size)
- info->data = talloc_memdup(mem_ctx, info_data_ptr, realloc_size);
- else
- info->data = NULL;
-
- safe_free(info_data_ptr);
free_a_printer(&printer, 2);
return True;
}
* that's the print server case, the printer case is even worse.
*/
-
-
/*******************************************************************
*
* enumerate all printers on the printserver
* fill a notify_info struct with info asked
*
********************************************************************/
-static uint32 printserver_notify_info(const POLICY_HND *hnd,
+
+static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd,
SPOOL_NOTIFY_INFO *info,
TALLOC_CTX *mem_ctx)
{
int snum;
- Printer_entry *Printer=find_printer_index_by_hnd(hnd);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
int n_services=lp_numservices();
int i;
uint32 id;
for (snum=0; snum<n_services; snum++)
if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) )
- if (construct_notify_printer_info(info, snum, option_type, id, mem_ctx))
+ if (construct_notify_printer_info
+ (info, snum, option_type, id, mem_ctx))
id++;
}
* fill a notify_info struct with info asked
*
********************************************************************/
-static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info,
+static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info,
TALLOC_CTX *mem_ctx)
{
int snum;
- Printer_entry *Printer=find_printer_index_by_hnd(hnd);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
int i;
uint32 id;
SPOOL_NOTIFY_OPTION *option;
info->data=NULL;
info->count=0;
- get_printer_snum(hnd, &snum);
+ get_printer_snum(p, hnd, &snum);
for (i=0; i<option->count; i++) {
option_type=&option->ctr.type[i];
switch ( option_type->type ) {
case PRINTER_NOTIFY_TYPE:
- if(construct_notify_printer_info(info, snum, option_type, id, mem_ctx))
+ if(construct_notify_printer_info(info, snum,
+ option_type, id,
+ mem_ctx))
id--;
break;
memset(&status, 0, sizeof(status));
count = print_queue_status(snum, &queue, &status);
- if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
+ if (get_a_printer(&printer, 2,
+ lp_servicename(snum)) != 0)
goto done;
for (j=0; j<count; j++) {
/* SPOOL_NOTIFY_OPTION *option = q_u->option; - notused. */
SPOOL_NOTIFY_INFO *info = &r_u->info;
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
uint32 result = ERROR_INVALID_HANDLE;
/* we always have a NOTIFY_INFO struct */
r_u->info_ptr=0x1;
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n",
OUR_HANDLE(handle)));
goto done;
switch (Printer->printer_type) {
case PRINTER_HANDLE_IS_PRINTSERVER:
- result = printserver_notify_info(handle, info,
- p->mem_ctx);
+ result = printserver_notify_info(p, handle, info, p->mem_ctx);
break;
case PRINTER_HANDLE_IS_PRINTER:
- result = printer_notify_info(handle, info, p->mem_ctx);
+ result = printer_notify_info(p, handle, info, p->mem_ctx);
break;
}
*needed=0;
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p, handle, &snum))
return ERROR_INVALID_HANDLE;
switch (level) {
pstrcpy(servername, global_myname);
unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p, handle, &snum))
return ERROR_INVALID_HANDLE;
switch (level) {
{
POLICY_HND *handle = &q_u->handle;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
- if (OPEN_HANDLE(Printer)) {
+ if (Printer) {
Printer->page_started=True;
return 0x0;
}
{
POLICY_HND *handle = &q_u->handle;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
int snum;
pstring jobname;
fstring datatype;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
struct current_user user;
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
}
/* get the share number of the printer */
- if (!get_printer_snum(handle, &snum)) {
+ if (!get_printer_snum(p, handle, &snum)) {
return ERROR_INVALID_HANDLE;
}
{
POLICY_HND *handle = &q_u->handle;
- return _spoolss_enddocprinter_internal(handle);
+ return _spoolss_enddocprinter_internal(p, handle);
}
/****************************************************************************
uint8 *buffer = q_u->buffer;
uint32 *buffer_written = &q_u->buffer_size2;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle)));
r_u->buffer_written = q_u->buffer_size2;
return ERROR_INVALID_HANDLE;
{
struct current_user user;
int snum, errcode = ERROR_INVALID_FUNCTION;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
get_current_user(&user, p);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p, handle, &snum))
return ERROR_INVALID_HANDLE;
switch (command) {
uint32 result;
int snum;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer) || !get_printer_snum(handle, &snum)) {
+ if (!Printer || !get_printer_snum(p, handle, &snum)) {
DEBUG(0,("update_printer_sec: Invalid handle (%s)\n",
OUR_HANDLE(handle)));
* when updating a printer description
********************************************************************/
-static uint32 update_printer(POLICY_HND *handle, uint32 level,
+static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level,
const SPOOL_PRINTER_INFO_LEVEL *info,
DEVICEMODE *devmode)
{
int snum;
NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
uint32 result;
DEBUG(8,("update_printer\n"));
goto done;
}
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
result = ERROR_INVALID_HANDLE;
goto done;
}
- if (!get_printer_snum(handle, &snum)) {
+ if (!get_printer_snum(p, handle, &snum)) {
result = ERROR_INVALID_HANDLE;
goto done;
}
free_a_printer(&printer, 2);
free_a_printer(&old_printer, 2);
- srv_spoolss_sendnotify(handle);
+ srv_spoolss_sendnotify(p, handle);
return result;
}
SEC_DESC_BUF *secdesc_ctr = q_u->secdesc_ctr;
uint32 command = q_u->command;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
case 0:
return control_printer(handle, command, p);
case 2:
- return update_printer(handle, level, info, devmode_ctr.devmode);
+ return update_printer(p, handle, level, info, devmode_ctr.devmode);
case 3:
return update_printer_sec(handle, level, info, p,
secdesc_ctr);
{
POLICY_HND *handle = &q_u->handle;
- Printer_entry *Printer= find_printer_index_by_hnd(handle);
+ Printer_entry *Printer= find_printer_index_by_hnd(p, handle);
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
if (Printer->notify.client_connected==True)
- if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd))
- return ERROR_INVALID_HANDLE;
+ srv_spoolss_replycloseprinter(&Printer->notify.client_hnd);
Printer->notify.flags=0;
Printer->notify.options=0;
*needed=0;
*returned=0;
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p, handle, &snum))
return ERROR_INVALID_HANDLE;
*returned = print_queue_status(snum, &queue, &prt_status);
memset(&prt_status, 0, sizeof(prt_status));
- if (!get_printer_snum(handle, &snum)) {
+ if (!get_printer_snum(p, handle, &snum)) {
return ERROR_INVALID_HANDLE;
}
return ERROR_INSUFFICIENT_BUFFER;
}
- /* fill the buffer with the form structures */
+ /* fill the buffer with the driver structures */
for (i=0; i<*returned; i++) {
DEBUGADD(6,("adding driver [%d] to buffer\n",i));
new_smb_io_printer_driver_info_1("", buffer, &driver_info_1[i], 0);
/****************************************************************************
****************************************************************************/
-static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
+static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name,
const SPOOL_PRINTER_INFO_LEVEL *info,
uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
uint32 user_switch, const SPOOL_USER_CTR *user,
return ERROR_ACCESS_DENIED;
}
- if (!open_printer_hnd(handle, name)) {
+ if (!open_printer_hnd(p, handle, name)) {
/* Handle open failed - remove addition. */
del_a_printer(printer->info_2->sharename);
free_a_printer(&printer,2);
free_a_printer(&printer,2);
- srv_spoolss_sendnotify(handle);
+ srv_spoolss_sendnotify(p, handle);
return NT_STATUS_NO_PROBLEMO;
}
/* but I know what to do ... */
return ERROR_INVALID_LEVEL;
case 2:
- return spoolss_addprinterex_level_2(uni_srv_name, info,
+ return spoolss_addprinterex_level_2(p, uni_srv_name, info,
unk0, unk1, unk2, unk3,
user_switch, user, handle);
default:
uint32 biggest_valuesize;
uint32 biggest_datasize;
uint32 data_len;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
int snum;
uint8 *data=NULL;
uint32 type;
DEBUG(5,("spoolss_enumprinterdata\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p,handle, &snum))
return ERROR_INVALID_HANDLE;
if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
NT_PRINTER_PARAM *param = NULL, old_param;
int snum=0;
uint32 status = 0x0;
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
DEBUG(5,("spoolss_setprinterdata\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p,handle, &snum))
return ERROR_INVALID_HANDLE;
status = get_a_printer(&printer, 2, lp_servicename(snum));
NT_PRINTER_PARAM param;
int snum=0;
uint32 status = 0x0;
- Printer_entry *Printer=find_printer_index_by_hnd(handle);
+ Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
DEBUG(5,("spoolss_deleteprinterdata\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p, handle, &snum))
return ERROR_INVALID_HANDLE;
if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
int count=0;
nt_forms_struct *list=NULL;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
DEBUG(5,("spoolss_addform\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
int count=0;
uint32 ret = 0;
nt_forms_struct *list=NULL;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
DEBUG(5,("spoolss_deleteform\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
int count=0;
nt_forms_struct *list=NULL;
- Printer_entry *Printer = find_printer_index_by_hnd(handle);
+ Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
DEBUG(5,("spoolss_setform\n"));
- if (!OPEN_HANDLE(Printer)) {
+ if (!Printer) {
DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle)));
return ERROR_INVALID_HANDLE;
}
*needed=0;
- if (!get_printer_snum(handle, &snum))
+ if (!get_printer_snum(p, handle, &snum))
return ERROR_INVALID_HANDLE;
count = print_queue_status(snum, &queue, &prt_status);
return ERROR_INVALID_LEVEL;
}
}
-#undef OLD_NTDOMAIN