Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/printing/print_cups.c

    r664 r745  
    2525#include "includes.h"
    2626#include "printing.h"
     27#include "printing/pcap.h"
    2728#include "librpc/gen_ndr/ndr_printcap.h"
    2829
     
    4142****************************************************************/
    4243
    43 static void gotalarm_sig(void)
     44static void gotalarm_sig(int signum)
    4445{
    4546        gotalarm = 1;
     
    9596
    9697        if (timeout) {
    97                 CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
     98                CatchSignal(SIGALRM, gotalarm_sig);
    9899                alarm(timeout);
    99100        }
     
    106107
    107108
    108         CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
     109        CatchSignal(SIGALRM, SIG_IGN);
    109110        alarm(0);
    110111
     
    131132        }
    132133
    133         DEBUG(10, ("successfully sent blob of len %ld\n", (int64_t)ret));
     134        DEBUG(10, ("successfully sent blob of len %d\n", (int)ret));
    134135        return true;
    135136}
     
    156157        }
    157158
    158         DEBUG(10, ("successfully recvd blob of len %ld\n", (int64_t)ret));
     159        DEBUG(10, ("successfully recvd blob of len %d\n", (int)ret));
    159160        return true;
    160161}
     
    167168        char *name;
    168169        char *info;
     170        char *location = NULL;
    169171        struct pcap_printer *printer;
    170172        bool ret_ok = false;
     
    204206                                if (!pull_utf8_talloc(mem_ctx,
    205207                                                &info,
     208                                                attr->values[0].string.text,
     209                                                &size)) {
     210                                        goto err_out;
     211                                }
     212                        }
     213
     214                        if (strcmp(attr->name, "printer-location") == 0 &&
     215                            attr->value_tag == IPP_TAG_TEXT) {
     216                                if (!pull_utf8_talloc(mem_ctx,
     217                                                &location,
    206218                                                attr->values[0].string.text,
    207219                                                &size)) {
     
    233245                pcap_data->printers[pcap_data->count].name = name;
    234246                pcap_data->printers[pcap_data->count].info = info;
     247                pcap_data->printers[pcap_data->count].location = location;
    235248                pcap_data->count++;
    236249        }
     
    256269                        {
    257270                          "printer-name",
    258                           "printer-info"
     271                          "printer-info",
     272                          "printer-location"
    259273                        };
    260274        bool ret = False;
     
    368382
    369383        ret = false;
    370         ndr_ret = ndr_push_struct_blob(&pcap_blob, frame, NULL, &pcap_data,
     384        ndr_ret = ndr_push_struct_blob(&pcap_blob, frame, &pcap_data,
    371385                                       (ndr_push_flags_fn_t)ndr_push_pcap_data);
    372386        if (ndr_ret == NDR_ERR_SUCCESS) {
     
    378392}
    379393
    380 static struct pcap_cache *local_pcap_copy;
    381 struct fd_event *cache_fd_event;
    382 
    383 static bool cups_pcap_load_async(int *pfd)
     394static struct fd_event *cache_fd_event;
     395
     396static bool cups_pcap_load_async(struct tevent_context *ev,
     397                                 struct messaging_context *msg_ctx,
     398                                 int *pfd)
    384399{
    385400        int fds[2];
    386401        pid_t pid;
     402        NTSTATUS status;
    387403
    388404        *pfd = -1;
     
    422438        close_all_print_db();
    423439
    424         if (!NT_STATUS_IS_OK(reinit_after_fork(smbd_messaging_context(),
    425                                                smbd_event_context(), true))) {
     440        status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
     441        if (!NT_STATUS_IS_OK(status)) {
    426442                DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
    427443                smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
     
    436452struct cups_async_cb_args {
    437453        int pipe_fd;
    438         void (*post_cache_fill_fn)(void);
     454        struct event_context *event_ctx;
     455        struct messaging_context *msg_ctx;
     456        void (*post_cache_fill_fn)(struct event_context *,
     457                                   struct messaging_context *);
    439458};
    440459
     
    462481        }
    463482
    464         ndr_ret = ndr_pull_struct_blob(&pcap_blob, frame, NULL, &pcap_data,
     483        ndr_ret = ndr_pull_struct_blob(&pcap_blob, frame, &pcap_data,
    465484                                       (ndr_pull_flags_fn_t)ndr_pull_pcap_data);
    466485        if (ndr_ret != NDR_ERR_SUCCESS) {
     
    477496                ret_ok = pcap_cache_add_specific(&tmp_pcap_cache,
    478497                                                 pcap_data.printers[i].name,
    479                                                  pcap_data.printers[i].info);
     498                                                 pcap_data.printers[i].info,
     499                                                 pcap_data.printers[i].location);
    480500                if (!ret_ok) {
    481501                        DEBUG(0, ("failed to add to tmp pcap cache\n"));
    482                         break;
     502                        goto err_out;
    483503                }
    484504        }
    485505
     506        /* replace the system-wide pcap cache with a (possibly empty) new one */
     507        ret_ok = pcap_cache_replace(tmp_pcap_cache);
    486508        if (!ret_ok) {
    487                 DEBUG(0,("failed to read a new printer list\n"));
    488                 pcap_cache_destroy_specific(&tmp_pcap_cache);
    489         } else {
    490                 /* We got a possibly empty namelist, replace our local cache. */
    491                 pcap_cache_destroy_specific(&local_pcap_copy);
    492                 local_pcap_copy = tmp_pcap_cache;
    493 
    494                 /* And the systemwide pcap cache. */
    495                 pcap_cache_replace(local_pcap_copy);
    496 
    497                 /* Caller may have requested post cache fill callback */
    498                 if (cb_args->post_cache_fill_fn) {
    499                         cb_args->post_cache_fill_fn();
    500                 }
     509                DEBUG(0, ("failed to replace pcap cache\n"));
     510        } else if (cb_args->post_cache_fill_fn != NULL) {
     511                /* Caller requested post cache fill callback */
     512                cb_args->post_cache_fill_fn(cb_args->event_ctx,
     513                                            cb_args->msg_ctx);
    501514        }
    502515err_out:
     516        pcap_cache_destroy_specific(&tmp_pcap_cache);
    503517        TALLOC_FREE(frame);
    504518        close(cb_args->pipe_fd);
     
    507521}
    508522
    509 bool cups_cache_reload(void (*post_cache_fill_fn)(void))
     523bool cups_cache_reload(struct tevent_context *ev,
     524                       struct messaging_context *msg_ctx,
     525                       void (*post_cache_fill_fn)(struct tevent_context *,
     526                                                  struct messaging_context *))
    510527{
    511528        struct cups_async_cb_args *cb_args;
     
    513530
    514531        cb_args = TALLOC_P(NULL, struct cups_async_cb_args);
    515         if (!cb_args) {
     532        if (cb_args == NULL) {
    516533                return false;
    517534        }
     535
    518536        cb_args->post_cache_fill_fn = post_cache_fill_fn;
     537        cb_args->event_ctx = ev;
     538        cb_args->msg_ctx = msg_ctx;
    519539        p_pipe_fd = &cb_args->pipe_fd;
    520540        *p_pipe_fd = -1;
    521541
    522542        /* Set up an async refresh. */
    523         if (!cups_pcap_load_async(p_pipe_fd)) {
     543        if (!cups_pcap_load_async(ev, msg_ctx, p_pipe_fd)) {
    524544                talloc_free(cb_args);
    525545                return false;
    526546        }
    527         if (!local_pcap_copy) {
    528                 /* We have no local cache, wait directly for
    529                  * async refresh to complete.
    530                  */
    531                 DEBUG(10,("cups_cache_reload: sync read on fd %d\n",
    532                         *p_pipe_fd ));
    533 
    534                 cups_async_callback(smbd_event_context(),
    535                                         NULL,
    536                                         EVENT_FD_READ,
    537                                         (void *)cb_args);
    538                 if (!local_pcap_copy) {
    539                         return false;
    540                 }
    541         } else {
    542                 /* Replace the system cache with our
    543                  * local copy. */
    544                 pcap_cache_replace(local_pcap_copy);
    545 
    546                 DEBUG(10,("cups_cache_reload: async read on fd %d\n",
    547                         *p_pipe_fd ));
    548 
    549                 /* Trigger an event when the pipe can be read. */
    550                 cache_fd_event = event_add_fd(smbd_event_context(),
    551                                         NULL, *p_pipe_fd,
    552                                         EVENT_FD_READ,
    553                                         cups_async_callback,
    554                                         (void *)cb_args);
    555                 if (!cache_fd_event) {
    556                         close(*p_pipe_fd);
    557                         talloc_free(cb_args);
    558                         return false;
    559                 }
    560         }
     547
     548        DEBUG(10,("cups_cache_reload: async read on fd %d\n",
     549                *p_pipe_fd ));
     550
     551        /* Trigger an event when the pipe can be read. */
     552        cache_fd_event = event_add_fd(ev,
     553                                NULL, *p_pipe_fd,
     554                                EVENT_FD_READ,
     555                                cups_async_callback,
     556                                (void *)cb_args);
     557        if (!cache_fd_event) {
     558                close(*p_pipe_fd);
     559                TALLOC_FREE(cb_args);
     560                return false;
     561        }
     562
    561563        return true;
    562564}
     
    865867        cups_lang_t     *language = NULL;       /* Default language */
    866868        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
    867         const char      *clientname = NULL;     /* hostname of client for job-originating-host attribute */
    868869        char *new_jobname = NULL;
    869870        int             num_options = 0;
     
    876877        size_t size;
    877878        uint32_t jobid = (uint32_t)-1;
    878         char addr[INET6_ADDRSTRLEN];
    879879
    880880        DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
     
    918918                     "attributes-natural-language", NULL, language->language);
    919919
    920         if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
     920        if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
     921                              &size)) {
    921922                goto out;
    922923        }
     
    933934                     NULL, user);
    934935
    935         clientname = client_name(get_client_fd());
    936         if (strcmp(clientname, "UNKNOWN") == 0) {
    937                 clientname = client_addr(get_client_fd(),addr,sizeof(addr));
    938         }
    939 
    940936        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
    941937                     "job-originating-host-name", NULL,
    942                       clientname);
     938                     pjob->clientmachine);
    943939
    944940        /* Get the jobid from the filename. */
     
    989985        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    990986                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
    991                         DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum),
     987                        DEBUG(0,("Unable to print file to %s - %s\n",
     988                                 lp_printername(snum),
    992989                                 ippErrorString(cupsLastError())));
    993990                } else {
     
    1002999                }
    10031000        } else {
    1004                 DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
     1001                DEBUG(0,("Unable to print file to `%s' - %s\n",
     1002                         lp_printername(snum),
    10051003                         ippErrorString(cupsLastError())));
    10061004        }
     
    14271425                     "attributes-natural-language", NULL, language->language);
    14281426
    1429         if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
     1427        if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
     1428                              &size)) {
    14301429                goto out;
    14311430        }
     
    14471446        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    14481447                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
    1449                         DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
     1448                        DEBUG(0,("Unable to pause printer %s - %s\n",
     1449                                 lp_printername(snum),
    14501450                                ippErrorString(cupsLastError())));
    14511451                } else {
     
    14531453                }
    14541454        } else {
    1455                 DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum),
     1455                DEBUG(0,("Unable to pause printer %s - %s\n",
     1456                         lp_printername(snum),
    14561457                        ippErrorString(cupsLastError())));
    14571458        }
     
    15281529                     "attributes-natural-language", NULL, language->language);
    15291530
    1530         if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) {
     1531        if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
     1532                              &size)) {
    15311533                goto out;
    15321534        }
     
    15481550        if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) {
    15491551                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
    1550                         DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
     1552                        DEBUG(0,("Unable to resume printer %s - %s\n",
     1553                                 lp_printername(snum),
    15511554                                ippErrorString(cupsLastError())));
    15521555                } else {
     
    15541557                }
    15551558        } else {
    1556                 DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum),
     1559                DEBUG(0,("Unable to resume printer %s - %s\n",
     1560                         lp_printername(snum),
    15571561                        ippErrorString(cupsLastError())));
    15581562        }
     
    15881592};
    15891593
    1590 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer)
    1591 {
    1592         TALLOC_CTX *frame = talloc_stackframe();
    1593         http_t          *http = NULL;           /* HTTP connection to server */
    1594         ipp_t           *request = NULL,        /* IPP Request */
    1595                         *response = NULL;       /* IPP Response */
    1596         ipp_attribute_t *attr;          /* Current attribute */
    1597         cups_lang_t     *language = NULL;       /* Default language */
    1598         char            uri[HTTP_MAX_URI];
    1599         char *sharename = NULL;
    1600         char *name = NULL;
    1601         static const char *requested[] =/* Requested attributes */
    1602                         {
    1603                           "printer-name",
    1604                           "printer-info",
    1605                           "printer-location"
    1606                         };
    1607         bool ret = False;
    1608         size_t size;
    1609 
    1610         DEBUG(5, ("pulling %s location\n", printer->sharename));
    1611 
    1612         /*
    1613          * Make sure we don't ask for passwords...
    1614          */
    1615 
    1616         cupsSetPasswordCB(cups_passwd_cb);
    1617 
    1618         /*
    1619          * Try to connect to the server...
    1620          */
    1621 
    1622         if ((http = cups_connect(frame)) == NULL) {
    1623                 goto out;
    1624         }
    1625 
    1626         request = ippNew();
    1627 
    1628         request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
    1629         request->request.op.request_id   = 1;
    1630 
    1631         language = cupsLangDefault();
    1632 
    1633         ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
    1634                      "attributes-charset", NULL, "utf-8");
    1635 
    1636         ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
    1637                      "attributes-natural-language", NULL, language->language);
    1638 
    1639         if (!push_utf8_talloc(frame, &sharename, printer->sharename, &size)) {
    1640                 goto out;
    1641         }
    1642         slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s",
    1643                  sharename);
    1644 
    1645         ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
    1646                      "printer-uri", NULL, uri);
    1647 
    1648         ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
    1649                       "requested-attributes",
    1650                       (sizeof(requested) / sizeof(requested[0])),
    1651                       NULL, requested);
    1652 
    1653         /*
    1654          * Do the request and get back a response...
    1655          */
    1656 
    1657         if ((response = cupsDoRequest(http, request, "/")) == NULL) {
    1658                 DEBUG(0,("Unable to get printer attributes - %s\n",
    1659                          ippErrorString(cupsLastError())));
    1660                 goto out;
    1661         }
    1662 
    1663         for (attr = response->attrs; attr != NULL;) {
    1664                 /*
    1665                  * Skip leading attributes until we hit a printer...
    1666                  */
    1667 
    1668                 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
    1669                         attr = attr->next;
    1670 
    1671                 if (attr == NULL)
    1672                         break;
    1673 
    1674                 /*
    1675                  * Pull the needed attributes from this printer...
    1676                  */
    1677 
    1678                 while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) {
    1679                         if (strcmp(attr->name, "printer-name") == 0 &&
    1680                             attr->value_tag == IPP_TAG_NAME) {
    1681                                 if (!pull_utf8_talloc(frame,
    1682                                                 &name,
    1683                                                 attr->values[0].string.text,
    1684                                                 &size)) {
    1685                                         goto out;
    1686                                 }
    1687                         }
    1688 
    1689                         /* Grab the comment if we don't have one */
    1690                         if ( (strcmp(attr->name, "printer-info") == 0)
    1691                              && (attr->value_tag == IPP_TAG_TEXT)
    1692                              && !strlen(printer->comment) )
    1693                         {
    1694                                 char *comment = NULL;
    1695                                 if (!pull_utf8_talloc(frame,
    1696                                                 &comment,
    1697                                                 attr->values[0].string.text,
    1698                                                 &size)) {
    1699                                         goto out;
    1700                                 }
    1701                                 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n",
    1702                                          comment));
    1703                                 strlcpy(printer->comment,
    1704                                         comment,
    1705                                         sizeof(printer->comment));
    1706                         }
    1707 
    1708                         /* Grab the location if we don't have one */
    1709                         if ( (strcmp(attr->name, "printer-location") == 0)
    1710                              && (attr->value_tag == IPP_TAG_TEXT)
    1711                              && !strlen(printer->location) )
    1712                         {
    1713                                 char *location = NULL;
    1714                                 if (!pull_utf8_talloc(frame,
    1715                                                 &location,
    1716                                                 attr->values[0].string.text,
    1717                                                 &size)) {
    1718                                         goto out;
    1719                                 }
    1720                                 DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n",
    1721                                          location));
    1722                                 strlcpy(printer->location,
    1723                                         location,
    1724                                         sizeof(printer->location));
    1725                         }
    1726 
    1727                         attr = attr->next;
    1728                 }
    1729 
    1730                 /*
    1731                  * We have everything needed...
    1732                  */
    1733 
    1734                 if (name != NULL)
    1735                         break;
    1736         }
    1737 
    1738         ret = True;
    1739 
    1740  out:
    1741         if (response)
    1742                 ippDelete(response);
    1743 
    1744         if (language)
    1745                 cupsLangFree(language);
    1746 
    1747         if (http)
    1748                 httpClose(http);
    1749 
    1750         TALLOC_FREE(frame);
    1751         return ret;
    1752 }
    1753 
    17541594#else
    17551595 /* this keeps fussy compilers happy */
Note: See TracChangeset for help on using the changeset viewer.