Ignore:
Timestamp:
May 26, 2009, 9:44:50 AM (16 years ago)
Author:
Herwig Bauernfeind
Message:

Update 3.2 branch to 3.2.6

Location:
branches/samba-3.2.x/source/printing
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/samba-3.2.x/source/printing/load.c

    r133 r228  
    6161        /* load all printcap printers */
    6262        if (lp_load_printers() && lp_servicenumber(PRINTERS_NAME) >= 0)
    63                 pcap_printer_fn(lp_add_one_printer);
     63                pcap_printer_fn(lp_add_one_printer, NULL);
    6464}
  • branches/samba-3.2.x/source/printing/nt_printing.c

    r136 r228  
    13801380        }
    13811381        close_file(fsp, NORMAL_CLOSE);
     1382        fsp = NULL;
    13821383
    13831384        /* Get file version info (if available) for new file */
     
    14201421        }
    14211422        close_file(fsp, NORMAL_CLOSE);
     1423        fsp = NULL;
    14221424
    14231425        if (use_version && (new_major != old_major || new_minor != old_minor)) {
  • branches/samba-3.2.x/source/printing/pcap.c

    r133 r228  
    6464
    6565
    66 typedef struct pcap_cache {
     66struct pcap_cache {
    6767        char *name;
    6868        char *comment;
    6969        struct pcap_cache *next;
    70 } pcap_cache_t;
    71 
    72 static pcap_cache_t *pcap_cache = NULL;
    73 
    74 bool pcap_cache_add(const char *name, const char *comment)
    75 {
    76         pcap_cache_t *p;
    77 
    78         if (name == NULL || ((p = SMB_MALLOC_P(pcap_cache_t)) == NULL))
    79                 return False;
     70};
     71
     72/* The systemwide printcap cache. */
     73static struct pcap_cache *pcap_cache = NULL;
     74
     75bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment)
     76{
     77        struct pcap_cache *p;
     78
     79        if (name == NULL || ((p = SMB_MALLOC_P(struct pcap_cache)) == NULL))
     80                return false;
    8081
    8182        p->name = SMB_STRDUP(name);
    8283        p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL;
    8384
    84         p->next = pcap_cache;
    85         pcap_cache = p;
    86 
    87         return True;
    88 }
    89 
    90 static void pcap_cache_destroy(pcap_cache_t *cache)
    91 {
    92         pcap_cache_t *p, *next;
    93 
    94         for (p = cache; p != NULL; p = next) {
     85        DEBUG(11,("pcap_cache_add_specific: Adding name %s info %s\n",
     86                p->name, p->comment ? p->comment : ""));
     87
     88        p->next = *ppcache;
     89        *ppcache = p;
     90
     91        return true;
     92}
     93
     94void pcap_cache_destroy_specific(struct pcap_cache **pp_cache)
     95{
     96        struct pcap_cache *p, *next;
     97
     98        for (p = *pp_cache; p != NULL; p = next) {
    9599                next = p->next;
    96100
     
    99103                SAFE_FREE(p);
    100104        }
     105        *pp_cache = NULL;
     106}
     107
     108bool pcap_cache_add(const char *name, const char *comment)
     109{
     110        return pcap_cache_add_specific(&pcap_cache, name, comment);
    101111}
    102112
     
    104114{
    105115        return (pcap_cache != NULL);
     116}
     117
     118void pcap_cache_replace(const struct pcap_cache *pcache)
     119{
     120        const struct pcap_cache *p;
     121
     122        pcap_cache_destroy_specific(&pcap_cache);
     123        for (p = pcache; p; p = p->next) {
     124                pcap_cache_add(p->name, p->comment);
     125        }
    106126}
    107127
     
    110130        const char *pcap_name = lp_printcapname();
    111131        bool pcap_reloaded = False;
    112         pcap_cache_t *tmp_cache = NULL;
     132        struct pcap_cache *tmp_cache = NULL;
    113133        XFILE *pcap_file;
    114134        char *pcap_line;
     
    224244
    225245        if (pcap_reloaded)
    226                 pcap_cache_destroy(tmp_cache);
     246                pcap_cache_destroy_specific(&tmp_cache);
    227247        else {
    228                 pcap_cache_destroy(pcap_cache);
     248                pcap_cache_destroy_specific(&pcap_cache);
    229249                pcap_cache = tmp_cache;
    230250        }
     
    236256bool pcap_printername_ok(const char *printername)
    237257{
    238         pcap_cache_t *p;
     258        struct pcap_cache *p;
    239259
    240260        for (p = pcap_cache; p != NULL; p = p->next)
     
    246266
    247267/***************************************************************************
    248 run a function on each printer name in the printcap file. The function is
    249 passed the primary name and the comment (if possible). Note the fn() takes
    250 strings in DOS codepage. This means the xxx_printer_fn() calls must be fixed
    251 to return DOS codepage. FIXME !! JRA.
    252 
    253 XXX: I'm not sure if this comment still applies.. Anyone?  -Rob
     268run a function on each printer name in the printcap file.
    254269***************************************************************************/
    255 void pcap_printer_fn(void (*fn)(char *, char *))
    256 {
    257         pcap_cache_t *p;
    258 
    259         for (p = pcap_cache; p != NULL; p = p->next)
    260                 fn(p->name, p->comment);
     270
     271void pcap_printer_fn_specific(const struct pcap_cache *pc,
     272                        void (*fn)(const char *, const char *, void *),
     273                        void *pdata)
     274{
     275        const struct pcap_cache *p;
     276
     277        for (p = pc; p != NULL; p = p->next)
     278                fn(p->name, p->comment, pdata);
    261279
    262280        return;
    263281}
     282
     283void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata)
     284{
     285        pcap_printer_fn_specific(pcap_cache, fn, pdata);
     286}
  • branches/samba-3.2.x/source/printing/print_cups.c

    r133 r228  
    33 *
    44 * Copyright 1999-2003 by Michael R Sweet.
     5 * Copyright 2008 Jeremy Allison.
    56 *
    67 * This program is free software; you can redistribute it and/or modify
     
    89 * the Free Software Foundation; either version 3 of the License, or
    910 * (at your option) any later version.
    10  * 
     11 *
    1112 * This program is distributed in the hope that it will be useful,
    1213 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1314 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1415 * GNU General Public License for more details.
    15  * 
     16 *
    1617 * You should have received a copy of the GNU General Public License
    1718 * along with this program; if not, see <http://www.gnu.org/licenses/>.
     19 */
     20
     21/*
     22 * JRA. Converted to utf8 pull/push.
    1823 */
    1924
     
    4146}
    4247
    43 static http_t *cups_connect(void)
     48static http_t *cups_connect(TALLOC_CTX *frame)
    4449{
    45         http_t *http;
    46         char *server, *p;
     50        http_t *http = NULL;
     51        char *server = NULL, *p = NULL;
    4752        int port;
    48        
     53
    4954        if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
    50                 server = smb_xstrdup(lp_cups_server());
     55                if (push_utf8_talloc(frame, &server, lp_cups_server()) == (size_t)-1) {
     56                        return NULL;
     57                }
    5158        } else {
    52                 server = smb_xstrdup(cupsServer());
     59                server = talloc_strdup(frame,cupsServer());
     60        }
     61        if (!server) {
     62                return NULL;
    5363        }
    5464
     
    6070                port = ippPort();
    6171        }
    62        
     72
    6373        DEBUG(10, ("connecting to cups server %s:%d\n",
    6474                   server, port));
    6575
    6676        if ((http = httpConnect(server, port)) == NULL) {
    67                 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n", 
     77                DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n",
    6878                         server, port, strerror(errno)));
    69                 SAFE_FREE(server);
    7079                return NULL;
    7180        }
    7281
    73         SAFE_FREE(server);
    7482        return http;
    7583}
    7684
    77 bool cups_cache_reload(void)
     85static void send_pcap_info(const char *name, const char *info, void *pd)
    7886{
     87        int fd = *(int *)pd;
     88        size_t namelen = name ? strlen(name)+1 : 0;
     89        size_t infolen = info ? strlen(info)+1 : 0;
     90
     91        DEBUG(11,("send_pcap_info: writing namelen %u\n", (unsigned int)namelen));
     92        if (sys_write(fd, &namelen, sizeof(namelen)) != sizeof(namelen)) {
     93                DEBUG(10,("send_pcap_info: namelen write failed %s\n",
     94                        strerror(errno)));
     95                return;
     96        }
     97        DEBUG(11,("send_pcap_info: writing infolen %u\n", (unsigned int)infolen));
     98        if (sys_write(fd, &infolen, sizeof(infolen)) != sizeof(infolen)) {
     99                DEBUG(10,("send_pcap_info: infolen write failed %s\n",
     100                        strerror(errno)));
     101                return;
     102        }
     103        if (namelen) {
     104                DEBUG(11,("send_pcap_info: writing name %s\n", name));
     105                if (sys_write(fd, name, namelen) != namelen) {
     106                        DEBUG(10,("send_pcap_info: name write failed %s\n",
     107                                strerror(errno)));
     108                        return;
     109                }
     110        }
     111        if (infolen) {
     112                DEBUG(11,("send_pcap_info: writing info %s\n", info));
     113                if (sys_write(fd, info, infolen) != infolen) {
     114                        DEBUG(10,("send_pcap_info: info write failed %s\n",
     115                                strerror(errno)));
     116                        return;
     117                }
     118        }
     119}
     120
     121static bool cups_cache_reload_async(int fd)
     122{
     123        TALLOC_CTX *frame = talloc_stackframe();
     124        struct pcap_cache *tmp_pcap_cache = NULL;
    79125        http_t          *http = NULL;           /* HTTP connection to server */
    80126        ipp_t           *request = NULL,        /* IPP Request */
     
    88134                          "printer-name",
    89135                          "printer-info"
    90                         };       
     136                        };
    91137        bool ret = False;
    92138
     
    103149        */
    104150
    105         if ((http = cups_connect()) == NULL) {
     151        if ((http = cups_connect(frame)) == NULL) {
    106152                goto out;
    107153        }
     
    124170
    125171        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    126                      "attributes-charset", NULL, cupsLangEncoding(language));
     172                     "attributes-charset", NULL, "utf-8");
    127173
    128174        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    164210                while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
    165211                        if (strcmp(attr->name, "printer-name") == 0 &&
    166                             attr->value_tag == IPP_TAG_NAME)
    167                                 name = attr->values[0].string.text;
     212                            attr->value_tag == IPP_TAG_NAME) {
     213                                pull_utf8_talloc(frame,
     214                                                &name,
     215                                                attr->values[0].string.text);
     216                        }
    168217
    169218                        if (strcmp(attr->name, "printer-info") == 0 &&
    170                             attr->value_tag == IPP_TAG_TEXT)
    171                                 info = attr->values[0].string.text;
     219                            attr->value_tag == IPP_TAG_TEXT) {
     220                                pull_utf8_talloc(frame,
     221                                                &info,
     222                                                attr->values[0].string.text);
     223                        }
    172224
    173225                        attr = attr->next;
     
    181233                        break;
    182234
    183                 if (!pcap_cache_add(name, info)) {
     235                if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
    184236                        goto out;
    185237                }
     
    204256
    205257        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    206                      "attributes-charset", NULL, cupsLangEncoding(language));
     258                     "attributes-charset", NULL, "utf-8");
    207259
    208260        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    244296                while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
    245297                        if (strcmp(attr->name, "printer-name") == 0 &&
    246                             attr->value_tag == IPP_TAG_NAME)
    247                                 name = attr->values[0].string.text;
     298                            attr->value_tag == IPP_TAG_NAME) {
     299                                pull_utf8_talloc(frame,
     300                                                &name,
     301                                                attr->values[0].string.text);
     302                        }
    248303
    249304                        if (strcmp(attr->name, "printer-info") == 0 &&
    250                             attr->value_tag == IPP_TAG_TEXT)
    251                                 info = attr->values[0].string.text;
     305                            attr->value_tag == IPP_TAG_TEXT) {
     306                                pull_utf8_talloc(frame,
     307                                                &info,
     308                                                attr->values[0].string.text);
     309                        }
    252310
    253311                        attr = attr->next;
     
    261319                        break;
    262320
    263                 if (!pcap_cache_add(name, info)) {
     321                if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) {
    264322                        goto out;
    265323                }
     
    278336                httpClose(http);
    279337
     338        /* Send all the entries up the pipe. */
     339        if (tmp_pcap_cache) {
     340                pcap_printer_fn_specific(tmp_pcap_cache,
     341                                send_pcap_info,
     342                                (void *)&fd);
     343
     344                pcap_cache_destroy_specific(&tmp_pcap_cache);
     345        }
     346        TALLOC_FREE(frame);
    280347        return ret;
    281348}
    282349
     350static struct pcap_cache *local_pcap_copy;
     351struct fd_event *cache_fd_event;
     352
     353static bool cups_pcap_load_async(int *pfd)
     354{
     355        int fds[2];
     356        pid_t pid;
     357
     358        *pfd = -1;
     359
     360        if (cache_fd_event) {
     361                DEBUG(3,("cups_pcap_load_async: already waiting for "
     362                        "a refresh event\n" ));
     363                return false;
     364        }
     365
     366        DEBUG(5,("cups_pcap_load_async: asynchronously loading cups printers\n"));
     367
     368        if (pipe(fds) == -1) {
     369                return false;
     370        }
     371
     372        pid = sys_fork();
     373        if (pid == (pid_t)-1) {
     374                DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
     375                        strerror(errno) ));
     376                close(fds[0]);
     377                close(fds[1]);
     378                return false;
     379        }
     380
     381        if (pid) {
     382                DEBUG(10,("cups_pcap_load_async: child pid = %u\n",
     383                        (unsigned int)pid ));
     384                /* Parent. */
     385                close(fds[1]);
     386                *pfd = fds[0];
     387                return true;
     388        }
     389
     390        /* Child. */
     391        if (!reinit_after_fork(smbd_messaging_context(), true)) {
     392                DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
     393                smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
     394        }
     395
     396        close(fds[0]);
     397        cups_cache_reload_async(fds[1]);
     398        close(fds[1]);
     399        _exit(0);
     400}
     401
     402static void cups_async_callback(struct event_context *event_ctx,
     403                                struct fd_event *event,
     404                                uint16 flags,
     405                                void *p)
     406{
     407        TALLOC_CTX *frame = talloc_stackframe();
     408        int fd = *(int *)p;
     409        struct pcap_cache *tmp_pcap_cache = NULL;
     410
     411        DEBUG(5,("cups_async_callback: callback received for printer data. "
     412                "fd = %d\n", fd));
     413
     414        while (1) {
     415                char *name = NULL, *info = NULL;
     416                size_t namelen = 0, infolen = 0;
     417                ssize_t ret = -1;
     418
     419                ret = sys_read(fd, &namelen, sizeof(namelen));
     420                if (ret == 0) {
     421                        /* EOF */
     422                        break;
     423                }
     424                if (ret != sizeof(namelen)) {
     425                        DEBUG(10,("cups_async_callback: namelen read failed %d %s\n",
     426                                errno, strerror(errno)));
     427                        break;
     428                }
     429
     430                DEBUG(11,("cups_async_callback: read namelen %u\n",
     431                        (unsigned int)namelen));
     432
     433                ret = sys_read(fd, &infolen, sizeof(infolen));
     434                if (ret == 0) {
     435                        /* EOF */
     436                        break;
     437                }
     438                if (ret != sizeof(infolen)) {
     439                        DEBUG(10,("cups_async_callback: infolen read failed %s\n",
     440                                strerror(errno)));
     441                        break;
     442                }
     443
     444                DEBUG(11,("cups_async_callback: read infolen %u\n",
     445                        (unsigned int)infolen));
     446
     447                if (namelen) {
     448                        name = TALLOC_ARRAY(frame, char, namelen);
     449                        if (!name) {
     450                                break;
     451                        }
     452                        ret = sys_read(fd, name, namelen);
     453                        if (ret == 0) {
     454                                /* EOF */
     455                                break;
     456                        }
     457                        if (ret != namelen) {
     458                                DEBUG(10,("cups_async_callback: name read failed %s\n",
     459                                        strerror(errno)));
     460                                break;
     461                        }
     462                        DEBUG(11,("cups_async_callback: read name %s\n",
     463                                name));
     464                } else {
     465                        name = NULL;
     466                }
     467                if (infolen) {
     468                        info = TALLOC_ARRAY(frame, char, infolen);
     469                        if (!info) {
     470                                break;
     471                        }
     472                        ret = sys_read(fd, info, infolen);
     473                        if (ret == 0) {
     474                                /* EOF */
     475                                break;
     476                        }
     477                        if (ret != infolen) {
     478                                DEBUG(10,("cups_async_callback: info read failed %s\n",
     479                                        strerror(errno)));
     480                                break;
     481                        }
     482                        DEBUG(11,("cups_async_callback: read info %s\n",
     483                                info));
     484                } else {
     485                        info = NULL;
     486                }
     487
     488                /* Add to our local pcap cache. */
     489                pcap_cache_add_specific(&tmp_pcap_cache, name, info);
     490                TALLOC_FREE(name);
     491                TALLOC_FREE(info);
     492        }
     493
     494        TALLOC_FREE(frame);
     495        if (tmp_pcap_cache) {
     496                /* We got a namelist, replace our local cache. */
     497                pcap_cache_destroy_specific(&local_pcap_copy);
     498                local_pcap_copy = tmp_pcap_cache;
     499
     500                /* And the systemwide pcap cache. */
     501                pcap_cache_replace(local_pcap_copy);
     502        } else {
     503                DEBUG(2,("cups_async_callback: failed to read a new "
     504                        "printer list\n"));
     505        }
     506        close(fd);
     507        TALLOC_FREE(p);
     508        TALLOC_FREE(cache_fd_event);
     509}
     510
     511bool cups_cache_reload(void)
     512{
     513        int *p_pipe_fd = TALLOC_P(NULL, int);
     514
     515        if (!p_pipe_fd) {
     516                return false;
     517        }
     518
     519        *p_pipe_fd = -1;
     520
     521        /* Set up an async refresh. */
     522        if (!cups_pcap_load_async(p_pipe_fd)) {
     523                return false;
     524        }
     525        if (!local_pcap_copy) {
     526                /* We have no local cache, wait directly for
     527                 * async refresh to complete.
     528                 */
     529                DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
     530                        *p_pipe_fd ));
     531
     532                cups_async_callback(smbd_event_context(),
     533                                        NULL,
     534                                        EVENT_FD_READ,
     535                                        (void *)p_pipe_fd);
     536                if (!local_pcap_copy) {
     537                        return false;
     538                }
     539        } else {
     540                /* Replace the system cache with our
     541                 * local copy. */
     542                pcap_cache_replace(local_pcap_copy);
     543
     544                DEBUG(10,("cups_cache_reload: async read on fd %d\n",
     545                        *p_pipe_fd ));
     546
     547                /* Trigger an event when the pipe can be read. */
     548                cache_fd_event = event_add_fd(smbd_event_context(),
     549                                        NULL, *p_pipe_fd,
     550                                        EVENT_FD_READ,
     551                                        cups_async_callback,
     552                                        (void *)p_pipe_fd);
     553                if (!cache_fd_event) {
     554                        close(*p_pipe_fd);
     555                        TALLOC_FREE(p_pipe_fd);
     556                        return false;
     557                }
     558        }
     559        return true;
     560}
    283561
    284562/*
     
    288566static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
    289567{
     568        TALLOC_CTX *frame = talloc_stackframe();
    290569        int             ret = 1;                /* Return value */
    291570        http_t          *http = NULL;           /* HTTP connection to server */
     
    293572                        *response = NULL;       /* IPP Response */
    294573        cups_lang_t     *language = NULL;       /* Default language */
     574        char *user = NULL;
    295575        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    296576
     
    308588        */
    309589
    310         if ((http = cups_connect()) == NULL) {
     590        if ((http = cups_connect(frame)) == NULL) {
    311591                goto out;
    312592        }
     
    330610
    331611        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    332                      "attributes-charset", NULL, cupsLangEncoding(language));
     612                     "attributes-charset", NULL, "utf-8");
    333613
    334614        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    339619        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    340620
     621        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     622                goto out;
     623        }
     624
    341625        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    342                      NULL, pjob->user);
     626                     NULL, user);
    343627
    344628       /*
     
    368652                httpClose(http);
    369653
     654        TALLOC_FREE(frame);
    370655        return ret;
    371656}
     
    378663static int cups_job_pause(int snum, struct printjob *pjob)
    379664{
     665        TALLOC_CTX *frame = talloc_stackframe();
    380666        int             ret = 1;                /* Return value */
    381667        http_t          *http = NULL;           /* HTTP connection to server */
     
    383669                        *response = NULL;       /* IPP Response */
    384670        cups_lang_t     *language = NULL;       /* Default language */
     671        char *user = NULL;
    385672        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    386673
     
    398685        */
    399686
    400         if ((http = cups_connect()) == NULL) {
     687        if ((http = cups_connect(frame)) == NULL) {
    401688                goto out;
    402689        }
     
    420707
    421708        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    422                      "attributes-charset", NULL, cupsLangEncoding(language));
     709                     "attributes-charset", NULL, "utf-8");
    423710
    424711        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    429716        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    430717
     718        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     719                goto out;
     720        }
    431721        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    432                      NULL, pjob->user);
     722                     NULL, user);
    433723
    434724       /*
     
    458748                httpClose(http);
    459749
     750        TALLOC_FREE(frame);
    460751        return ret;
    461752}
     
    468759static int cups_job_resume(int snum, struct printjob *pjob)
    469760{
     761        TALLOC_CTX *frame = talloc_stackframe();
    470762        int             ret = 1;                /* Return value */
    471763        http_t          *http = NULL;           /* HTTP connection to server */
     
    473765                        *response = NULL;       /* IPP Response */
    474766        cups_lang_t     *language = NULL;       /* Default language */
     767        char *user = NULL;
    475768        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    476769
     
    488781        */
    489782
    490         if ((http = cups_connect()) == NULL) {
     783        if ((http = cups_connect(frame)) == NULL) {
    491784                goto out;
    492785        }
     
    510803
    511804        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    512                      "attributes-charset", NULL, cupsLangEncoding(language));
     805                     "attributes-charset", NULL, "utf-8");
    513806
    514807        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    519812        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri);
    520813
     814        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     815                goto out;
     816        }
    521817        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    522                      NULL, pjob->user);
     818                     NULL, user);
    523819
    524820       /*
     
    548844                httpClose(http);
    549845
     846        TALLOC_FREE(frame);
    550847        return ret;
    551848}
     
    558855static int cups_job_submit(int snum, struct printjob *pjob)
    559856{
     857        TALLOC_CTX *frame = talloc_stackframe();
    560858        int             ret = 1;                /* Return value */
    561859        http_t          *http = NULL;           /* HTTP connection to server */
     
    568866        int             num_options = 0;
    569867        cups_option_t   *options = NULL;
     868        char *printername = NULL;
     869        char *user = NULL;
     870        char *jobname = NULL;
     871        char *cupsoptions = NULL;
     872        char *filename = NULL;
    570873        char addr[INET6_ADDRSTRLEN];
    571874
     
    582885        */
    583886
    584         if ((http = cups_connect()) == NULL) {
     887        if ((http = cups_connect(frame)) == NULL) {
    585888                goto out;
    586889        }
     
    605908
    606909        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    607                      "attributes-charset", NULL, cupsLangEncoding(language));
     910                     "attributes-charset", NULL, "utf-8");
    608911
    609912        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    610913                     "attributes-natural-language", NULL, language->language);
    611914
     915        if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) {
     916                goto out;
     917        }
    612918        slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    613                  PRINTERNAME(snum));
     919                 printername);
    614920
    615921        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
    616922                     "printer-uri", NULL, uri);
    617923
     924        if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) {
     925                goto out;
     926        }
    618927        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    619                      NULL, pjob->user);
     928                     NULL, user);
    620929
    621930        clientname = client_name(get_client_fd());
     
    628937                      clientname);
    629938
    630         if (asprintf(&new_jobname,"%s%.8u %s", PRINT_SPOOL_PREFIX,
    631                         (unsigned int)pjob->smbjob, pjob->jobname) < 0) {
     939        if (push_utf8_talloc(frame, &jobname, pjob->jobname) == (size_t)-1) {
     940                goto out;
     941        }
     942        new_jobname = talloc_asprintf(frame,
     943                        "%s%.8u %s", PRINT_SPOOL_PREFIX,
     944                        (unsigned int)pjob->smbjob,
     945                        jobname);
     946        if (new_jobname == NULL) {
    632947                goto out;
    633948        }
     
    636951                     new_jobname);
    637952
    638         /* 
    639          * add any options defined in smb.conf 
     953        /*
     954         * add any options defined in smb.conf
    640955         */
    641956
     957        if (push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum)) == (size_t)-1) {
     958                goto out;
     959        }
    642960        num_options = 0;
    643961        options     = NULL;
    644         num_options = cupsParseOptions(lp_cups_options(snum), num_options, &options);
     962        num_options = cupsParseOptions(cupsoptions, num_options, &options);
    645963
    646964        if ( num_options )
    647                 cupsEncodeOptions(request, num_options, options); 
     965                cupsEncodeOptions(request, num_options, options);
    648966
    649967       /*
     
    651969        */
    652970
    653         slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum));
    654 
     971        slprintf(uri, sizeof(uri) - 1, "/printers/%s", printername);
     972
     973        if (push_utf8_talloc(frame, &filename, pjob->filename) == (size_t)-1) {
     974                goto out;
     975        }
    655976        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    656977                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
     
    6791000                httpClose(http);
    6801001
    681         SAFE_FREE(new_jobname);
     1002        TALLOC_FREE(frame);
    6821003
    6831004        return ret;
     
    6911012               enum printing_types printing_type,
    6921013               char *lpq_command,
    693                print_queue_struct **q, 
     1014               print_queue_struct **q,
    6941015               print_status_struct *status)
    6951016{
    696         fstring         printername;
     1017        TALLOC_CTX *frame = talloc_stackframe();
     1018        char *printername = NULL;
    6971019        http_t          *http = NULL;           /* HTTP connection to server */
    6981020        ipp_t           *request = NULL,        /* IPP Request */
     
    7051027        print_queue_struct *queue = NULL,       /* Queue entries */
    7061028                        *temp;          /* Temporary pointer for queue */
    707         const char      *user_name,     /* job-originating-user-name attribute */
    708                         *job_name;      /* job-name attribute */
     1029        char            *user_name = NULL,      /* job-originating-user-name attribute */
     1030                        *job_name = NULL;       /* job-name attribute */
    7091031        int             job_id;         /* job-id attribute */
    7101032        int             job_k_octets;   /* job-k-octets attribute */
     
    7301052        *q = NULL;
    7311053
    732         /* HACK ALERT!!!  The problem with support the 'printer name' 
    733            option is that we key the tdb off the sharename.  So we will 
    734            overload the lpq_command string to pass in the printername 
    735            (which is basically what we do for non-cups printers ... using 
     1054        /* HACK ALERT!!!  The problem with support the 'printer name'
     1055           option is that we key the tdb off the sharename.  So we will
     1056           overload the lpq_command string to pass in the printername
     1057           (which is basically what we do for non-cups printers ... using
    7361058           the lpq_command to get the queue listing). */
    7371059
    738         fstrcpy( printername, lpq_command );
    739 
    740         DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printername, q, status));
     1060        if (push_utf8_talloc(frame, &printername, lpq_command) == (size_t)-1) {
     1061                goto out;
     1062        }
     1063        DEBUG(5,("cups_queue_get(%s, %p, %p)\n", lpq_command, q, status));
    7411064
    7421065       /*
     
    7501073        */
    7511074
    752         if ((http = cups_connect()) == NULL) {
     1075        if ((http = cups_connect(frame)) == NULL) {
    7531076                goto out;
    7541077        }
     
    7781101
    7791102        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    780                      "attributes-charset", NULL, cupsLangEncoding(language));
     1103                     "attributes-charset", NULL, "utf-8");
    7811104
    7821105        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    8831206
    8841207                        if (strcmp(attr->name, "job-name") == 0 &&
    885                             attr->value_tag == IPP_TAG_NAME)
    886                                 job_name = attr->values[0].string.text;
     1208                            attr->value_tag == IPP_TAG_NAME) {
     1209                                pull_utf8_talloc(frame,
     1210                                                &job_name,
     1211                                                attr->values[0].string.text);
     1212                        }
    8871213
    8881214                        if (strcmp(attr->name, "job-originating-user-name") == 0 &&
    889                             attr->value_tag == IPP_TAG_NAME)
    890                                 user_name = attr->values[0].string.text;
     1215                            attr->value_tag == IPP_TAG_NAME) {
     1216                                pull_utf8_talloc(frame,
     1217                                                &user_name,
     1218                                                attr->values[0].string.text);
     1219                        }
    8911220
    8921221                        attr = attr->next;
     
    9121241                temp->priority = job_priority;
    9131242                temp->time     = job_time;
    914                 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
    915                 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
     1243                strlcpy(temp->fs_user, user_name, sizeof(temp->fs_user));
     1244                strlcpy(temp->fs_file, job_name, sizeof(temp->fs_file));
    9161245
    9171246                qcount ++;
     
    9401269
    9411270        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    942                      "attributes-charset", NULL, cupsLangEncoding(language));
     1271                     "attributes-charset", NULL, "utf-8");
    9431272
    9441273        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
     
    9831312
    9841313        if ((attr = ippFindAttribute(response, "printer-state-message",
    985                                      IPP_TAG_TEXT)) != NULL)
    986                 fstrcpy(status->message, attr->values[0].string.text);
     1314                                     IPP_TAG_TEXT)) != NULL) {
     1315                char *msg = NULL;
     1316                pull_utf8_talloc(frame, &msg, attr->values[0].string.text);
     1317                fstrcpy(status->message, msg);
     1318        }
    9871319
    9881320       /*
     
    10021334                httpClose(http);
    10031335
     1336        TALLOC_FREE(frame);
    10041337        return qcount;
    10051338}
     
    10121345static int cups_queue_pause(int snum)
    10131346{
     1347        TALLOC_CTX *frame = talloc_stackframe();
    10141348        int             ret = 1;                /* Return value */
    10151349        http_t          *http = NULL;           /* HTTP connection to server */
     
    10171351                        *response = NULL;       /* IPP Response */
    10181352        cups_lang_t     *language = NULL;       /* Default language */
     1353        char *printername = NULL;
     1354        char *username = NULL;
    10191355        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    10201356
     
    10321368         */
    10331369
    1034         if ((http = cups_connect()) == NULL) {
     1370        if ((http = cups_connect(frame)) == NULL) {
    10351371                goto out;
    10361372        }
     
    10541390
    10551391        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1056                      "attributes-charset", NULL, cupsLangEncoding(language));
     1392                     "attributes-charset", NULL, "utf-8");
    10571393
    10581394        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    10591395                     "attributes-natural-language", NULL, language->language);
    10601396
     1397        if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) {
     1398                goto out;
     1399        }
    10611400        slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    1062                  PRINTERNAME(snum));
     1401                 printername);
    10631402
    10641403        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
    10651404
     1405        if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) {
     1406                goto out;
     1407        }
    10661408        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    1067                      NULL, current_user_info.unix_name);
     1409                     NULL, username);
    10681410
    10691411       /*
     
    10931435                httpClose(http);
    10941436
     1437        TALLOC_FREE(frame);
    10951438        return ret;
    10961439}
     
    11031446static int cups_queue_resume(int snum)
    11041447{
     1448        TALLOC_CTX *frame = talloc_stackframe();
    11051449        int             ret = 1;                /* Return value */
    11061450        http_t          *http = NULL;           /* HTTP connection to server */
     
    11081452                        *response = NULL;       /* IPP Response */
    11091453        cups_lang_t     *language = NULL;       /* Default language */
     1454        char *printername = NULL;
     1455        char *username = NULL;
    11101456        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    11111457
     
    11231469        */
    11241470
    1125         if ((http = cups_connect()) == NULL) {
     1471        if ((http = cups_connect(frame)) == NULL) {
    11261472                goto out;
    11271473        }
     
    11451491
    11461492        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1147                      "attributes-charset", NULL, cupsLangEncoding(language));
     1493                     "attributes-charset", NULL, "utf-8");
    11481494
    11491495        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    11501496                     "attributes-natural-language", NULL, language->language);
    11511497
     1498        if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) {
     1499                goto out;
     1500        }
    11521501        slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    1153                  PRINTERNAME(snum));
     1502                 printername);
    11541503
    11551504        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
    11561505
     1506        if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) {
     1507                goto out;
     1508        }
    11571509        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
    1158                      NULL, current_user_info.unix_name);
     1510                     NULL, username);
    11591511
    11601512       /*
     
    11841536                httpClose(http);
    11851537
     1538        TALLOC_FREE(frame);
    11861539        return ret;
    11871540}
     
    12051558bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
    12061559{
     1560        TALLOC_CTX *frame = talloc_stackframe();
    12071561        http_t          *http = NULL;           /* HTTP connection to server */
    12081562        ipp_t           *request = NULL,        /* IPP Request */
     
    12101564        ipp_attribute_t *attr;          /* Current attribute */
    12111565        cups_lang_t     *language = NULL;       /* Default language */
    1212         char            *name,          /* printer-name attribute */
    1213                         *info,          /* printer-info attribute */
    1214                         *location;      /* printer-location attribute */
    12151566        char            uri[HTTP_MAX_URI];
     1567        char *server = NULL;
     1568        char *sharename = NULL;
     1569        char *name = NULL;
    12161570        static const char *requested[] =/* Requested attributes */
    12171571                        {
     
    12341588         */
    12351589
    1236         if ((http = cups_connect()) == NULL) {
     1590        if ((http = cups_connect(frame)) == NULL) {
    12371591                goto out;
    12381592        }
     
    12461600
    12471601        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1248                      "attributes-charset", NULL, cupsLangEncoding(language));
     1602                     "attributes-charset", NULL, "utf-8");
    12491603
    12501604        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    12511605                     "attributes-natural-language", NULL, language->language);
    12521606
     1607        if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
     1608                if (push_utf8_talloc(frame, &server, lp_cups_server()) == (size_t)-1) {
     1609                        goto out;
     1610                }
     1611        } else {
     1612                server = talloc_strdup(frame,cupsServer());
     1613        }
     1614        if (server) {
     1615                goto out;
     1616        }
     1617        if (push_utf8_talloc(frame, &sharename, printer->sharename) == (size_t)-1) {
     1618                goto out;
     1619        }
    12531620        slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s",
    1254                  lp_cups_server(), printer->sharename);
     1621                 server, sharename);
    12551622
    12561623        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
     
    12871654                 */
    12881655
    1289                 name       = NULL;
    1290                 info       = NULL;
    1291                 location   = NULL;
    1292 
    12931656                while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
     1657                        if (strcmp(attr->name, "printer-name") == 0 &&
     1658                            attr->value_tag == IPP_TAG_NAME) {
     1659                                pull_utf8_talloc(frame,
     1660                                                &name,
     1661                                                attr->values[0].string.text);
     1662                        }
     1663
    12941664                        /* Grab the comment if we don't have one */
    12951665                        if ( (strcmp(attr->name, "printer-info") == 0)
    12961666                             && (attr->value_tag == IPP_TAG_TEXT)
    1297                              && !strlen(printer->comment) ) 
     1667                             && !strlen(printer->comment) )
    12981668                        {
     1669                                char *comment = NULL;
     1670                                pull_utf8_talloc(frame,
     1671                                        &comment,
     1672                                        attr->values[0].string.text);
    12991673                                DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
    1300                                          attr->values[0].string.text));                         
     1674                                         comment));
    13011675                                strlcpy(printer->comment,
    1302                                                 attr->values[0].string.text,
    1303                                                 sizeof(printer->comment));
     1676                                        comment,
     1677                                        sizeof(printer->comment));
    13041678                        }
    13051679
    1306                         /* Grab the location if we don't have one */ 
     1680                        /* Grab the location if we don't have one */
    13071681                        if ( (strcmp(attr->name, "printer-location") == 0)
    1308                              && (attr->value_tag == IPP_TAG_TEXT) 
     1682                             && (attr->value_tag == IPP_TAG_TEXT)
    13091683                             && !strlen(printer->location) )
    13101684                        {
     1685                                char *location = NULL;
     1686                                pull_utf8_talloc(frame,
     1687                                        &location,
     1688                                        attr->values[0].string.text);
    13111689                                DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
    1312                                          attr->values[0].string.text));                         
    1313                                 fstrcpy(printer->location,attr->values[0].string.text);
     1690                                         location));
     1691                                strlcpy(printer->location,
     1692                                        location,
     1693                                        sizeof(printer->location));
    13141694                        }
    13151695
     
    13181698
    13191699                /*
    1320                  * See if we have everything needed...
     1700                 * We have everything needed...
    13211701                 */
    13221702
    1323                 if (name == NULL)
     1703                if (name != NULL)
    13241704                        break;
    1325 
    13261705        }
    13271706
     
    13381717                httpClose(http);
    13391718
     1719        TALLOC_FREE(frame);
    13401720        return ret;
    13411721}
  • branches/samba-3.2.x/source/printing/printfsp.c

    r133 r228  
    2929
    3030NTSTATUS print_fsp_open(connection_struct *conn, const char *fname,
    31                         files_struct **result)
     31                        files_struct *fsp)
    3232{
    3333        int jobid;
    3434        SMB_STRUCT_STAT sbuf;
    35         files_struct *fsp;
    3635        fstring name;
    3736        NTSTATUS status;
    38 
    39         status = file_new(conn, &fsp);
    40         if(!NT_STATUS_IS_OK(status)) {
    41                 return status;
    42         }
    4337
    4438        fstrcpy( name, "Remote Downlevel Document");
     
    5549        if (jobid == -1) {
    5650                status = map_nt_error_from_unix(errno);
    57                 file_free(fsp);
    5851                return status;
    5952        }
     
    6457                /* We need to delete the entry in the tdb. */
    6558                pjob_delete(lp_const_servicename(SNUM(conn)), jobid);
    66                 file_free(fsp);
    6759                return NT_STATUS_ACCESS_DENIED; /* No errno around here */
    6860        }
     
    8375        fsp->is_directory = False;
    8476        string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
    85         fsp->wcp = NULL; 
     77        fsp->wcp = NULL;
    8678        SMB_VFS_FSTAT(fsp, &sbuf);
    8779        fsp->mode = sbuf.st_mode;
    8880        fsp->file_id = vfs_file_id_from_sbuf(conn, &sbuf);
    8981
    90         conn->num_files_open++;
    91 
    92         *result = fsp;
    9382        return NT_STATUS_OK;
    9483}
  • branches/samba-3.2.x/source/printing/printing.c

    r141 r228  
    13951395void start_background_queue(void)
    13961396{
     1397        /* Use local variables for this as we don't
     1398         * need to save the parent side of this, just
     1399         * ensure it closes when the process exits.
     1400         */
     1401        int pause_pipe[2];
     1402
    13971403        DEBUG(3,("start_background_queue: Starting background LPQ thread\n"));
     1404
     1405        if (pipe(pause_pipe) == -1) {
     1406                DEBUG(5,("start_background_queue: cannot create pipe. %s\n", strerror(errno) ));
     1407                exit(1);
     1408        }
     1409
    13981410        background_lpq_updater_pid = sys_fork();
    13991411
     
    14071419                DEBUG(5,("start_background_queue: background LPQ thread started\n"));
    14081420
     1421                close(pause_pipe[0]);
     1422                pause_pipe[0] = -1;
     1423
    14091424                if (!reinit_after_fork(smbd_messaging_context(), true)) {
    14101425                        DEBUG(0,("reinit_after_fork() failed\n"));
     
    14211436                messaging_register(smbd_messaging_context(), NULL,
    14221437                                   MSG_PRINTER_UPDATE, print_queue_receive);
    1423                
     1438
    14241439                DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
    14251440                while (1) {
    1426                         pause();
    1427                        
     1441                        fd_set pause_fds;
     1442                        int pause_select;
     1443
     1444                        FD_ZERO(&pause_fds);
     1445                        FD_SET(pause_pipe[1], &pause_fds);
     1446                        pause_select = sys_select(pause_pipe[1]+1, &pause_fds, NULL, NULL, NULL);
     1447                        /* If pause_pipe[0] is closed it means the parent smbd
     1448                         * and children exited or aborted. */
     1449                        if (pause_select == 1) {
     1450                                exit_server_cleanly(NULL);
     1451                        }
     1452
    14281453                        /* check for some essential signals first */
    1429                        
     1454
    14301455                        if (got_sig_term) {
    14311456                                exit_server_cleanly(NULL);
     
    14381463                                reload_after_sighup = 0;
    14391464                        }
    1440                        
     1465
    14411466                        /* now check for messages */
    1442                        
     1467
    14431468                        DEBUG(10,("start_background_queue: background LPQ thread got a message\n"));
    14441469                        message_dispatch(smbd_messaging_context());
     
    14501475                }
    14511476        }
     1477
     1478        close(pause_pipe[1]);
    14521479}
    14531480
Note: See TracChangeset for help on using the changeset viewer.