Changeset 745 for trunk/server/source3/printing/print_cups.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/printing/print_cups.c
r664 r745 25 25 #include "includes.h" 26 26 #include "printing.h" 27 #include "printing/pcap.h" 27 28 #include "librpc/gen_ndr/ndr_printcap.h" 28 29 … … 41 42 ****************************************************************/ 42 43 43 static void gotalarm_sig( void)44 static void gotalarm_sig(int signum) 44 45 { 45 46 gotalarm = 1; … … 95 96 96 97 if (timeout) { 97 CatchSignal(SIGALRM, SIGNAL_CASTgotalarm_sig);98 CatchSignal(SIGALRM, gotalarm_sig); 98 99 alarm(timeout); 99 100 } … … 106 107 107 108 108 CatchSignal(SIGALRM, SIG NAL_CAST SIG_IGN);109 CatchSignal(SIGALRM, SIG_IGN); 109 110 alarm(0); 110 111 … … 131 132 } 132 133 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)); 134 135 return true; 135 136 } … … 156 157 } 157 158 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)); 159 160 return true; 160 161 } … … 167 168 char *name; 168 169 char *info; 170 char *location = NULL; 169 171 struct pcap_printer *printer; 170 172 bool ret_ok = false; … … 204 206 if (!pull_utf8_talloc(mem_ctx, 205 207 &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, 206 218 attr->values[0].string.text, 207 219 &size)) { … … 233 245 pcap_data->printers[pcap_data->count].name = name; 234 246 pcap_data->printers[pcap_data->count].info = info; 247 pcap_data->printers[pcap_data->count].location = location; 235 248 pcap_data->count++; 236 249 } … … 256 269 { 257 270 "printer-name", 258 "printer-info" 271 "printer-info", 272 "printer-location" 259 273 }; 260 274 bool ret = False; … … 368 382 369 383 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, 371 385 (ndr_push_flags_fn_t)ndr_push_pcap_data); 372 386 if (ndr_ret == NDR_ERR_SUCCESS) { … … 378 392 } 379 393 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) 394 static struct fd_event *cache_fd_event; 395 396 static bool cups_pcap_load_async(struct tevent_context *ev, 397 struct messaging_context *msg_ctx, 398 int *pfd) 384 399 { 385 400 int fds[2]; 386 401 pid_t pid; 402 NTSTATUS status; 387 403 388 404 *pfd = -1; … … 422 438 close_all_print_db(); 423 439 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)) { 426 442 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n")); 427 443 smb_panic("cups_pcap_load_async: reinit_after_fork() failed"); … … 436 452 struct cups_async_cb_args { 437 453 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 *); 439 458 }; 440 459 … … 462 481 } 463 482 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, 465 484 (ndr_pull_flags_fn_t)ndr_pull_pcap_data); 466 485 if (ndr_ret != NDR_ERR_SUCCESS) { … … 477 496 ret_ok = pcap_cache_add_specific(&tmp_pcap_cache, 478 497 pcap_data.printers[i].name, 479 pcap_data.printers[i].info); 498 pcap_data.printers[i].info, 499 pcap_data.printers[i].location); 480 500 if (!ret_ok) { 481 501 DEBUG(0, ("failed to add to tmp pcap cache\n")); 482 break;502 goto err_out; 483 503 } 484 504 } 485 505 506 /* replace the system-wide pcap cache with a (possibly empty) new one */ 507 ret_ok = pcap_cache_replace(tmp_pcap_cache); 486 508 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); 501 514 } 502 515 err_out: 516 pcap_cache_destroy_specific(&tmp_pcap_cache); 503 517 TALLOC_FREE(frame); 504 518 close(cb_args->pipe_fd); … … 507 521 } 508 522 509 bool cups_cache_reload(void (*post_cache_fill_fn)(void)) 523 bool 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 *)) 510 527 { 511 528 struct cups_async_cb_args *cb_args; … … 513 530 514 531 cb_args = TALLOC_P(NULL, struct cups_async_cb_args); 515 if ( !cb_args) {532 if (cb_args == NULL) { 516 533 return false; 517 534 } 535 518 536 cb_args->post_cache_fill_fn = post_cache_fill_fn; 537 cb_args->event_ctx = ev; 538 cb_args->msg_ctx = msg_ctx; 519 539 p_pipe_fd = &cb_args->pipe_fd; 520 540 *p_pipe_fd = -1; 521 541 522 542 /* 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)) { 524 544 talloc_free(cb_args); 525 545 return false; 526 546 } 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 561 563 return true; 562 564 } … … 865 867 cups_lang_t *language = NULL; /* Default language */ 866 868 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 867 const char *clientname = NULL; /* hostname of client for job-originating-host attribute */868 869 char *new_jobname = NULL; 869 870 int num_options = 0; … … 876 877 size_t size; 877 878 uint32_t jobid = (uint32_t)-1; 878 char addr[INET6_ADDRSTRLEN];879 879 880 880 DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob)); … … 918 918 "attributes-natural-language", NULL, language->language); 919 919 920 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) { 920 if (!push_utf8_talloc(frame, &printername, lp_printername(snum), 921 &size)) { 921 922 goto out; 922 923 } … … 933 934 NULL, user); 934 935 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 940 936 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, 941 937 "job-originating-host-name", NULL, 942 clientname);938 pjob->clientmachine); 943 939 944 940 /* Get the jobid from the filename. */ … … 989 985 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) { 990 986 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), 992 989 ippErrorString(cupsLastError()))); 993 990 } else { … … 1002 999 } 1003 1000 } 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), 1005 1003 ippErrorString(cupsLastError()))); 1006 1004 } … … 1427 1425 "attributes-natural-language", NULL, language->language); 1428 1426 1429 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) { 1427 if (!push_utf8_talloc(frame, &printername, lp_printername(snum), 1428 &size)) { 1430 1429 goto out; 1431 1430 } … … 1447 1446 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { 1448 1447 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), 1450 1450 ippErrorString(cupsLastError()))); 1451 1451 } else { … … 1453 1453 } 1454 1454 } 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), 1456 1457 ippErrorString(cupsLastError()))); 1457 1458 } … … 1528 1529 "attributes-natural-language", NULL, language->language); 1529 1530 1530 if (!push_utf8_talloc(frame, &printername, PRINTERNAME(snum), &size)) { 1531 if (!push_utf8_talloc(frame, &printername, lp_printername(snum), 1532 &size)) { 1531 1533 goto out; 1532 1534 } … … 1548 1550 if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { 1549 1551 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), 1551 1554 ippErrorString(cupsLastError()))); 1552 1555 } else { … … 1554 1557 } 1555 1558 } 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), 1557 1561 ippErrorString(cupsLastError()))); 1558 1562 } … … 1588 1592 }; 1589 1593 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 1754 1594 #else 1755 1595 /* this keeps fussy compilers happy */
Note:
See TracChangeset
for help on using the changeset viewer.