summaryrefslogtreecommitdiffstats
path: root/source/printing
diff options
context:
space:
mode:
Diffstat (limited to 'source/printing')
-rw-r--r--source/printing/load.c48
-rw-r--r--source/printing/nt_printing.c69
-rw-r--r--source/printing/pcap.c468
-rw-r--r--source/printing/print_aix.c111
-rw-r--r--source/printing/print_cups.c595
-rw-r--r--source/printing/print_svid.c69
-rw-r--r--source/printing/printing.c3
7 files changed, 601 insertions, 762 deletions
diff --git a/source/printing/load.c b/source/printing/load.c
index 59306aa1047..a925a63e17f 100644
--- a/source/printing/load.c
+++ b/source/printing/load.c
@@ -22,44 +22,29 @@
/***************************************************************************
-auto-load printer services
-***************************************************************************/
-void add_all_printers(void)
-{
- int printers = lp_servicenumber(PRINTERS_NAME);
-
- if (printers < 0) return;
-
- pcap_printer_fn(lp_add_one_printer);
-}
-
-/***************************************************************************
auto-load some homes and printer services
***************************************************************************/
static void add_auto_printers(void)
{
const char *p;
- int printers;
- char *str = SMB_STRDUP(lp_auto_services());
+ int pnum = lp_servicenumber(PRINTERS_NAME);
+ char *str;
- if (!str) return;
-
- printers = lp_servicenumber(PRINTERS_NAME);
+ if (pnum < 0)
+ return;
- if (printers < 0) {
- SAFE_FREE(str);
+ if ((str = SMB_STRDUP(lp_auto_services())) == NULL)
return;
- }
-
- for (p=strtok(str,LIST_SEP);p;p=strtok(NULL,LIST_SEP)) {
- if (lp_servicenumber(p) >= 0) continue;
+
+ for (p = strtok(str, LIST_SEP); p; p = strtok(NULL, LIST_SEP)) {
+ if (lp_servicenumber(p) >= 0)
+ continue;
- if (pcap_printername_ok(p,NULL)) {
- lp_add_printer(p,printers);
- }
+ if (pcap_printername_ok(p))
+ lp_add_printer(p, pnum);
}
- SAFE_FREE(str);
+ SAFE_FREE(str);
}
/***************************************************************************
@@ -67,7 +52,12 @@ load automatic printer services
***************************************************************************/
void load_printers(void)
{
+ if (!pcap_cache_loaded())
+ pcap_cache_reload();
+
add_auto_printers();
- if (lp_load_printers())
- add_all_printers();
+
+ /* load all printcap printers */
+ if (lp_load_printers() && lp_servicenumber(PRINTERS_NAME) >= 0)
+ pcap_printer_fn(lp_add_one_printer);
}
diff --git a/source/printing/nt_printing.c b/source/printing/nt_printing.c
index 3ffedcf1858..d5cf58f54d8 100644
--- a/source/printing/nt_printing.c
+++ b/source/printing/nt_printing.c
@@ -2046,17 +2046,32 @@ static int pack_values(NT_PRINTER_DATA *data, char *buf, int buflen)
handles are not affected.
****************************************************************************/
-uint32 del_a_printer(char *sharename)
+uint32 del_a_printer(const char *sharename)
{
pstring key;
TDB_DATA kbuf;
+ pstring printdb_path;
slprintf(key, sizeof(key)-1, "%s%s", PRINTERS_PREFIX, sharename);
-
kbuf.dptr=key;
kbuf.dsize=strlen(key)+1;
+ tdb_delete(tdb_printers, kbuf);
+ slprintf(key, sizeof(key)-1, "%s%s", SECDESC_PREFIX, sharename);
+ kbuf.dptr=key;
+ kbuf.dsize=strlen(key)+1;
tdb_delete(tdb_printers, kbuf);
+
+ close_all_print_db();
+
+ if (geteuid() == 0) {
+ pstrcpy(printdb_path, lock_path("printing/"));
+ pstrcat(printdb_path, sharename);
+ pstrcat(printdb_path, ".tdb");
+
+ unlink(printdb_path);
+ }
+
return 0;
}
@@ -2899,7 +2914,8 @@ BOOL is_printer_published(Printer_entry *print_hnd, int snum,
return False;
}
- if (regval_size(guid_val) == sizeof(struct uuid))
+ /* fetching printer guids really ought to be a separate function.. */
+ if (guid && regval_size(guid_val) == sizeof(struct uuid))
memcpy(guid, regval_data_p(guid_val), sizeof(struct uuid));
free_a_printer(&printer, 2);
@@ -4790,7 +4806,8 @@ WERROR nt_printing_setsec(const char *printername, SEC_DESC_BUF *secdesc_ctr)
static SEC_DESC_BUF *construct_default_printer_sdb(TALLOC_CTX *ctx)
{
- SEC_ACE ace[3];
+ SEC_ACE ace[5]; /* max number of ace entries */
+ int i = 0;
SEC_ACCESS sa;
SEC_ACL *psa = NULL;
SEC_DESC_BUF *sdb = NULL;
@@ -4801,7 +4818,7 @@ static SEC_DESC_BUF *construct_default_printer_sdb(TALLOC_CTX *ctx)
/* Create an ACE where Everyone is allowed to print */
init_sec_access(&sa, PRINTER_ACE_PRINT);
- init_sec_ace(&ace[0], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED,
sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
/* Make the security descriptor owned by the Administrators group
@@ -4820,20 +4837,38 @@ static SEC_DESC_BUF *construct_default_printer_sdb(TALLOC_CTX *ctx)
}
init_sec_access(&sa, PRINTER_ACE_FULL_CONTROL);
- init_sec_ace(&ace[1], &owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ init_sec_ace(&ace[i++], &owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
sa, SEC_ACE_FLAG_OBJECT_INHERIT |
SEC_ACE_FLAG_INHERIT_ONLY);
init_sec_access(&sa, PRINTER_ACE_FULL_CONTROL);
- init_sec_ace(&ace[2], &owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ init_sec_ace(&ace[i++], &owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
+ /* Add the domain admins group if we are a DC */
+
+ if ( IS_DC ) {
+ DOM_SID domadmins_sid;
+
+ sid_copy(&domadmins_sid, get_global_sam_sid());
+ sid_append_rid(&domadmins_sid, DOMAIN_GROUP_RID_ADMINS);
+
+ init_sec_access(&sa, PRINTER_ACE_FULL_CONTROL);
+ init_sec_ace(&ace[i++], &domadmins_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ sa, SEC_ACE_FLAG_OBJECT_INHERIT |
+ SEC_ACE_FLAG_INHERIT_ONLY);
+
+ init_sec_access(&sa, PRINTER_ACE_FULL_CONTROL);
+ init_sec_ace(&ace[i++], &domadmins_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
+ sa, SEC_ACE_FLAG_CONTAINER_INHERIT);
+ }
+
/* The ACL revision number in rpc_secdesc.h differs from the one
created by NT when setting ACE entries in printer
descriptors. NT4 complains about the property being edited by a
NT5 machine. */
- if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 3, ace)) != NULL) {
+ if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) != NULL) {
psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,
&owner_sid, NULL,
NULL, psa, &sd_size);
@@ -5018,6 +5053,11 @@ void map_printer_permissions(SEC_DESC *sd)
print_job_delete, print_job_pause, print_job_resume,
print_queue_purge
+ Try access control in the following order (for performance reasons):
+ 1) root ans SE_PRINT_OPERATOR can do anything (easy check)
+ 2) check security descriptor (bit comparisons in memory)
+ 3) "printer admins" (may result in numerous calls to winbind)
+
****************************************************************************/
BOOL print_access_check(struct current_user *user, int snum, int access_type)
{
@@ -5028,16 +5068,16 @@ BOOL print_access_check(struct current_user *user, int snum, int access_type)
const char *pname;
TALLOC_CTX *mem_ctx = NULL;
extern struct current_user current_user;
+ SE_PRIV se_printop = SE_PRINT_OPERATOR;
/* If user is NULL then use the current_user structure */
if (!user)
user = &current_user;
- /* Always allow root or printer admins to do anything */
+ /* Always allow root or SE_PRINT_OPERATROR to do anything */
- if (user->uid == 0 ||
- user_in_list(uidtoname(user->uid), lp_printer_admin(snum), user->groups, user->ngroups)) {
+ if ( user->uid == 0 || user_has_privileges(user->nt_user_token, &se_printop ) ) {
return True;
}
@@ -5086,6 +5126,13 @@ BOOL print_access_check(struct current_user *user, int snum, int access_type)
DEBUG(4, ("access check was %s\n", result ? "SUCCESS" : "FAILURE"));
+ /* see if we need to try the printer admin list */
+
+ if ( access_granted == 0 ) {
+ if ( user_in_list(uidtoname(user->uid), lp_printer_admin(snum), user->groups, user->ngroups) )
+ return True;
+ }
+
talloc_destroy(mem_ctx);
if (!result)
diff --git a/source/printing/pcap.c b/source/printing/pcap.c
index a5fb53a320d..0495b6fc1fc 100644
--- a/source/printing/pcap.c
+++ b/source/printing/pcap.c
@@ -27,10 +27,8 @@
*/
/*
- * Parse printcap file.
- *
- * This module does exactly one thing - it looks into the printcap file
- * and tells callers if a specified string appears as a printer name.
+ * This module contains code to parse and cache printcap data, possibly
+ * in concert with the CUPS/SYSV/AIX-specific code found elsewhere.
*
* The way this module looks at the printcap file is very simplistic.
* Only the local printcap file is inspected (no searching of NIS
@@ -62,352 +60,194 @@
#include "includes.h"
-#ifdef AIX
-/* ******************************************
- Extend for AIX system and qconfig file
- from 'boulard@univ-rennes1.fr
- ****************************************** */
-static int strlocate(char *xpLine,char *xpS)
+
+typedef struct pcap_cache {
+ char *name;
+ char *comment;
+ struct pcap_cache *next;
+} pcap_cache_t;
+
+static pcap_cache_t *pcap_cache = NULL;
+
+BOOL pcap_cache_add(const char *name, const char *comment)
{
- int iS,iL,iRet;
- char *p;
- iS = strlen(xpS);
- iL = strlen(xpLine);
-
- iRet = 0;
- p = xpLine;
- while (iL >= iS)
- {
- if (strncmp(p,xpS,iS) == 0) {iRet =1;break;};
- p++;
- iL--;
- }
- /*DEBUG(3,(" strlocate %s in line '%s',ret=%d\n",xpS,xpLine,iRet));*/
-
- return(iRet);
+ pcap_cache_t *p;
+
+ if (name == NULL || ((p = SMB_MALLOC_P(pcap_cache_t)) == NULL))
+ return False;
+
+ p->name = SMB_STRDUP(name);
+ p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL;
+
+ p->next = pcap_cache;
+ pcap_cache = p;
+
+ return True;
}
-
-
-/* ******************************************************************* */
-/* * Scan qconfig and search all virtual printer (device printer) * */
-/* ******************************************************************* */
-static void ScanQconfig_fn(char *psz,void (*fn)(char *, char *))
+
+static void pcap_cache_destroy(pcap_cache_t *cache)
{
- int iEtat;
- XFILE *pfile;
- char *line,*p;
- pstring name,comment;
- line = NULL;
- *name = 0;
- *comment = 0;
-
- if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
- {
- DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
- return;
- }
+ pcap_cache_t *p, *next;
- iEtat = 0;
- /* scan qconfig file for searching <printername>: */
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
- {
- if (*line == '*' || *line == 0)
- continue;
- switch (iEtat)
- {
- case 0: /* locate an entry */
- if (*line == '\t' || *line == ' ') continue;
- if ((p=strchr_m(line,':')))
- {
- *p = '\0';
- p = strtok(line,":");
- if (strcmp(p,"bsh")!=0)
- {
- pstrcpy(name,p);
- iEtat = 1;
- continue;
- }
- }
- break;
- case 1: /* scanning device stanza */
- if (*line == '*' || *line == 0) continue;
- if (*line != '\t' && *line != ' ')
- {
- /* name is found without stanza device */
- /* probably a good printer ??? */
- fn(name,comment);
- iEtat = 0;
- continue;
- }
-
- if (strlocate(line,"backend"))
- {
- /* it's a device, not a virtual printer*/
- iEtat = 0;
- }
- else if (strlocate(line,"device"))
- {
- /* it's a good virtual printer */
- fn(name,comment);
- iEtat = 0;
- continue;
- }
- break;
- }
+ for (p = cache; p != NULL; p = next) {
+ next = p->next;
+
+ SAFE_FREE(p->name);
+ SAFE_FREE(p->comment);
+ SAFE_FREE(p);
}
- x_fclose(pfile);
}
-/* Scan qconfig file and locate de printername */
-
-static BOOL ScanQconfig(char *psz,char *pszPrintername)
+BOOL pcap_cache_loaded(void)
{
- int iLg,iEtat;
- XFILE *pfile;
- char *pName;
- char *line;
-
- pName = NULL;
- line = NULL;
- if ((pszPrintername!= NULL) && ((iLg = strlen(pszPrintername)) > 0))
- pName = malloc(iLg+10);
- if (pName == NULL)
- {
- DEBUG(0,(" Unable to allocate memory for printer %s\n",pszPrintername));
- return(False);
- }
- if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
- {
- DEBUG(0,( "Unable to open qconfig file %s for read!\n", psz));
- SAFE_FREE(pName);
- return(False);
- }
- slprintf(pName, iLg + 9, "%s:",pszPrintername);
- iLg = strlen(pName);
- /*DEBUG(3,( " Looking for entry %s\n",pName));*/
- iEtat = 0;
- /* scan qconfig file for searching <printername>: */
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
- {
- if (*line == '*' || *line == 0)
- continue;
- switch (iEtat)
- {
- case 0: /* scanning entry */
- if (strncmp(line,pName,iLg) == 0)
- {
- iEtat = 1;
- continue;
- }
- break;
- case 1: /* scanning device stanza */
- if (*line == '*' || *line == 0) continue;
- if (*line != '\t' && *line != ' ')
- {
- /* name is found without stanza device */
- /* probably a good printer ??? */
- free (line);
- SAFE_FREE(pName);
- x_fclose(pfile);
- return(True);
- }
-
- if (strlocate(line,"backend"))
- {
- /* it's a device, not a virtual printer*/
- iEtat = 0;
- }
- else if (strlocate(line,"device"))
- {
- /* it's a good virtual printer */
- free (line);
- SAFE_FREE(pName);
- x_fclose(pfile);
- return(True);
- }
- break;
- }
- }
- free (pName);
- x_fclose(pfile);
- return(False);
+ return (pcap_cache != NULL);
}
-#endif /* AIX */
-
-/***************************************************************************
-Scan printcap file pszPrintcapname for a printer called pszPrintername.
-Return True if found, else False. Returns False on error, too, after logging
-the error at level 0. For generality, the printcap name may be passed - if
-passed as NULL, the configuration will be queried for the name.
-***************************************************************************/
-BOOL pcap_printername_ok(const char *pszPrintername, const char *pszPrintcapname)
+void pcap_cache_reload(void)
{
- char *line=NULL;
- const char *psz;
- char *p,*q;
- XFILE *pfile;
-
- if (pszPrintername == NULL || pszPrintername[0] == '\0')
- {
- DEBUG(0,( "Attempt to locate null printername! Internal error?\n"));
- return(False);
- }
-
- /* only go looking if no printcap name supplied */
- if ((psz = pszPrintcapname) == NULL || psz[0] == '\0')
- if (((psz = lp_printcapname()) == NULL) || (psz[0] == '\0'))
- {
- DEBUG(0,( "No printcap file name configured!\n"));
- return(False);
- }
+ const char *pcap_name = lp_printcapname();
+ BOOL pcap_reloaded = False;
+ pcap_cache_t *tmp_cache = NULL;
+ XFILE *pcap_file;
+ char *pcap_line;
+
+ DEBUG(3, ("reloading printcap cache\n"));
+
+ /* only go looking if no printcap name supplied */
+ if (pcap_name == NULL || *pcap_name == 0) {
+ DEBUG(0, ("No printcap file name configured!\n"));
+ return;
+ }
+
+ tmp_cache = pcap_cache;
+ pcap_cache = NULL;
#ifdef HAVE_CUPS
- if (strequal(psz, "cups"))
- return (cups_printername_ok(pszPrintername));
-#endif /* HAVE_CUPS */
+ if (strequal(pcap_name, "cups")) {
+ pcap_reloaded = cups_cache_reload();
+ goto done;
+ }
+#endif
#ifdef SYSV
- if (strequal(psz, "lpstat"))
- return (sysv_printername_ok(pszPrintername));
+ if (strequal(pcap_name, "lpstat")) {
+ pcap_reloaded = sysv_cache_reload();
+ goto done;
+ }
#endif
#ifdef AIX
- if (strlocate(psz,"/qconfig"))
- return(ScanQconfig(psz,pszPrintername));
+ if (strstr_m(pcap_name, "/qconfig") != NULL) {
+ pcap_reloaded = aix_cache_reload();
+ goto done;
+ }
#endif
- if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
- {
- DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
- return(False);
- }
+ /* handle standard printcap - moved from pcap_printer_fn() */
+
+ if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) {
+ DEBUG(0, ("Unable to open printcap file %s for read!\n", pcap_name));
+ goto done;
+ }
+
+ for (; (pcap_line = fgets_slash(NULL, sizeof(pstring), pcap_file)) != NULL; safe_free(pcap_line)) {
+ pstring name, comment;
+ char *p, *q;
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
- {
- if (*line == '#' || *line == 0)
- continue;
+ if (*pcap_line == '#' || *pcap_line == 0)
+ continue;
- /* now we have a real printer line - cut it off at the first : */
- p = strchr_m(line,':');
- if (p) *p = 0;
+ /* now we have a real printer line - cut at the first : */
+ if ((p = strchr_m(pcap_line, ':')) != NULL)
+ *p = 0;
- /* now just check if the name is in the list */
- /* NOTE: I avoid strtok as the fn calling this one may be using it */
- for (p=line; p; p=q)
- {
- if ((q = strchr_m(p,'|'))) *q++ = 0;
-
- if (strequal(p,pszPrintername))
- {
- SAFE_FREE(line);
- x_fclose(pfile);
- return(True);
- }
- p = q;
+ /*
+ * now find the most likely printer name and comment
+ * this is pure guesswork, but it's better than nothing
+ */
+ for (*name = *comment = 0, p = pcap_line; p != NULL; p = q) {
+ BOOL has_punctuation;
+
+ if ((q = strchr_m(p, '|')) != NULL)
+ *q++ = 0;
+
+ has_punctuation = (strchr_m(p, ' ') ||
+ strchr_m(p, '\t') ||
+ strchr_m(p, '(') ||
+ strchr_m(p, ')'));
+
+ if (strlen(p) > strlen(comment) && has_punctuation) {
+ pstrcpy(comment, p);
+ continue;
+ }
+
+ if (strlen(p) <= MAXPRINTERLEN &&
+ strlen(p) > strlen(name) && !has_punctuation) {
+ if (!*comment)
+ pstrcpy(comment, name);
+
+ pstrcpy(name, p);
+ continue;
+ }
+
+ if (!strchr_m(comment, ' ') &&
+ strlen(p) > strlen(comment)) {
+ pstrcpy(comment, p);
+ continue;
+ }
+ }
+
+ comment[60] = 0;
+ name[MAXPRINTERLEN] = 0;
+
+ if (*name && !pcap_cache_add(name, comment)) {
+ x_fclose(pcap_file);
+ goto done;
+ }
}
- }
- x_fclose(pfile);
- return(False);
+ x_fclose(pcap_file);
+ pcap_reloaded = True;
+
+done:
+ DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error"));
+
+ if (pcap_reloaded)
+ pcap_cache_destroy(tmp_cache);
+ else {
+ pcap_cache_destroy(pcap_cache);
+ pcap_cache = tmp_cache;
+ }
+
+ return;
}
+BOOL pcap_printername_ok(const char *printername)
+{
+ pcap_cache_t *p;
+
+ for (p = pcap_cache; p != NULL; p = p->next)
+ if (strequal(p->name, printername))
+ return True;
+
+ return False;
+}
+
/***************************************************************************
run a function on each printer name in the printcap file. The function is
passed the primary name and the comment (if possible). Note the fn() takes
strings in DOS codepage. This means the xxx_printer_fn() calls must be fixed
to return DOS codepage. FIXME !! JRA.
+
+XXX: I'm not sure if this comment still applies.. Anyone? -Rob
***************************************************************************/
void pcap_printer_fn(void (*fn)(char *, char *))
{
- pstring name,comment;
- char *line;
- char *psz;
- char *p,*q;
- XFILE *pfile;
-
- /* only go looking if no printcap name supplied */
- if (((psz = lp_printcapname()) == NULL) || (psz[0] == '\0'))
- {
- DEBUG(0,( "No printcap file name configured!\n"));
- return;
- }
-
-#ifdef HAVE_CUPS
- if (strequal(psz, "cups")) {
- cups_printer_fn(fn);
- return;
- }
-#endif /* HAVE_CUPS */
-
-#ifdef SYSV
- if (strequal(psz, "lpstat")) {
- sysv_printer_fn(fn);
- return;
- }
-#endif
-
-#ifdef AIX
- if (strlocate(psz,"/qconfig"))
- {
- ScanQconfig_fn(psz,fn);
- return;
- }
-#endif
-
- if ((pfile = x_fopen(psz, O_RDONLY, 0)) == NULL)
- {
- DEBUG(0,( "Unable to open printcap file %s for read!\n", psz));
- return;
- }
-
- for (;(line = fgets_slash(NULL,sizeof(pstring),pfile)); safe_free(line))
- {
- if (*line == '#' || *line == 0)
- continue;
-
- /* now we have a real printer line - cut it off at the first : */
- p = strchr_m(line,':');
- if (p) *p = 0;
-
- /* now find the most likely printer name and comment
- this is pure guesswork, but it's better than nothing */
- *name = 0;
- *comment = 0;
- for (p=line; p; p=q)
- {
- BOOL has_punctuation;
- if ((q = strchr_m(p,'|'))) *q++ = 0;
-
- has_punctuation = (strchr_m(p,' ') || strchr_m(p,'\t') || strchr_m(p,'(') || strchr_m(p,')'));
-
- if (strlen(p)>strlen(comment) && has_punctuation)
- {
- pstrcpy(comment,p);
- continue;
- }
-
- if (strlen(p) <= MAXPRINTERLEN && strlen(p)>strlen(name) && !has_punctuation)
- {
- if (!*comment) pstrcpy(comment,name);
- pstrcpy(name,p);
- continue;
- }
-
- if (!strchr_m(comment,' ') &&
- strlen(p) > strlen(comment))
- {
- pstrcpy(comment,p);
- continue;
- }
- }
+ pcap_cache_t *p;
- comment[60] = 0;
- name[MAXPRINTERLEN] = 0;
+ for (p = pcap_cache; p != NULL; p = p->next)
+ fn(p->name, p->comment);
- if (*name)
- fn(name,comment);
- }
- x_fclose(pfile);
+ return;
}
diff --git a/source/printing/print_aix.c b/source/printing/print_aix.c
new file mode 100644
index 00000000000..6ed3510ee41
--- /dev/null
+++ b/source/printing/print_aix.c
@@ -0,0 +1,111 @@
+/*
+ AIX-specific printcap loading
+ Copyright (C) Jean-Pierre.Boulard@univ-rennes1.fr 1996
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/*
+ * This module implements AIX-specific printcap loading. Most of the code
+ * here was originally provided by Jean-Pierre.Boulard@univ-rennes1.fr in
+ * the Samba 1.9.14 release, and was formerly contained in pcap.c. It has
+ * been moved here and condensed as part of a larger effort to clean up and
+ * simplify the printcap code. -- Rob Foehl, 2004/12/06
+ */
+
+#include "includes.h"
+
+#ifdef AIX
+BOOL aix_cache_reload(void)
+{
+ int iEtat;
+ XFILE *pfile;
+ char *line = NULL, *p;
+ pstring name, comment;
+
+ *name = 0;
+ *comment = 0;
+
+ DEBUG(5, ("reloading aix printcap cache\n"));
+
+ if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) {
+ DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname()));
+ return False;
+ }
+
+ iEtat = 0;
+ /* scan qconfig file for searching <printername>: */
+ for (;(line = fgets_slash(NULL, sizeof(pstring), pfile)); safe_free(line)) {
+ if (*line == '*' || *line == 0)
+ continue;
+
+ switch (iEtat) {
+ case 0: /* locate an entry */
+ if (*line == '\t' || *line == ' ')
+ continue;
+
+ if ((p = strchr_m(line, ':'))) {
+ *p = '\0';
+ p = strtok(line, ":");
+ if (strcmp(p, "bsh") != 0) {
+ pstrcpy(name, p);
+ iEtat = 1;
+ continue;
+ }
+ }
+ break;
+
+ case 1: /* scanning device stanza */
+ if (*line == '*' || *line == 0)
+ continue;
+
+ if (*line != '\t' && *line != ' ') {
+ /* name is found without stanza device */
+ /* probably a good printer ??? */
+ iEtat = 0;
+ if (!pcap_cache_add(name, NULL)) {
+ safe_free(line);
+ x_fclose(pfile);
+ return False;
+ }
+ continue;
+ }
+
+ if (strstr_m(line, "backend")) {
+ /* it's a device, not a virtual printer */
+ iEtat = 0;
+ } else if (strstr_m(line, "device")) {
+ /* it's a good virtual printer */
+ iEtat = 0;
+ if (!pcap_cache_add(name, NULL)) {
+ safe_free(line);
+ x_fclose(pfile);
+ return False;
+ }
+ continue;
+ }
+ break;
+ }
+ }
+
+ x_fclose(pfile);
+ return True;
+}
+
+#else
+/* this keeps fussy compilers happy */
+ void print_aix_dummy(void);
+ void print_aix_dummy(void) {}
+#endif /* AIX */
diff --git a/source/printing/print_cups.c b/source/printing/print_cups.c
index 5cc36d6e170..90af10c3736 100644
--- a/source/printing/print_cups.c
+++ b/source/printing/print_cups.c
@@ -33,11 +33,11 @@
static const char * /* O - Password or NULL */
cups_passwd_cb(const char *prompt) /* I - Prompt */
{
- /*
- * Always return NULL to indicate that no password is available...
- */
+ /*
+ * Always return NULL to indicate that no password is available...
+ */
- return (NULL);
+ return (NULL);
}
static const char *cups_server(void)
@@ -52,19 +52,13 @@ static const char *cups_server(void)
return cupsServer();
}
-/*
- * 'cups_printer_fn()' - Call a function for every printer known to the
- * system.
- */
-
-void cups_printer_fn(void (*fn)(char *, char *))
+BOOL cups_cache_reload(void)
{
- /* I - Function to call */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
ipp_attribute_t *attr; /* Current attribute */
- cups_lang_t *language; /* Default language */
+ cups_lang_t *language = NULL; /* Default language */
char *name, /* printer-name attribute */
*info; /* printer-info attribute */
static const char *requested[] =/* Requested attributes */
@@ -72,9 +66,9 @@ void cups_printer_fn(void (*fn)(char *, char *))
"printer-name",
"printer-info"
};
+ BOOL ret = False;
-
- DEBUG(5,("cups_printer_fn(%p)\n", fn));
+ DEBUG(5, ("reloading cups printcap cache\n"));
/*
* Make sure we don't ask for passwords...
@@ -86,11 +80,10 @@ void cups_printer_fn(void (*fn)(char *, char *))
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return;
+ goto out;
}
/*
@@ -124,16 +117,13 @@ void cups_printer_fn(void (*fn)(char *, char *))
* Do the request and get back a response...
*/
- if ((response = cupsDoRequest(http, request, "/")) == NULL)
- {
+ if ((response = cupsDoRequest(http, request, "/")) == NULL) {
DEBUG(0,("Unable to get printer list - %s\n",
ippErrorString(cupsLastError())));
- httpClose(http);
- return;
+ goto out;
}
- for (attr = response->attrs; attr != NULL;)
- {
+ for (attr = response->attrs; attr != NULL;) {
/*
* Skip leading attributes until we hit a printer...
*/
@@ -151,8 +141,7 @@ void cups_printer_fn(void (*fn)(char *, char *))
name = NULL;
info = NULL;
- while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
- {
+ while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
if (strcmp(attr->name, "printer-name") == 0 &&
attr->value_tag == IPP_TAG_NAME)
name = attr->values[0].string.text;
@@ -171,11 +160,13 @@ void cups_printer_fn(void (*fn)(char *, char *))
if (name == NULL)
break;
- (*fn)(name, info);
+ if (!pcap_cache_add(name, info)) {
+ goto out;
+ }
}
ippDelete(response);
-
+ response = NULL;
/*
* Build a CUPS_GET_CLASSES request, which requires the following
@@ -191,8 +182,6 @@ void cups_printer_fn(void (*fn)(char *, char *))
request->request.op.operation_id = CUPS_GET_CLASSES;
request->request.op.request_id = 1;
- language = cupsLangDefault();
-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, cupsLangEncoding(language));
@@ -208,16 +197,13 @@ void cups_printer_fn(void (*fn)(char *, char *))
* Do the request and get back a response...
*/
- if ((response = cupsDoRequest(http, request, "/")) == NULL)
- {
+ if ((response = cupsDoRequest(http, request, "/")) == NULL) {
DEBUG(0,("Unable to get printer list - %s\n",
ippErrorString(cupsLastError())));
- httpClose(http);
- return;
+ goto out;
}
- for (attr = response->attrs; attr != NULL;)
- {
+ for (attr = response->attrs; attr != NULL;) {
/*
* Skip leading attributes until we hit a printer...
*/
@@ -235,8 +221,7 @@ void cups_printer_fn(void (*fn)(char *, char *))
name = NULL;
info = NULL;
- while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
- {
+ while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
if (strcmp(attr->name, "printer-name") == 0 &&
attr->value_tag == IPP_TAG_NAME)
name = attr->values[0].string.text;
@@ -255,110 +240,24 @@ void cups_printer_fn(void (*fn)(char *, char *))
if (name == NULL)
break;
- (*fn)(name, info);
+ if (!pcap_cache_add(name, info)) {
+ goto out;
+ }
}
- ippDelete(response);
-
- /*
- * Close the connection to the server...
- */
-
- httpClose(http);
-}
-
-
-/*
- * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok()
- * for CUPS.
- * O - 1 if printer name OK
- * I - Name of printer
- */
-int cups_printername_ok(const char *name)
-{
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
- char uri[HTTP_MAX_URI]; /* printer-uri attribute */
-
-
- DEBUG(5,("cups_printername_ok(\"%s\")\n", name));
+ ret = True;
- /*
- * Make sure we don't ask for passwords...
- */
-
- cupsSetPasswordCB(cups_passwd_cb);
-
- /*
- * Try to connect to the server...
- */
-
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
- DEBUG(3,("Unable to connect to CUPS server %s - %s\n",
- cups_server(), strerror(errno)));
- return (0);
- }
-
- /*
- * Build an IPP_GET_PRINTER_ATTRS request, which requires the following
- * attributes:
- *
- * attributes-charset
- * attributes-natural-language
- * requested-attributes
- * printer-uri
- */
-
- request = ippNew();
-
- request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
- request->request.op.request_id = 1;
-
- language = cupsLangDefault();
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
- "attributes-charset", NULL, cupsLangEncoding(language));
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
- "attributes-natural-language", NULL, language->language);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
- "requested-attributes", NULL, "printer-uri");
-
- slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name);
-
- ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
- "printer-uri", NULL, uri);
+ out:
+ if (response)
+ ippDelete(response);
- /*
- * Do the request and get back a response...
- */
+ if (language)
+ cupsLangFree(language);
- if ((response = cupsDoRequest(http, request, "/")) == NULL)
- {
- DEBUG(3,("Unable to get printer status for %s - %s\n", name,
- ippErrorString(cupsLastError())));
+ if (http)
httpClose(http);
- return (0);
- }
- httpClose(http);
-
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
- {
- DEBUG(3,("Unable to get printer status for %s - %s\n", name,
- ippErrorString(response->request.status.status_code)));
- ippDelete(response);
- return (0);
- }
- else
- {
- ippDelete(response);
- return (1);
- }
+ return ret;
}
@@ -366,14 +265,13 @@ int cups_printername_ok(const char *name)
* 'cups_job_delete()' - Delete a job.
*/
-static int
-cups_job_delete(int snum, struct printjob *pjob)
+static int cups_job_delete(int snum, struct printjob *pjob)
{
- int ret; /* Return value */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
+ int ret = 1; /* Return value */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
@@ -389,11 +287,10 @@ cups_job_delete(int snum, struct printjob *pjob)
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (1);
+ goto out;
}
/*
@@ -430,25 +327,29 @@ cups_job_delete(int snum, struct printjob *pjob)
* Do the request and get back a response...
*/
- ret = 1;
-
- if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
- {
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
+ if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
+ DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
+ ippErrorString(cupsLastError())));
+ } else {
+ ret = 0;
+ }
+ } else {
DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
- ippErrorString(cupsLastError())));
- else
- ret = 0;
-
- ippDelete(response);
+ ippErrorString(cupsLastError())));
}
- else
- DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
- ippErrorString(cupsLastError())));
- httpClose(http);
+ out:
+ if (response)
+ ippDelete(response);
- return (ret);
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return ret;
}
@@ -456,14 +357,13 @@ cups_job_delete(int snum, struct printjob *pjob)
* 'cups_job_pause()' - Pause a job.
*/
-static int
-cups_job_pause(int snum, struct printjob *pjob)
+static int cups_job_pause(int snum, struct printjob *pjob)
{
- int ret; /* Return value */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
+ int ret = 1; /* Return value */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
@@ -479,11 +379,10 @@ cups_job_pause(int snum, struct printjob *pjob)
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (1);
+ goto out;
}
/*
@@ -520,25 +419,29 @@ cups_job_pause(int snum, struct printjob *pjob)
* Do the request and get back a response...
*/
- ret = 1;
-
- if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
- {
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
+ if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
+ DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
+ ippErrorString(cupsLastError())));
+ } else {
+ ret = 0;
+ }
+ } else {
DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
- ippErrorString(cupsLastError())));
- else
- ret = 0;
-
- ippDelete(response);
+ ippErrorString(cupsLastError())));
}
- else
- DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
- ippErrorString(cupsLastError())));
- httpClose(http);
+ out:
+ if (response)
+ ippDelete(response);
- return (ret);
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return ret;
}
@@ -546,14 +449,13 @@ cups_job_pause(int snum, struct printjob *pjob)
* 'cups_job_resume()' - Resume a paused job.
*/
-static int
-cups_job_resume(int snum, struct printjob *pjob)
+static int cups_job_resume(int snum, struct printjob *pjob)
{
- int ret; /* Return value */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
+ int ret = 1; /* Return value */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
@@ -569,11 +471,10 @@ cups_job_resume(int snum, struct printjob *pjob)
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (1);
+ goto out;
}
/*
@@ -610,25 +511,29 @@ cups_job_resume(int snum, struct printjob *pjob)
* Do the request and get back a response...
*/
- ret = 1;
-
- if ((response = cupsDoRequest(http, request, "/jobs")) != NULL)
- {
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
+ if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
+ DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
+ ippErrorString(cupsLastError())));
+ } else {
+ ret = 0;
+ }
+ } else {
DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
- ippErrorString(cupsLastError())));
- else
- ret = 0;
-
- ippDelete(response);
+ ippErrorString(cupsLastError())));
}
- else
- DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
- ippErrorString(cupsLastError())));
- httpClose(http);
+ out:
+ if (response)
+ ippDelete(response);
- return (ret);
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return ret;
}
@@ -636,19 +541,18 @@ cups_job_resume(int snum, struct printjob *pjob)
* 'cups_job_submit()' - Submit a job for printing.
*/
-static int
-cups_job_submit(int snum, struct printjob *pjob)
+static int cups_job_submit(int snum, struct printjob *pjob)
{
- int ret; /* Return value */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
+ int ret = 1; /* Return value */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
- char *clientname; /* hostname of client for job-originating-host attribute */
+ char *clientname = NULL; /* hostname of client for job-originating-host attribute */
pstring new_jobname;
int num_options = 0;
- cups_option_t *options;
+ cups_option_t *options = NULL;
DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
@@ -662,11 +566,10 @@ cups_job_submit(int snum, struct printjob *pjob)
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (1);
+ goto out;
}
/*
@@ -734,28 +637,33 @@ cups_job_submit(int snum, struct printjob *pjob)
slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
- ret = 1;
- if ((response = cupsDoFileRequest(http, request, uri,
- pjob->filename)) != NULL)
- {
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
+ if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
ippErrorString(cupsLastError())));
- else
+ } else {
ret = 0;
-
- ippDelete(response);
- }
- else
+ }
+ } else {
DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
ippErrorString(cupsLastError())));
-
- httpClose(http);
+ }
if ( ret == 0 )
unlink(pjob->filename);
/* else print_job_end will do it for us */
+ out:
+ if (response)
+ ippDelete(response);
+
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return ret;
return (ret);
}
@@ -763,22 +671,21 @@ cups_job_submit(int snum, struct printjob *pjob)
* 'cups_queue_get()' - Get all the jobs in the print queue.
*/
-static int
-cups_queue_get(const char *printer_name,
+static int cups_queue_get(const char *printer_name,
enum printing_types printing_type,
char *lpq_command,
print_queue_struct **q,
print_status_struct *status)
{
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- ipp_attribute_t *attr; /* Current attribute */
- cups_lang_t *language; /* Default language */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ ipp_attribute_t *attr = NULL; /* Current attribute */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
- int qcount, /* Number of active queue entries */
- qalloc; /* Number of queue entries allocated */
- print_queue_struct *queue, /* Queue entries */
+ int qcount = 0, /* Number of active queue entries */
+ qalloc = 0; /* Number of queue entries allocated */
+ print_queue_struct *queue = NULL, /* Queue entries */
*temp; /* Temporary pointer for queue */
const char *user_name, /* job-originating-user-name attribute */
*job_name; /* job-name attribute */
@@ -803,6 +710,7 @@ cups_queue_get(const char *printer_name,
"printer-state-message"
};
+ *q = NULL;
DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printer_name, q, status));
@@ -816,11 +724,10 @@ cups_queue_get(const char *printer_name,
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (0);
+ goto out;
}
/*
@@ -864,22 +771,16 @@ cups_queue_get(const char *printer_name,
* Do the request and get back a response...
*/
- if ((response = cupsDoRequest(http, request, "/")) == NULL)
- {
+ if ((response = cupsDoRequest(http, request, "/")) == NULL) {
DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
ippErrorString(cupsLastError())));
- httpClose(http);
- return (0);
+ goto out;
}
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
- {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
ippErrorString(response->request.status.status_code)));
- ippDelete(response);
- httpClose(http);
-
- return (0);
+ goto out;
}
/*
@@ -890,8 +791,7 @@ cups_queue_get(const char *printer_name,
qalloc = 0;
queue = NULL;
- for (attr = response->attrs; attr != NULL; attr = attr->next)
- {
+ for (attr = response->attrs; attr != NULL; attr = attr->next) {
/*
* Skip leading attributes until we hit a job...
*/
@@ -905,20 +805,16 @@ cups_queue_get(const char *printer_name,
/*
* Allocate memory as needed...
*/
- if (qcount >= qalloc)
- {
+ if (qcount >= qalloc) {
qalloc += 16;
temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
- if (temp == NULL)
- {
+ if (temp == NULL) {
DEBUG(0,("cups_queue_get: Not enough memory!"));
- ippDelete(response);
- httpClose(http);
-
+ qcount = 0;
SAFE_FREE(queue);
- return (0);
+ goto out;
}
queue = temp;
@@ -939,10 +835,8 @@ cups_queue_get(const char *printer_name,
user_name = NULL;
job_name = NULL;
- while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
- {
- if (attr->name == NULL)
- {
+ while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
+ if (attr->name == NULL) {
attr = attr->next;
break;
}
@@ -982,12 +876,11 @@ cups_queue_get(const char *printer_name,
* See if we have everything needed...
*/
- if (user_name == NULL || job_name == NULL || job_id == 0)
- {
- if (attr == NULL)
- break;
- else
- continue;
+ if (user_name == NULL || job_name == NULL || job_id == 0) {
+ if (attr == NULL)
+ break;
+ else
+ continue;
}
temp->job = job_id;
@@ -1004,10 +897,11 @@ cups_queue_get(const char *printer_name,
qcount ++;
if (attr == NULL)
- break;
+ break;
}
ippDelete(response);
+ response = NULL;
/*
* Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
@@ -1019,13 +913,9 @@ cups_queue_get(const char *printer_name,
* printer-uri
*/
- request = ippNew();
-
request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
request->request.op.request_id = 1;
- language = cupsLangDefault();
-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, cupsLangEncoding(language));
@@ -1044,31 +934,25 @@ cups_queue_get(const char *printer_name,
* Do the request and get back a response...
*/
- if ((response = cupsDoRequest(http, request, "/")) == NULL)
- {
+ if ((response = cupsDoRequest(http, request, "/")) == NULL) {
DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
ippErrorString(cupsLastError())));
- httpClose(http);
*q = queue;
- return (qcount);
+ goto out;
}
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
- {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name,
ippErrorString(response->request.status.status_code)));
- ippDelete(response);
- httpClose(http);
*q = queue;
- return (qcount);
+ goto out;
}
/*
* Get the current printer status and convert it to the SAMBA values.
*/
- if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL)
- {
+ if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
if (attr->values[0].integer == IPP_PRINTER_STOPPED)
status->status = LPSTAT_STOPPED;
else
@@ -1079,16 +963,23 @@ cups_queue_get(const char *printer_name,
IPP_TAG_TEXT)) != NULL)
fstrcpy(status->message, attr->values[0].string.text);
- ippDelete(response);
-
/*
* Return the job queue...
*/
- httpClose(http);
-
*q = queue;
- return (qcount);
+
+ out:
+ if (response)
+ ippDelete(response);
+
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return qcount;
}
@@ -1096,15 +987,14 @@ cups_queue_get(const char *printer_name,
* 'cups_queue_pause()' - Pause a print queue.
*/
-static int
-cups_queue_pause(int snum)
+static int cups_queue_pause(int snum)
{
extern userdom_struct current_user_info;
- int ret; /* Return value */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
+ int ret = 1; /* Return value */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
@@ -1120,11 +1010,10 @@ cups_queue_pause(int snum)
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (1);
+ goto out;
}
/*
@@ -1162,25 +1051,29 @@ cups_queue_pause(int snum)
* Do the request and get back a response...
*/
- ret = 1;
-
- if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
- {
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
+ if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
+ DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
+ ippErrorString(cupsLastError())));
+ } else {
+ ret = 0;
+ }
+ } else {
DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
- ippErrorString(cupsLastError())));
- else
- ret = 0;
-
- ippDelete(response);
+ ippErrorString(cupsLastError())));
}
- else
- DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
- ippErrorString(cupsLastError())));
- httpClose(http);
+ out:
+ if (response)
+ ippDelete(response);
- return (ret);
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return ret;
}
@@ -1188,15 +1081,14 @@ cups_queue_pause(int snum)
* 'cups_queue_resume()' - Restart a print queue.
*/
-static int
-cups_queue_resume(int snum)
+static int cups_queue_resume(int snum)
{
extern userdom_struct current_user_info;
- int ret; /* Return value */
- http_t *http; /* HTTP connection to server */
- ipp_t *request, /* IPP Request */
- *response; /* IPP Response */
- cups_lang_t *language; /* Default language */
+ int ret = 1; /* Return value */
+ http_t *http = NULL; /* HTTP connection to server */
+ ipp_t *request = NULL, /* IPP Request */
+ *response = NULL; /* IPP Response */
+ cups_lang_t *language = NULL; /* Default language */
char uri[HTTP_MAX_URI]; /* printer-uri attribute */
@@ -1212,11 +1104,10 @@ cups_queue_resume(int snum)
* Try to connect to the server...
*/
- if ((http = httpConnect(cups_server(), ippPort())) == NULL)
- {
+ if ((http = httpConnect(cups_server(), ippPort())) == NULL) {
DEBUG(0,("Unable to connect to CUPS server %s - %s\n",
cups_server(), strerror(errno)));
- return (1);
+ goto out;
}
/*
@@ -1254,25 +1145,29 @@ cups_queue_resume(int snum)
* Do the request and get back a response...
*/
- ret = 1;
-
- if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
- {
- if (response->request.status.status_code >= IPP_OK_CONFLICT)
+ if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
+ if (response->request.status.status_code >= IPP_OK_CONFLICT) {
+ DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
+ ippErrorString(cupsLastError())));
+ } else {
+ ret = 0;
+ }
+ } else {
DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
- ippErrorString(cupsLastError())));
- else
- ret = 0;
-
- ippDelete(response);
+ ippErrorString(cupsLastError())));
}
- else
- DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
- ippErrorString(cupsLastError())));
- httpClose(http);
+ out:
+ if (response)
+ ippDelete(response);
- return (ret);
+ if (language)
+ cupsLangFree(language);
+
+ if (http)
+ httpClose(http);
+
+ return ret;
}
/*******************************************************************
diff --git a/source/printing/print_svid.c b/source/printing/print_svid.c
index d9db500425e..3a7c9356344 100644
--- a/source/printing/print_svid.c
+++ b/source/printing/print_svid.c
@@ -35,23 +35,17 @@
#include "includes.h"
#ifdef SYSV
-
-typedef struct printer {
- char *name;
- struct printer *next;
-} printer_t;
-static printer_t *printers = NULL;
-
-static void populate_printers(void)
+BOOL sysv_cache_reload(void)
{
char **lines;
int i;
- lines = file_lines_pload("/usr/bin/lpstat -v", NULL);
- if (!lines) return;
+ DEBUG(5, ("reloading sysv printcap cache\n"));
- for (i=0;lines[i];i++) {
- printer_t *ptmp;
+ if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL)
+ return False;
+
+ for (i = 0; lines[i]; i++) {
char *name, *tmp;
char *buf = lines[i];
@@ -64,7 +58,7 @@ static void populate_printers(void)
* In case we're only at the "for ".
*/
- if(!strncmp("for ",++tmp,4)) {
+ if(!strncmp("for ", ++tmp, 4)) {
tmp=strchr_m(tmp, ' ');
tmp++;
}
@@ -78,7 +72,7 @@ static void populate_printers(void)
* On HPUX there is an extra line that can be ignored.
* d.thibadeau 2001/08/09
*/
- if(!strncmp("remote to",tmp,9))
+ if(!strncmp("remote to", tmp, 9))
continue;
name = tmp;
@@ -88,53 +82,14 @@ static void populate_printers(void)
*tmp = '\0';
/* add it to the cache */
- if ((ptmp = SMB_MALLOC_P(printer_t)) != NULL) {
- ZERO_STRUCTP(ptmp);
- if((ptmp->name = SMB_STRDUP(name)) == NULL)
- DEBUG(0,("populate_printers: malloc fail in strdup !\n"));
- ptmp->next = printers;
- printers = ptmp;
- } else {
- DEBUG(0,("populate_printers: malloc fail for ptmp\n"));
+ if (!pcap_cache_add(name, NULL)) {
+ file_lines_free(lines);
+ return False;
}
}
file_lines_free(lines);
-}
-
-
-/*
- * provide the equivalent of pcap_printer_fn() for SVID/XPG4 conforming
- * systems. It was unclear why pcap_printer_fn() was tossing names longer
- * than 8 characters. I suspect that its a protocol limit, but amazingly
- * names longer than 8 characters appear to work with my test
- * clients (Win95/NT).
- */
-void sysv_printer_fn(void (*fn)(char *, char *))
-{
- printer_t *tmp;
-
- if (printers == NULL)
- populate_printers();
- for (tmp = printers; tmp != NULL; tmp = tmp->next)
- (fn)(tmp->name, "");
-}
-
-
-/*
- * provide the equivalent of pcap_printername_ok() for SVID/XPG4 conforming
- * systems.
- */
-int sysv_printername_ok(const char *name)
-{
- printer_t *tmp;
-
- if (printers == NULL)
- populate_printers();
- for (tmp = printers; tmp != NULL; tmp = tmp->next)
- if (strcmp(tmp->name, name) == 0)
- return (True);
- return (False);
+ return True;
}
#else
diff --git a/source/printing/printing.c b/source/printing/printing.c
index b5785440aeb..b4d0f3a44b3 100644
--- a/source/printing/printing.c
+++ b/source/printing/printing.c
@@ -1077,6 +1077,7 @@ static void print_queue_update_internal( const char *sharename,
if ( !print_cache_expired(sharename, False) ) {
DEBUG(5,("print_queue_update_internal: print cache for %s is still ok\n", sharename));
+ release_print_db(pdb);
return;
}
@@ -2247,7 +2248,7 @@ uint32 print_job_start(struct current_user *user, int snum, char *jobname, NT_DE
}
/* for autoloaded printers, check that the printcap entry still exists */
- if (lp_autoloaded(snum) && !pcap_printername_ok(lp_const_servicename(snum), NULL)) {
+ if (lp_autoloaded(snum) && !pcap_printername_ok(lp_const_servicename(snum))) {
DEBUG(3, ("print_job_start: printer name %s check failed.\n", lp_const_servicename(snum) ));
release_print_db(pdb);
errno = ENOENT;