mirror of
https://github.com/samba-team/samba.git
synced 2025-01-11 05:18:09 +03:00
Added Michael Sweet's CUPS patch to call directly into the CUPS backend.
Parameterises the printing functions so other backends can be plugged
directly in (this is a good thing :-).
Jeremy.
(This used to be commit c0345bbaed
)
This commit is contained in:
parent
977e0be9b3
commit
65d35749b7
@ -190,9 +190,11 @@ SMBD_OBJ1 = smbd/server.o smbd/files.o smbd/chgpasswd.o smbd/connection.o \
|
||||
smbd/process.o smbd/service.o smbd/error.o \
|
||||
printing/printfsp.o lib/util_seaccess.o smbd/srvstr.o
|
||||
|
||||
PRINTING_OBJ = printing/pcap.o printing/print_svid.o printing/print_cups.o printing/load.o
|
||||
PRINTING_OBJ = printing/pcap.o printing/print_svid.o \
|
||||
printing/print_cups.o printing/print_generic.o \
|
||||
printing/lpq_parse.o printing/load.o
|
||||
|
||||
PRINTBACKEND_OBJ = printing/printing.o printing/lpq_parse.o printing/nt_printing.o
|
||||
PRINTBACKEND_OBJ = printing/printing.o printing/nt_printing.o
|
||||
|
||||
MSDFS_OBJ = msdfs/msdfs.o
|
||||
|
||||
|
@ -1068,16 +1068,22 @@ static void init_printer_values(void)
|
||||
break;
|
||||
|
||||
case PRINT_CUPS:
|
||||
string_set(&sDefault.szLpqcommand,
|
||||
"/usr/bin/lpstat -o%p");
|
||||
string_set(&sDefault.szLprmcommand,
|
||||
"/usr/bin/cancel %p-%j");
|
||||
string_set(&sDefault.szPrintcommand,
|
||||
"/usr/bin/lp -d%p -oraw %s; rm %s");
|
||||
string_set(&sDefault.szQueuepausecommand,
|
||||
"/usr/bin/disable %p");
|
||||
string_set(&sDefault.szQueueresumecommand,
|
||||
"/usr/bin/enable %p");
|
||||
string_set(&Globals.szPrintcapname, "cups");
|
||||
#ifdef HAVE_LIBCUPS
|
||||
string_set(&sDefault.szLpqcommand, "");
|
||||
string_set(&sDefault.szLprmcommand, "");
|
||||
string_set(&sDefault.szPrintcommand, "");
|
||||
string_set(&sDefault.szLppausecommand, "");
|
||||
string_set(&sDefault.szLpresumecommand, "");
|
||||
string_set(&sDefault.szQueuepausecommand, "");
|
||||
string_set(&sDefault.szQueueresumecommand, "");
|
||||
#else
|
||||
string_set(&sDefault.szLpqcommand, "/usr/bin/lpstat -o%p");
|
||||
string_set(&sDefault.szLprmcommand, "/usr/bin/cancel %p-%j");
|
||||
string_set(&sDefault.szPrintcommand, "/usr/bin/lp -d%p -oraw %s; rm %s");
|
||||
string_set(&sDefault.szQueuepausecommand, "/usr/bin/disable %p");
|
||||
string_set(&sDefault.szQueueresumecommand, "/usr/bin/enable %p");
|
||||
#endif /* HAVE_LIBCUPS */
|
||||
break;
|
||||
|
||||
case PRINT_SYSV:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,10 +19,13 @@
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "printing.h"
|
||||
|
||||
extern int DEBUGLEVEL;
|
||||
|
||||
/* Current printer interface */
|
||||
struct printif *current_printif = &generic_printif;
|
||||
|
||||
/*
|
||||
the printing backend revolves around a tdb database that stores the
|
||||
SMB view of the print queue
|
||||
@ -37,34 +40,10 @@ extern int DEBUGLEVEL;
|
||||
jobids are assigned when a job starts spooling.
|
||||
*/
|
||||
|
||||
#define NEXT_JOBID(j) ((j+1) % PRINT_MAX_JOBID > 0 ? (j+1) % PRINT_MAX_JOBID : 1)
|
||||
|
||||
|
||||
struct printjob {
|
||||
pid_t pid; /* which process launched the job */
|
||||
int sysjob; /* the system (lp) job number */
|
||||
int fd; /* file descriptor of open file if open */
|
||||
time_t starttime; /* when the job started spooling */
|
||||
int status; /* the status of this job */
|
||||
size_t size; /* the size of the job so far */
|
||||
BOOL spooled; /* has it been sent to the spooler yet? */
|
||||
BOOL smbjob; /* set if the job is a SMB job */
|
||||
fstring filename; /* the filename used to spool the file */
|
||||
fstring jobname; /* the job name given to us by the client */
|
||||
fstring user; /* the user who started the job */
|
||||
fstring qname; /* name of the print queue the job was sent to */
|
||||
};
|
||||
|
||||
/* the open printing.tdb database */
|
||||
static TDB_CONTEXT *tdb;
|
||||
static pid_t local_pid;
|
||||
|
||||
#define PRINT_MAX_JOBID 10000
|
||||
#define UNIX_JOB_START PRINT_MAX_JOBID
|
||||
|
||||
#define PRINT_SPOOL_PREFIX "smbprn."
|
||||
#define PRINT_DATABASE_VERSION 2
|
||||
|
||||
static int get_queue_status(int, print_status_struct *);
|
||||
|
||||
/****************************************************************************
|
||||
@ -92,6 +71,13 @@ BOOL print_backend_init(void)
|
||||
}
|
||||
tdb_unlock_bystring(tdb, sversion);
|
||||
|
||||
/* select the appropriate printing interface... */
|
||||
#ifdef HAVE_LIBCUPS
|
||||
if (strcmp(lp_printcapname(), "cups") == 0)
|
||||
current_printif = &cups_printif;
|
||||
#endif /* HAVE_LIBCUPS */
|
||||
|
||||
/* do NT print initialization... */
|
||||
return nt_printing_init();
|
||||
}
|
||||
|
||||
@ -137,51 +123,6 @@ static BOOL print_job_store(int jobid, struct printjob *pjob)
|
||||
return (tdb_store(tdb, print_key(jobid), d, TDB_REPLACE) == 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
run a given print command
|
||||
a null terminated list of value/substitute pairs is provided
|
||||
for local substitution strings
|
||||
****************************************************************************/
|
||||
static int print_run_command(int snum,char *command,
|
||||
char *outfile,
|
||||
...)
|
||||
{
|
||||
pstring syscmd;
|
||||
char *p, *arg;
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
if (!command || !*command) return -1;
|
||||
|
||||
if (!VALID_SNUM(snum)) {
|
||||
DEBUG(0,("Invalid snum %d for command %s\n", snum, command));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pstrcpy(syscmd, command);
|
||||
|
||||
va_start(ap, outfile);
|
||||
while ((arg = va_arg(ap, char *))) {
|
||||
char *value = va_arg(ap,char *);
|
||||
pstring_sub(syscmd, arg, value);
|
||||
}
|
||||
va_end(ap);
|
||||
|
||||
p = PRINTERNAME(snum);
|
||||
|
||||
pstring_sub(syscmd, "%p", p);
|
||||
standard_sub_snum(snum,syscmd);
|
||||
|
||||
/* Convert script args to unix-codepage */
|
||||
dos_to_unix(syscmd, True);
|
||||
ret = smbrun(syscmd,outfile,False);
|
||||
|
||||
DEBUG(3,("Running the command `%s' gave %d\n",syscmd,ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
parse a file name from the system spooler to generate a jobid
|
||||
****************************************************************************/
|
||||
@ -378,11 +319,7 @@ update the internal database from the system print queue for a queue
|
||||
|
||||
static void print_queue_update(int snum)
|
||||
{
|
||||
char *path = lp_pathname(snum);
|
||||
char *cmd = lp_lpqcommand(snum);
|
||||
char **qlines;
|
||||
pstring tmp_file;
|
||||
int numlines, i, qcount;
|
||||
int i, qcount;
|
||||
print_queue_struct *queue = NULL;
|
||||
print_status_struct status;
|
||||
print_status_struct old_status;
|
||||
@ -446,31 +383,10 @@ static void print_queue_update(int snum)
|
||||
slprintf(cachestr, sizeof(cachestr), "CACHE/%s", printer_name);
|
||||
tdb_store_int(tdb, cachestr, (int)time(NULL));
|
||||
|
||||
slprintf(tmp_file, sizeof(tmp_file), "%s/smblpq.%d", path, local_pid);
|
||||
|
||||
unlink(tmp_file);
|
||||
print_run_command(snum, cmd, tmp_file, NULL);
|
||||
|
||||
numlines = 0;
|
||||
qlines = file_lines_load(tmp_file, &numlines, True);
|
||||
unlink(tmp_file);
|
||||
|
||||
/* turn the lpq output into a series of job structures */
|
||||
qcount = 0;
|
||||
/* get the current queue using the appropriate interface */
|
||||
ZERO_STRUCT(status);
|
||||
if (numlines)
|
||||
queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
|
||||
|
||||
if (queue) {
|
||||
for (i=0; i<numlines; i++) {
|
||||
/* parse the line */
|
||||
if (parse_lpq_entry(snum,qlines[i],
|
||||
&queue[qcount],&status,qcount==0)) {
|
||||
qcount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
file_lines_free(qlines);
|
||||
qcount = (*(current_printif->queue_get))(snum, &queue, &status);
|
||||
|
||||
DEBUG(3, ("%d job%s in queue for %s\n", qcount, (qcount != 1) ?
|
||||
"s" : "", printer_name));
|
||||
@ -658,17 +574,14 @@ static BOOL print_job_delete1(int jobid)
|
||||
pjob->status = LPQ_DELETING;
|
||||
print_job_store(jobid, pjob);
|
||||
|
||||
if (pjob->spooled && pjob->sysjob != -1) {
|
||||
fstring jobstr;
|
||||
if (pjob->spooled && pjob->sysjob != -1)
|
||||
result = (*(current_printif->job_delete))(snum, pjob);
|
||||
|
||||
/* need to delete the spooled entry */
|
||||
slprintf(jobstr, sizeof(jobstr), "%d", pjob->sysjob);
|
||||
result = print_run_command(
|
||||
snum,
|
||||
lp_lprmcommand(snum), NULL,
|
||||
"%j", jobstr,
|
||||
"%T", http_timestring(pjob->starttime),
|
||||
NULL);
|
||||
/* Delete the tdb entry if the delete suceeded or the job hasn't
|
||||
been spooled. */
|
||||
|
||||
if (result == 0) {
|
||||
tdb_delete(tdb, print_key(jobid));
|
||||
}
|
||||
|
||||
return (result == 0);
|
||||
@ -739,17 +652,14 @@ BOOL print_job_pause(struct current_user *user, int jobid, int *errcode)
|
||||
struct printjob *pjob = print_job_find(jobid);
|
||||
int snum, ret = -1;
|
||||
char *printer_name;
|
||||
fstring jobstr;
|
||||
BOOL owner;
|
||||
|
||||
if (!pjob || !user) return False;
|
||||
|
||||
if (!pjob->spooled || pjob->sysjob == -1) return False;
|
||||
|
||||
snum = print_job_snum(jobid);
|
||||
owner = is_owner(user, jobid);
|
||||
|
||||
if (!owner &&
|
||||
if (!is_owner(user, jobid) &&
|
||||
!print_access_check(user, snum, JOB_ACCESS_ADMINISTER)) {
|
||||
DEBUG(3, ("pause denied by security descriptor\n"));
|
||||
*errcode = ERROR_ACCESS_DENIED;
|
||||
@ -757,11 +667,7 @@ BOOL print_job_pause(struct current_user *user, int jobid, int *errcode)
|
||||
}
|
||||
|
||||
/* need to pause the spooled entry */
|
||||
slprintf(jobstr, sizeof(jobstr), "%d", pjob->sysjob);
|
||||
ret = print_run_command(snum,
|
||||
lp_lppausecommand(snum), NULL,
|
||||
"%j", jobstr,
|
||||
NULL);
|
||||
ret = (*(current_printif->job_pause))(snum, pjob);
|
||||
|
||||
if (ret != 0) {
|
||||
*errcode = ERROR_INVALID_PARAMETER;
|
||||
@ -790,7 +696,6 @@ BOOL print_job_resume(struct current_user *user, int jobid, int *errcode)
|
||||
struct printjob *pjob = print_job_find(jobid);
|
||||
char *printer_name;
|
||||
int snum, ret;
|
||||
fstring jobstr;
|
||||
|
||||
if (!pjob || !user) return False;
|
||||
|
||||
@ -805,11 +710,7 @@ BOOL print_job_resume(struct current_user *user, int jobid, int *errcode)
|
||||
return False;
|
||||
}
|
||||
|
||||
slprintf(jobstr, sizeof(jobstr), "%d", pjob->sysjob);
|
||||
ret = print_run_command(snum,
|
||||
lp_lpresumecommand(snum), NULL,
|
||||
"%j", jobstr,
|
||||
NULL);
|
||||
ret = (*(current_printif->job_resume))(snum, pjob);
|
||||
|
||||
if (ret != 0) {
|
||||
*errcode = ERROR_INVALID_PARAMETER;
|
||||
@ -1056,10 +957,6 @@ BOOL print_job_end(int jobid, BOOL normal_close)
|
||||
struct printjob *pjob = print_job_find(jobid);
|
||||
int snum, ret;
|
||||
SMB_STRUCT_STAT sbuf;
|
||||
pstring current_directory;
|
||||
pstring print_directory;
|
||||
char *wd, *p;
|
||||
pstring jobname;
|
||||
|
||||
if (!pjob)
|
||||
return False;
|
||||
@ -1096,30 +993,7 @@ BOOL print_job_end(int jobid, BOOL normal_close)
|
||||
return True;
|
||||
}
|
||||
|
||||
/* we print from the directory path to give the best chance of
|
||||
parsing the lpq output */
|
||||
wd = sys_getwd(current_directory);
|
||||
if (!wd) goto fail;
|
||||
|
||||
pstrcpy(print_directory, pjob->filename);
|
||||
p = strrchr(print_directory,'/');
|
||||
if (!p) goto fail;
|
||||
*p++ = 0;
|
||||
|
||||
if (chdir(print_directory) != 0) goto fail;
|
||||
|
||||
pstrcpy(jobname, pjob->jobname);
|
||||
pstring_sub(jobname, "'", "_");
|
||||
|
||||
/* send it to the system spooler */
|
||||
ret = print_run_command(snum,
|
||||
lp_printcommand(snum), NULL,
|
||||
"%s", p,
|
||||
"%J", jobname,
|
||||
"%f", p,
|
||||
NULL);
|
||||
|
||||
chdir(wd);
|
||||
ret = (*(current_printif->job_submit))(snum, pjob);
|
||||
|
||||
if (ret) goto fail;
|
||||
|
||||
@ -1310,8 +1184,7 @@ BOOL print_queue_pause(struct current_user *user, int snum, int *errcode)
|
||||
return False;
|
||||
}
|
||||
|
||||
ret = print_run_command(snum, lp_queuepausecommand(snum), NULL,
|
||||
NULL);
|
||||
ret = (*(current_printif->queue_pause))(snum);
|
||||
|
||||
if (ret != 0) {
|
||||
*errcode = ERROR_INVALID_PARAMETER;
|
||||
@ -1343,8 +1216,7 @@ BOOL print_queue_resume(struct current_user *user, int snum, int *errcode)
|
||||
return False;
|
||||
}
|
||||
|
||||
ret = print_run_command(snum, lp_queueresumecommand(snum), NULL,
|
||||
NULL);
|
||||
ret = (*(current_printif->queue_resume))(snum);
|
||||
|
||||
if (ret != 0) {
|
||||
*errcode = ERROR_INVALID_PARAMETER;
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Copyright (C) Andrew Tridgell 1992-1997,
|
||||
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
|
||||
* Copyright (C) Paul Ashton 1997.
|
||||
* Copyright (C) Hewlett-Packard Company 1999.
|
||||
* Copyright (C) Marc Jacobsen 1999.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Copyright (C) Andrew Tridgell 1992-1997,
|
||||
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
|
||||
* Copyright (C) Paul Ashton 1997.
|
||||
* Copyright (C) Hewlett-Packard Company 1999.
|
||||
* Copyright (C) Marc Jacobsen 2000.
|
||||
* Copyright (C) Jeremy Allison 2001.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Copyright (C) Andrew Tridgell 1992-1997,
|
||||
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
|
||||
* Copyright (C) Paul Ashton 1997.
|
||||
* Copyright (C) Hewlett-Packard Company 1999.
|
||||
* Copyright (C) Marc Jacobsen 1999.
|
||||
*
|
||||
* Split into interface and implementation modules by,
|
||||
*
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Copyright (C) Andrew Tridgell 1992-1997,
|
||||
* Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
|
||||
* Copyright (C) Paul Ashton 1997.
|
||||
* Copyright (C) Hewlett-Packard Company 1999.
|
||||
* Copyright (C) Marc Jacobsen 1999.
|
||||
* Copyright (C) Jeremy Allison 2001.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
Loading…
Reference in New Issue
Block a user