mirror of
https://github.com/samba-team/samba.git
synced 2025-01-26 10:04:02 +03:00
Added print job substitutions for %{printername}, %{sharename} and %{portname}
from the NT printer tdb. Also added checks for time restrictions before allowing a job to print. Jeremy.
This commit is contained in:
parent
c0648c981e
commit
8cfb55e81a
@ -285,4 +285,9 @@ typedef struct _form
|
||||
UNISTR2 name;
|
||||
} FORM;
|
||||
*/
|
||||
|
||||
#ifndef SAMBA_PRINTER_PORT_NAME
|
||||
#define SAMBA_PRINTER_PORT_NAME "Samba Printer Port"
|
||||
#endif
|
||||
|
||||
#endif /* NT_PRINTING_H_ */
|
||||
|
@ -1686,6 +1686,7 @@ BOOL unlink_specific_param_if_exist(NT_PRINTER_INFO_LEVEL_2 *info_2, NT_PRINTER_
|
||||
NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename);
|
||||
NT_DEVICEMODE *dup_nt_devicemode(NT_DEVICEMODE *nt_devicemode);
|
||||
void free_nt_devicemode(NT_DEVICEMODE **devmode_ptr);
|
||||
void get_printer_subst_params(int snum, fstring *printername, fstring *sharename, fstring *portname);
|
||||
uint32 add_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level);
|
||||
uint32 get_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level, fstring sharename);
|
||||
uint32 free_a_printer(NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level);
|
||||
@ -1701,6 +1702,7 @@ uint32 nt_printing_setsec(char *printername, SEC_DESC_BUF *secdesc_ctr);
|
||||
BOOL nt_printing_getsec(char *printername, SEC_DESC_BUF **secdesc_ctr);
|
||||
BOOL print_access_check(struct current_user *user, int snum,
|
||||
uint32 required_access);
|
||||
BOOL print_time_access_check(int snum);
|
||||
#endif
|
||||
|
||||
/*The following definitions come from printing/pcap.c */
|
||||
|
@ -1380,7 +1380,7 @@ static uint32 get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstrin
|
||||
|
||||
fstrcpy(info.servername, global_myname);
|
||||
fstrcpy(info.printername, sharename);
|
||||
fstrcpy(info.portname, sharename);
|
||||
fstrcpy(info.portname, SAMBA_PRINTER_PORT_NAME);
|
||||
fstrcpy(info.drivername, lp_printerdriver(snum));
|
||||
pstrcpy(info.comment, "");
|
||||
fstrcpy(info.printprocessor, "winprint");
|
||||
@ -1398,10 +1398,8 @@ static uint32 get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstrin
|
||||
if ((info.devmode = construct_nt_devicemode(info.printername)) == NULL)
|
||||
goto fail;
|
||||
|
||||
#if 1
|
||||
if (!nt_printing_getsec(sharename, &info.secdesc_buf))
|
||||
goto fail;
|
||||
#endif
|
||||
|
||||
*info_ptr = (NT_PRINTER_INFO_LEVEL_2 *)memdup(&info, sizeof(info));
|
||||
if (! *info_ptr) {
|
||||
@ -1438,7 +1436,8 @@ static uint32 get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstring sharen
|
||||
|
||||
dbuf = tdb_fetch(tdb, kbuf);
|
||||
#if 1 /* JRATEST */
|
||||
if (!dbuf.dptr) return get_a_printer_2_default(info_ptr, sharename);
|
||||
if (!dbuf.dptr)
|
||||
return get_a_printer_2_default(info_ptr, sharename);
|
||||
#else
|
||||
if (!dbuf.dptr) return 1;
|
||||
#endif
|
||||
@ -1543,13 +1542,32 @@ static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level)
|
||||
return (success);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Get the parameters we can substitute in an NT print job.
|
||||
****************************************************************************/
|
||||
|
||||
void get_printer_subst_params(int snum, fstring *printername, fstring *sharename, fstring *portname)
|
||||
{
|
||||
NT_PRINTER_INFO_LEVEL *printer = NULL;
|
||||
|
||||
**printername = **sharename = **portname = '\0';
|
||||
|
||||
if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
|
||||
return;
|
||||
|
||||
fstrcpy(*printername, printer->info_2->printername);
|
||||
fstrcpy(*sharename, printer->info_2->sharename);
|
||||
fstrcpy(*portname, printer->info_2->portname);
|
||||
|
||||
free_a_printer(&printer, 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* The function below are the high level ones.
|
||||
* only those ones must be called from the spoolss code.
|
||||
* JFM.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
****************************************************************************/
|
||||
uint32 add_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level)
|
||||
@ -1827,10 +1845,10 @@ BOOL get_specific_param(NT_PRINTER_INFO_LEVEL printer, uint32 level,
|
||||
return (False);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
store a security desc for a printer
|
||||
Store a security desc for a printer.
|
||||
****************************************************************************/
|
||||
|
||||
uint32 nt_printing_setsec(char *printername, SEC_DESC_BUF *secdesc_ctr)
|
||||
{
|
||||
SEC_DESC_BUF *new_secdesc_ctr = NULL;
|
||||
@ -2160,4 +2178,34 @@ BOOL print_access_check(struct current_user *user, int snum,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Check the time parameters allow a print operation.
|
||||
*****************************************************************************/
|
||||
|
||||
BOOL print_time_access_check(int snum)
|
||||
{
|
||||
NT_PRINTER_INFO_LEVEL *printer = NULL;
|
||||
BOOL ok = False;
|
||||
time_t now = time(NULL);
|
||||
struct tm *t;
|
||||
uint32 mins;
|
||||
|
||||
if (get_a_printer(&printer, 2, lp_servicename(snum))!=0)
|
||||
return False;
|
||||
|
||||
if (printer->info_2->starttime == 0 && printer->info_2->untiltime == 0)
|
||||
ok = True;
|
||||
|
||||
t = gmtime(&now);
|
||||
mins = (uint32)t->tm_hour*60 + (uint32)t->tm_min;
|
||||
|
||||
if (mins >= printer->info_2->starttime && mins <= printer->info_2->untiltime)
|
||||
ok = True;
|
||||
|
||||
free_a_printer(&printer, 2);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
#undef OLD_NTDOMAIN
|
||||
|
@ -716,8 +716,9 @@ int print_job_start(struct current_user *user, int snum, char *jobname)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
print a file - called on closing the file. This spools the job
|
||||
Print a file - called on closing the file. This spools the job.
|
||||
****************************************************************************/
|
||||
|
||||
BOOL print_job_end(int jobid)
|
||||
{
|
||||
struct printjob *pjob = print_job_find(jobid);
|
||||
@ -728,13 +729,16 @@ BOOL print_job_end(int jobid)
|
||||
char *wd, *p;
|
||||
pstring jobname;
|
||||
|
||||
if (!pjob) return False;
|
||||
if (!pjob)
|
||||
return False;
|
||||
|
||||
if (pjob->spooled || pjob->pid != local_pid) return False;
|
||||
if (pjob->spooled || pjob->pid != local_pid)
|
||||
return False;
|
||||
|
||||
snum = print_job_snum(jobid);
|
||||
|
||||
if (sys_fstat(pjob->fd, &sbuf) == 0) pjob->size = sbuf.st_size;
|
||||
if (sys_fstat(pjob->fd, &sbuf) == 0)
|
||||
pjob->size = sbuf.st_size;
|
||||
|
||||
close(pjob->fd);
|
||||
pjob->fd = -1;
|
||||
@ -749,14 +753,17 @@ BOOL print_job_end(int jobid)
|
||||
/* we print from the directory path to give the best chance of
|
||||
parsing the lpq output */
|
||||
wd = sys_getwd(current_directory);
|
||||
if (!wd) return False;
|
||||
if (!wd)
|
||||
return False;
|
||||
|
||||
pstrcpy(print_directory, pjob->filename);
|
||||
p = strrchr(print_directory,'/');
|
||||
if (!p) return False;
|
||||
if (!p)
|
||||
return False;
|
||||
*p++ = 0;
|
||||
|
||||
if (chdir(print_directory) != 0) return False;
|
||||
if (chdir(print_directory) != 0)
|
||||
return False;
|
||||
|
||||
pstrcpy(jobname, pjob->jobname);
|
||||
pstring_sub(jobname, "'", "_");
|
||||
@ -780,10 +787,10 @@ BOOL print_job_end(int jobid)
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
check if the print queue has been updated recently enough
|
||||
Check if the print queue has been updated recently enough.
|
||||
****************************************************************************/
|
||||
|
||||
static BOOL print_cache_expired(int snum)
|
||||
{
|
||||
fstring key;
|
||||
|
@ -28,10 +28,6 @@
|
||||
extern int DEBUGLEVEL;
|
||||
extern pstring global_myname;
|
||||
|
||||
#ifndef SAMBA_PRINTER_PORT_NAME
|
||||
#define SAMBA_PRINTER_PORT_NAME "Samba Printer Port"
|
||||
#endif
|
||||
|
||||
#ifndef MAX_OPEN_PRINTER_EXS
|
||||
#define MAX_OPEN_PRINTER_EXS 50
|
||||
#endif
|
||||
@ -3339,7 +3335,7 @@ static void fill_job_info_1(JOB_INFO_1 *job_info, print_queue_struct *queue,
|
||||
job_info->totalpages=0;
|
||||
job_info->pagesprinted=0;
|
||||
|
||||
make_systemtime(&(job_info->submitted), t);
|
||||
make_systemtime(&job_info->submitted, t);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -707,23 +707,21 @@ static int get_printerdrivernumber(int snum)
|
||||
} else {
|
||||
/* didn't find driver in tdb */
|
||||
|
||||
DEBUG(10,("snum: %d\nlp_printerdriver: [%s]\nlp_driverfile: [%s]\n",
|
||||
DEBUG(10,("snum: %d\nlp_printerdriver: [%s]\nlp_driverfile: [%s]\n",
|
||||
snum, lp_printerdriver(snum), lp_driverfile(snum)));
|
||||
|
||||
lines = file_lines_load(lp_driverfile(snum), NULL);
|
||||
if (!lines) {
|
||||
lines = file_lines_load(lp_driverfile(snum), NULL);
|
||||
if (!lines) {
|
||||
DEBUG(3,("Can't open %s - %s\n", lp_driverfile(snum),strerror(errno)));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* lookup the long printer driver name in the file description */
|
||||
for (i=0;lines[i] && !ok;i++) {
|
||||
p = lines[i];
|
||||
if (next_token(&p,tok,":",sizeof(tok)) &&
|
||||
(strlen(lp_printerdriver(snum)) == strlen(tok)) &&
|
||||
(!strncmp(tok,lp_printerdriver(snum),strlen(lp_printerdriver(snum)))))
|
||||
for (i=0;lines[i] && !ok;i++) {
|
||||
p = lines[i];
|
||||
if (next_token(&p,tok,":",sizeof(tok)) &&
|
||||
(strlen(lp_printerdriver(snum)) == strlen(tok)) &&
|
||||
(!strncmp(tok,lp_printerdriver(snum),strlen(lp_printerdriver(snum)))))
|
||||
ok = True;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -741,7 +739,7 @@ static int get_printerdrivernumber(int snum)
|
||||
i++;
|
||||
|
||||
file_lines_free(lines);
|
||||
return(i);
|
||||
return(i);
|
||||
}
|
||||
|
||||
err:
|
||||
@ -861,10 +859,10 @@ static BOOL api_DosPrintQGetInfo(connection_struct *conn,
|
||||
return(True);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
view list of all print jobs on all queues
|
||||
****************************************************************************/
|
||||
View list of all print jobs on all queues.
|
||||
****************************************************************************/
|
||||
|
||||
static BOOL api_DosPrintQEnum(connection_struct *conn, uint16 vuid, char* param, char* data,
|
||||
int mdrcnt, int mprcnt,
|
||||
char **rdata, char** rparam,
|
||||
|
Loading…
x
Reference in New Issue
Block a user