[PATCH] Alllow long printer names with /etc/printcap

Jeremy Allison jra at samba.org
Thu Nov 10 19:03:55 UTC 2016


On Thu, Nov 10, 2016 at 11:51:16AM +0100, Andreas Schneider wrote:
> Hi,
> 
> the attached patch allows longer printer names in /etc/printcap and issues a 
> warning if longer ones are found. Older client might not like long printer 
> names.
> 
> BUG: https://bugzilla.samba.org/show_bug.cgi?id=12195
> 
> 
> Review and push appreciated!

Pushed with the removal of the:

> +     DBG_ERR("ASN\n");

line :-). Plus addition of a missing talloc_free(frame)
in the x_fopen() fail return path and cast of MAXPRINTERLEN
to (unsigned int) to match the %u parameter.

Cheers,

Jeremy.

> 
> -- 
> Andreas Schneider                   GPG-ID: CC014E3D
> Samba Team                             asn at samba.org
> www.samba.org

> From ce982fe2c6588a02dd8d93de537c510e5ffcbba0 Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> Date: Thu, 10 Nov 2016 11:47:54 +0100
> Subject: [PATCH] s3-printing: Allow printer names longer than 16 chars
> 
> Printers with long names are supported in the meantime. However we issue
> a warning that if one printer exceeeds 15 chars we warn about it.
> 
> BUG: https://bugzilla.samba.org/show_bug.cgi?id=12195
> 
> Signed-off-by: Andreas Schneider <asn at samba.org>
> ---
>  source3/printing/print_standard.c | 55 ++++++++++++++++++++++++++-------------
>  1 file changed, 37 insertions(+), 18 deletions(-)
> 
> diff --git a/source3/printing/print_standard.c b/source3/printing/print_standard.c
> index b5f1056..89d1dd3 100644
> --- a/source3/printing/print_standard.c
> +++ b/source3/printing/print_standard.c
> @@ -61,18 +61,21 @@
>  /* handle standard printcap - moved from pcap_printer_fn() */
>  bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
>  {
> +	TALLOC_CTX *frame = talloc_stackframe();
>  	XFILE *pcap_file;
>  	char *pcap_line;
>  	struct pcap_cache *pcache = NULL;
> +	bool print_warning = false;
>  
> +	DBG_ERR("ASN\n");
>  	if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) {
>  		DEBUG(0, ("Unable to open printcap file %s for read!\n", pcap_name));
>  		return false;
>  	}
>  
>  	for (; (pcap_line = fgets_slash(NULL, 1024, pcap_file)) != NULL; free(pcap_line)) {
> -		char name[MAXPRINTERLEN+1];
> -		char comment[62];
> +		char *name = NULL;
> +		char *comment = NULL;
>  		char *p, *q;
>  
>  		if (*pcap_line == '#' || *pcap_line == 0)
> @@ -86,8 +89,8 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
>  		 * 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;
> +		for (p = pcap_line; p != NULL; p = q) {
> +			bool has_punctuation = false;
>  
>  			if ((q = strchr_m(p, '|')) != NULL)
>  				*q++ = 0;
> @@ -101,32 +104,48 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
>  			                   strchr_m(p, '(') ||
>  			                   strchr_m(p, ')'));
>  
> -			if (strlen(p) > strlen(comment) && has_punctuation) {
> -				strlcpy(comment, p, sizeof(comment));
> +			if (name == NULL && !has_punctuation) {
> +				name = talloc_strdup(frame, p);
>  				continue;
>  			}
>  
> -			if (strlen(p) <= MAXPRINTERLEN && *name == '\0' && !has_punctuation) {
> -				strlcpy(name, p, sizeof(name));
> +			if (has_punctuation) {
> +				comment = talloc_strdup(frame, p);
>  				continue;
>  			}
> +		}
>  
> -			if (!strchr_m(comment, ' ') &&
> -			    strlen(p) > strlen(comment)) {
> -				strlcpy(comment, p, sizeof(comment));
> -				continue;
> +		if (name != NULL) {
> +			bool ok;
> +
> +			if (!print_warning && strlen(name) > MAXPRINTERLEN) {
> +				print_warning = true;
>  			}
> -		}
>  
> -		if ((*name != '\0')
> -		 && !pcap_cache_add_specific(&pcache, name, comment, NULL)) {
> -			x_fclose(pcap_file);
> -			pcap_cache_destroy_specific(&pcache);
> -			return false;
> +			ok = pcap_cache_add_specific(&pcache,
> +						     name,
> +						     comment,
> +						     NULL);
> +			if (!ok) {
> +				x_fclose(pcap_file);
> +				pcap_cache_destroy_specific(&pcache);
> +				talloc_free(frame);
> +				return false;
> +			}
>  		}
> +		TALLOC_FREE(name);
> +		TALLOC_FREE(comment);
> +	}
> +
> +	if (print_warning) {
> +		DBG_WARNING("WARNING: You have some printer names that are "
> +			    "longer than %u characters. These may not be "
> +			    "accessible to some older clients!\n",
> +			    MAXPRINTERLEN);
>  	}
>  
>  	x_fclose(pcap_file);
>  	*_pcache = pcache;
> +	talloc_free(frame);
>  	return true;
>  }
> -- 
> 2.10.2
> 




More information about the samba-technical mailing list