The branch, master has been updated
       via  2611fd0 s3-printing: Allow printer names longer than 16 chars
       via  c160ae9 s3-printing: Correctly encode CUPS printer URIs
      from  82e630d s3-client: Sync in tool cmdline help with smbclient manpage

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 2611fd02a0a6a0a0a506df70fe1a1eb4a2e76062
Author: Andreas Schneider <a...@samba.org>
Date:   Thu Nov 10 11:47:54 2016 +0100

    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 <a...@samba.org>
    
    Autobuild-User(master): Jeremy Allison <j...@samba.org>
    Autobuild-Date(master): Fri Nov 11 00:02:10 CET 2016 on sn-devel-144

commit c160ae9afb222466c50ae170447a6a0805f7169f
Author: Andreas Schneider <a...@samba.org>
Date:   Wed Nov 9 19:05:49 2016 +0100

    s3-printing: Correctly encode CUPS printer URIs
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12183
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/printing/print_cups.c     | 128 ++++++++++++++++++++++++++++++++------
 source3/printing/print_standard.c |  55 ++++++++++------
 2 files changed, 147 insertions(+), 36 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index 756d67a..673a150 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -615,7 +615,8 @@ static int cups_job_delete(const char *sharename, const 
char *lprm_command, stru
                        *response = NULL;       /* IPP Response */
        cups_lang_t     *language = NULL;       /* Default language */
        char *user = NULL;
-       char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        size_t size;
 
        DEBUG(5,("cups_job_delete(%s, %p (%d))\n", sharename, pjob, 
pjob->sysjob));
@@ -657,7 +658,18 @@ static int cups_job_delete(const char *sharename, const 
char *lprm_command, stru
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/jobs/%d",
+                                  pjob->sysjob);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, 
uri);
 
@@ -712,7 +724,8 @@ static int cups_job_pause(int snum, struct printjob *pjob)
                        *response = NULL;       /* IPP Response */
        cups_lang_t     *language = NULL;       /* Default language */
        char *user = NULL;
-       char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        size_t size;
 
        DEBUG(5,("cups_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
@@ -754,7 +767,18 @@ static int cups_job_pause(int snum, struct printjob *pjob)
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/jobs/%d",
+                                  pjob->sysjob);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, 
uri);
 
@@ -808,7 +832,8 @@ static int cups_job_resume(int snum, struct printjob *pjob)
                        *response = NULL;       /* IPP Response */
        cups_lang_t     *language = NULL;       /* Default language */
        char *user = NULL;
-       char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        size_t size;
 
        DEBUG(5,("cups_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
@@ -850,7 +875,18 @@ static int cups_job_resume(int snum, struct printjob *pjob)
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/jobs/%d", pjob->sysjob);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/jobs/%d",
+                                  pjob->sysjob);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, 
uri);
 
@@ -906,7 +942,8 @@ static int cups_job_submit(int snum, struct printjob *pjob,
                        *response = NULL;       /* IPP Response */
        ipp_attribute_t *attr_job_id = NULL;    /* IPP Attribute "job-id" */
        cups_lang_t     *language = NULL;       /* Default language */
-       char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        char *new_jobname = NULL;
        int             num_options = 0;
        cups_option_t   *options = NULL;
@@ -962,8 +999,18 @@ static int cups_job_submit(int snum, struct printjob *pjob,
                              &size)) {
                goto out;
        }
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
-                printername);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/printers/%s",
+                                  printername);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                     "printer-uri", NULL, uri);
@@ -1010,7 +1057,18 @@ static int cups_job_submit(int snum, struct printjob 
*pjob,
        * Do the request and get back a response...
        */
 
-       slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/printers/%s",
+                                  printername);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        if (!push_utf8_talloc(frame, &filename, pjob->filename, &size)) {
                goto out;
@@ -1072,7 +1130,8 @@ static int cups_queue_get(const char *sharename,
                        *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 */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        int             qcount = 0,             /* Number of active queue 
entries */
                        qalloc = 0;             /* Number of queue entries 
allocated */
        print_queue_struct *queue = NULL,       /* Queue entries */
@@ -1132,7 +1191,18 @@ static int cups_queue_get(const char *sharename,
         * Generate the printer URI...
        */
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 
printername);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/printers/%s",
+                                  printername);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        /*
        * Build an IPP_GET_JOBS request, which requires the following
@@ -1415,7 +1485,8 @@ static int cups_queue_pause(int snum)
        cups_lang_t     *language = NULL;       /* Default language */
        char *printername = NULL;
        char *username = NULL;
-       char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        size_t size;
 
        DEBUG(5,("cups_queue_pause(%d)\n", snum));
@@ -1461,8 +1532,18 @@ static int cups_queue_pause(int snum)
                              lp_printername(talloc_tos(), snum), &size)) {
                goto out;
        }
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
-                printername);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/printers/%s",
+                                  printername);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", 
NULL, uri);
 
@@ -1519,7 +1600,8 @@ static int cups_queue_resume(int snum)
        cups_lang_t     *language = NULL;       /* Default language */
        char *printername = NULL;
        char *username = NULL;
-       char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
+       char            uri[HTTP_MAX_URI] = {0}; /* printer-uri attribute */
+       http_uri_status_t ustatus;
        size_t size;
 
        DEBUG(5,("cups_queue_resume(%d)\n", snum));
@@ -1565,8 +1647,18 @@ static int cups_queue_resume(int snum)
                              &size)) {
                goto out;
        }
-       slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
-                printername);
+       ustatus = httpAssembleURIf(HTTP_URI_CODING_ALL,
+                                  uri,
+                                  sizeof(uri),
+                                  "ipp",
+                                  NULL, /* username */
+                                  "localhost",
+                                  ippPort(),
+                                  "/printers/%s",
+                                  printername);
+       if (ustatus != HTTP_URI_STATUS_OK) {
+               goto out;
+       }
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", 
NULL, uri);
 
diff --git a/source3/printing/print_standard.c 
b/source3/printing/print_standard.c
index b5f1056..140ca70 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;
 
        if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) {
                DEBUG(0, ("Unable to open printcap file %s for read!\n", 
pcap_name));
+               talloc_free(frame);
                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",
+                           (unsigned int)MAXPRINTERLEN);
        }
 
        x_fclose(pcap_file);
        *_pcache = pcache;
+       talloc_free(frame);
        return true;
 }


-- 
Samba Shared Repository

Reply via email to