Changeset 228 for branches/samba-3.2.x/source/printing
- Timestamp:
- May 26, 2009, 9:44:50 AM (16 years ago)
- 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 61 61 /* load all printcap printers */ 62 62 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); 64 64 } -
branches/samba-3.2.x/source/printing/nt_printing.c
r136 r228 1380 1380 } 1381 1381 close_file(fsp, NORMAL_CLOSE); 1382 fsp = NULL; 1382 1383 1383 1384 /* Get file version info (if available) for new file */ … … 1420 1421 } 1421 1422 close_file(fsp, NORMAL_CLOSE); 1423 fsp = NULL; 1422 1424 1423 1425 if (use_version && (new_major != old_major || new_minor != old_minor)) { -
branches/samba-3.2.x/source/printing/pcap.c
r133 r228 64 64 65 65 66 typedefstruct pcap_cache {66 struct pcap_cache { 67 67 char *name; 68 68 char *comment; 69 69 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. */ 73 static struct pcap_cache *pcap_cache = NULL; 74 75 bool 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; 80 81 81 82 p->name = SMB_STRDUP(name); 82 83 p->comment = (comment && *comment) ? SMB_STRDUP(comment) : NULL; 83 84 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 94 void 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) { 95 99 next = p->next; 96 100 … … 99 103 SAFE_FREE(p); 100 104 } 105 *pp_cache = NULL; 106 } 107 108 bool pcap_cache_add(const char *name, const char *comment) 109 { 110 return pcap_cache_add_specific(&pcap_cache, name, comment); 101 111 } 102 112 … … 104 114 { 105 115 return (pcap_cache != NULL); 116 } 117 118 void 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 } 106 126 } 107 127 … … 110 130 const char *pcap_name = lp_printcapname(); 111 131 bool pcap_reloaded = False; 112 pcap_cache_t*tmp_cache = NULL;132 struct pcap_cache *tmp_cache = NULL; 113 133 XFILE *pcap_file; 114 134 char *pcap_line; … … 224 244 225 245 if (pcap_reloaded) 226 pcap_cache_destroy (tmp_cache);246 pcap_cache_destroy_specific(&tmp_cache); 227 247 else { 228 pcap_cache_destroy (pcap_cache);248 pcap_cache_destroy_specific(&pcap_cache); 229 249 pcap_cache = tmp_cache; 230 250 } … … 236 256 bool pcap_printername_ok(const char *printername) 237 257 { 238 pcap_cache_t*p;258 struct pcap_cache *p; 239 259 240 260 for (p = pcap_cache; p != NULL; p = p->next) … … 246 266 247 267 /*************************************************************************** 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 268 run a function on each printer name in the printcap file. 254 269 ***************************************************************************/ 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 271 void 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); 261 279 262 280 return; 263 281 } 282 283 void 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 3 3 * 4 4 * Copyright 1999-2003 by Michael R Sweet. 5 * Copyright 2008 Jeremy Allison. 5 6 * 6 7 * This program is free software; you can redistribute it and/or modify … … 8 9 * the Free Software Foundation; either version 3 of the License, or 9 10 * (at your option) any later version. 10 * 11 * 11 12 * This program is distributed in the hope that it will be useful, 12 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 15 * GNU General Public License for more details. 15 * 16 * 16 17 * You should have received a copy of the GNU General Public License 17 18 * along with this program; if not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 /* 22 * JRA. Converted to utf8 pull/push. 18 23 */ 19 24 … … 41 46 } 42 47 43 static http_t *cups_connect( void)48 static http_t *cups_connect(TALLOC_CTX *frame) 44 49 { 45 http_t *http ;46 char *server , *p;50 http_t *http = NULL; 51 char *server = NULL, *p = NULL; 47 52 int port; 48 53 49 54 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 } 51 58 } else { 52 server = smb_xstrdup(cupsServer()); 59 server = talloc_strdup(frame,cupsServer()); 60 } 61 if (!server) { 62 return NULL; 53 63 } 54 64 … … 60 70 port = ippPort(); 61 71 } 62 72 63 73 DEBUG(10, ("connecting to cups server %s:%d\n", 64 74 server, port)); 65 75 66 76 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", 68 78 server, port, strerror(errno))); 69 SAFE_FREE(server);70 79 return NULL; 71 80 } 72 81 73 SAFE_FREE(server);74 82 return http; 75 83 } 76 84 77 bool cups_cache_reload(void)85 static void send_pcap_info(const char *name, const char *info, void *pd) 78 86 { 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 121 static bool cups_cache_reload_async(int fd) 122 { 123 TALLOC_CTX *frame = talloc_stackframe(); 124 struct pcap_cache *tmp_pcap_cache = NULL; 79 125 http_t *http = NULL; /* HTTP connection to server */ 80 126 ipp_t *request = NULL, /* IPP Request */ … … 88 134 "printer-name", 89 135 "printer-info" 90 }; 136 }; 91 137 bool ret = False; 92 138 … … 103 149 */ 104 150 105 if ((http = cups_connect( )) == NULL) {151 if ((http = cups_connect(frame)) == NULL) { 106 152 goto out; 107 153 } … … 124 170 125 171 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 126 "attributes-charset", NULL, cupsLangEncoding(language));172 "attributes-charset", NULL, "utf-8"); 127 173 128 174 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 164 210 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) { 165 211 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 } 168 217 169 218 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 } 172 224 173 225 attr = attr->next; … … 181 233 break; 182 234 183 if (!pcap_cache_add (name, info)) {235 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) { 184 236 goto out; 185 237 } … … 204 256 205 257 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 206 "attributes-charset", NULL, cupsLangEncoding(language));258 "attributes-charset", NULL, "utf-8"); 207 259 208 260 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 244 296 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) { 245 297 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 } 248 303 249 304 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 } 252 310 253 311 attr = attr->next; … … 261 319 break; 262 320 263 if (!pcap_cache_add (name, info)) {321 if (!pcap_cache_add_specific(&tmp_pcap_cache, name, info)) { 264 322 goto out; 265 323 } … … 278 336 httpClose(http); 279 337 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); 280 347 return ret; 281 348 } 282 349 350 static struct pcap_cache *local_pcap_copy; 351 struct fd_event *cache_fd_event; 352 353 static 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 402 static 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 511 bool 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 } 283 561 284 562 /* … … 288 566 static int cups_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob) 289 567 { 568 TALLOC_CTX *frame = talloc_stackframe(); 290 569 int ret = 1; /* Return value */ 291 570 http_t *http = NULL; /* HTTP connection to server */ … … 293 572 *response = NULL; /* IPP Response */ 294 573 cups_lang_t *language = NULL; /* Default language */ 574 char *user = NULL; 295 575 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 296 576 … … 308 588 */ 309 589 310 if ((http = cups_connect( )) == NULL) {590 if ((http = cups_connect(frame)) == NULL) { 311 591 goto out; 312 592 } … … 330 610 331 611 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 332 "attributes-charset", NULL, cupsLangEncoding(language));612 "attributes-charset", NULL, "utf-8"); 333 613 334 614 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 339 619 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); 340 620 621 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 622 goto out; 623 } 624 341 625 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 342 NULL, pjob->user);626 NULL, user); 343 627 344 628 /* … … 368 652 httpClose(http); 369 653 654 TALLOC_FREE(frame); 370 655 return ret; 371 656 } … … 378 663 static int cups_job_pause(int snum, struct printjob *pjob) 379 664 { 665 TALLOC_CTX *frame = talloc_stackframe(); 380 666 int ret = 1; /* Return value */ 381 667 http_t *http = NULL; /* HTTP connection to server */ … … 383 669 *response = NULL; /* IPP Response */ 384 670 cups_lang_t *language = NULL; /* Default language */ 671 char *user = NULL; 385 672 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 386 673 … … 398 685 */ 399 686 400 if ((http = cups_connect( )) == NULL) {687 if ((http = cups_connect(frame)) == NULL) { 401 688 goto out; 402 689 } … … 420 707 421 708 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 422 "attributes-charset", NULL, cupsLangEncoding(language));709 "attributes-charset", NULL, "utf-8"); 423 710 424 711 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 429 716 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); 430 717 718 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 719 goto out; 720 } 431 721 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 432 NULL, pjob->user);722 NULL, user); 433 723 434 724 /* … … 458 748 httpClose(http); 459 749 750 TALLOC_FREE(frame); 460 751 return ret; 461 752 } … … 468 759 static int cups_job_resume(int snum, struct printjob *pjob) 469 760 { 761 TALLOC_CTX *frame = talloc_stackframe(); 470 762 int ret = 1; /* Return value */ 471 763 http_t *http = NULL; /* HTTP connection to server */ … … 473 765 *response = NULL; /* IPP Response */ 474 766 cups_lang_t *language = NULL; /* Default language */ 767 char *user = NULL; 475 768 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 476 769 … … 488 781 */ 489 782 490 if ((http = cups_connect( )) == NULL) {783 if ((http = cups_connect(frame)) == NULL) { 491 784 goto out; 492 785 } … … 510 803 511 804 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 512 "attributes-charset", NULL, cupsLangEncoding(language));805 "attributes-charset", NULL, "utf-8"); 513 806 514 807 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 519 812 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "job-uri", NULL, uri); 520 813 814 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 815 goto out; 816 } 521 817 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 522 NULL, pjob->user);818 NULL, user); 523 819 524 820 /* … … 548 844 httpClose(http); 549 845 846 TALLOC_FREE(frame); 550 847 return ret; 551 848 } … … 558 855 static int cups_job_submit(int snum, struct printjob *pjob) 559 856 { 857 TALLOC_CTX *frame = talloc_stackframe(); 560 858 int ret = 1; /* Return value */ 561 859 http_t *http = NULL; /* HTTP connection to server */ … … 568 866 int num_options = 0; 569 867 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; 570 873 char addr[INET6_ADDRSTRLEN]; 571 874 … … 582 885 */ 583 886 584 if ((http = cups_connect( )) == NULL) {887 if ((http = cups_connect(frame)) == NULL) { 585 888 goto out; 586 889 } … … 605 908 606 909 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 607 "attributes-charset", NULL, cupsLangEncoding(language));910 "attributes-charset", NULL, "utf-8"); 608 911 609 912 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 610 913 "attributes-natural-language", NULL, language->language); 611 914 915 if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) { 916 goto out; 917 } 612 918 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 613 PRINTERNAME(snum));919 printername); 614 920 615 921 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, 616 922 "printer-uri", NULL, uri); 617 923 924 if (push_utf8_talloc(frame, &user, pjob->user) == (size_t)-1) { 925 goto out; 926 } 618 927 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 619 NULL, pjob->user);928 NULL, user); 620 929 621 930 clientname = client_name(get_client_fd()); … … 628 937 clientname); 629 938 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) { 632 947 goto out; 633 948 } … … 636 951 new_jobname); 637 952 638 /* 639 * add any options defined in smb.conf 953 /* 954 * add any options defined in smb.conf 640 955 */ 641 956 957 if (push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum)) == (size_t)-1) { 958 goto out; 959 } 642 960 num_options = 0; 643 961 options = NULL; 644 num_options = cupsParseOptions( lp_cups_options(snum), num_options, &options);962 num_options = cupsParseOptions(cupsoptions, num_options, &options); 645 963 646 964 if ( num_options ) 647 cupsEncodeOptions(request, num_options, options); 965 cupsEncodeOptions(request, num_options, options); 648 966 649 967 /* … … 651 969 */ 652 970 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 } 655 976 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) { 656 977 if (response->request.status.status_code >= IPP_OK_CONFLICT) { … … 679 1000 httpClose(http); 680 1001 681 SAFE_FREE(new_jobname);1002 TALLOC_FREE(frame); 682 1003 683 1004 return ret; … … 691 1012 enum printing_types printing_type, 692 1013 char *lpq_command, 693 print_queue_struct **q, 1014 print_queue_struct **q, 694 1015 print_status_struct *status) 695 1016 { 696 fstring printername; 1017 TALLOC_CTX *frame = talloc_stackframe(); 1018 char *printername = NULL; 697 1019 http_t *http = NULL; /* HTTP connection to server */ 698 1020 ipp_t *request = NULL, /* IPP Request */ … … 705 1027 print_queue_struct *queue = NULL, /* Queue entries */ 706 1028 *temp; /* Temporary pointer for queue */ 707 c onst 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 */ 709 1031 int job_id; /* job-id attribute */ 710 1032 int job_k_octets; /* job-k-octets attribute */ … … 730 1052 *q = NULL; 731 1053 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 736 1058 the lpq_command to get the queue listing). */ 737 1059 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)); 741 1064 742 1065 /* … … 750 1073 */ 751 1074 752 if ((http = cups_connect( )) == NULL) {1075 if ((http = cups_connect(frame)) == NULL) { 753 1076 goto out; 754 1077 } … … 778 1101 779 1102 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 780 "attributes-charset", NULL, cupsLangEncoding(language));1103 "attributes-charset", NULL, "utf-8"); 781 1104 782 1105 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 883 1206 884 1207 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 } 887 1213 888 1214 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 } 891 1220 892 1221 attr = attr->next; … … 912 1241 temp->priority = job_priority; 913 1242 temp->time = job_time; 914 str ncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);915 str ncpy(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)); 916 1245 917 1246 qcount ++; … … 940 1269 941 1270 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 942 "attributes-charset", NULL, cupsLangEncoding(language));1271 "attributes-charset", NULL, "utf-8"); 943 1272 944 1273 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, … … 983 1312 984 1313 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 } 987 1319 988 1320 /* … … 1002 1334 httpClose(http); 1003 1335 1336 TALLOC_FREE(frame); 1004 1337 return qcount; 1005 1338 } … … 1012 1345 static int cups_queue_pause(int snum) 1013 1346 { 1347 TALLOC_CTX *frame = talloc_stackframe(); 1014 1348 int ret = 1; /* Return value */ 1015 1349 http_t *http = NULL; /* HTTP connection to server */ … … 1017 1351 *response = NULL; /* IPP Response */ 1018 1352 cups_lang_t *language = NULL; /* Default language */ 1353 char *printername = NULL; 1354 char *username = NULL; 1019 1355 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 1020 1356 … … 1032 1368 */ 1033 1369 1034 if ((http = cups_connect( )) == NULL) {1370 if ((http = cups_connect(frame)) == NULL) { 1035 1371 goto out; 1036 1372 } … … 1054 1390 1055 1391 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1056 "attributes-charset", NULL, cupsLangEncoding(language));1392 "attributes-charset", NULL, "utf-8"); 1057 1393 1058 1394 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1059 1395 "attributes-natural-language", NULL, language->language); 1060 1396 1397 if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) { 1398 goto out; 1399 } 1061 1400 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 1062 PRINTERNAME(snum));1401 printername); 1063 1402 1064 1403 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); 1065 1404 1405 if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) { 1406 goto out; 1407 } 1066 1408 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 1067 NULL, current_user_info.unix_name);1409 NULL, username); 1068 1410 1069 1411 /* … … 1093 1435 httpClose(http); 1094 1436 1437 TALLOC_FREE(frame); 1095 1438 return ret; 1096 1439 } … … 1103 1446 static int cups_queue_resume(int snum) 1104 1447 { 1448 TALLOC_CTX *frame = talloc_stackframe(); 1105 1449 int ret = 1; /* Return value */ 1106 1450 http_t *http = NULL; /* HTTP connection to server */ … … 1108 1452 *response = NULL; /* IPP Response */ 1109 1453 cups_lang_t *language = NULL; /* Default language */ 1454 char *printername = NULL; 1455 char *username = NULL; 1110 1456 char uri[HTTP_MAX_URI]; /* printer-uri attribute */ 1111 1457 … … 1123 1469 */ 1124 1470 1125 if ((http = cups_connect( )) == NULL) {1471 if ((http = cups_connect(frame)) == NULL) { 1126 1472 goto out; 1127 1473 } … … 1145 1491 1146 1492 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1147 "attributes-charset", NULL, cupsLangEncoding(language));1493 "attributes-charset", NULL, "utf-8"); 1148 1494 1149 1495 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1150 1496 "attributes-natural-language", NULL, language->language); 1151 1497 1498 if (push_utf8_talloc(frame, &printername, PRINTERNAME(snum)) == (size_t)-1) { 1499 goto out; 1500 } 1152 1501 slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", 1153 PRINTERNAME(snum));1502 printername); 1154 1503 1155 1504 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); 1156 1505 1506 if (push_utf8_talloc(frame, &username, current_user_info.unix_name) == (size_t)-1) { 1507 goto out; 1508 } 1157 1509 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", 1158 NULL, current_user_info.unix_name);1510 NULL, username); 1159 1511 1160 1512 /* … … 1184 1536 httpClose(http); 1185 1537 1538 TALLOC_FREE(frame); 1186 1539 return ret; 1187 1540 } … … 1205 1558 bool cups_pull_comment_location(NT_PRINTER_INFO_LEVEL_2 *printer) 1206 1559 { 1560 TALLOC_CTX *frame = talloc_stackframe(); 1207 1561 http_t *http = NULL; /* HTTP connection to server */ 1208 1562 ipp_t *request = NULL, /* IPP Request */ … … 1210 1564 ipp_attribute_t *attr; /* Current attribute */ 1211 1565 cups_lang_t *language = NULL; /* Default language */ 1212 char *name, /* printer-name attribute */1213 *info, /* printer-info attribute */1214 *location; /* printer-location attribute */1215 1566 char uri[HTTP_MAX_URI]; 1567 char *server = NULL; 1568 char *sharename = NULL; 1569 char *name = NULL; 1216 1570 static const char *requested[] =/* Requested attributes */ 1217 1571 { … … 1234 1588 */ 1235 1589 1236 if ((http = cups_connect( )) == NULL) {1590 if ((http = cups_connect(frame)) == NULL) { 1237 1591 goto out; 1238 1592 } … … 1246 1600 1247 1601 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 1248 "attributes-charset", NULL, cupsLangEncoding(language));1602 "attributes-charset", NULL, "utf-8"); 1249 1603 1250 1604 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 1251 1605 "attributes-natural-language", NULL, language->language); 1252 1606 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 } 1253 1620 slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s", 1254 lp_cups_server(), printer->sharename);1621 server, sharename); 1255 1622 1256 1623 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, … … 1287 1654 */ 1288 1655 1289 name = NULL;1290 info = NULL;1291 location = NULL;1292 1293 1656 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 1294 1664 /* Grab the comment if we don't have one */ 1295 1665 if ( (strcmp(attr->name, "printer-info") == 0) 1296 1666 && (attr->value_tag == IPP_TAG_TEXT) 1297 && !strlen(printer->comment) ) 1667 && !strlen(printer->comment) ) 1298 1668 { 1669 char *comment = NULL; 1670 pull_utf8_talloc(frame, 1671 &comment, 1672 attr->values[0].string.text); 1299 1673 DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n", 1300 attr->values[0].string.text));1674 comment)); 1301 1675 strlcpy(printer->comment, 1302 attr->values[0].string.text,1303 1676 comment, 1677 sizeof(printer->comment)); 1304 1678 } 1305 1679 1306 /* Grab the location if we don't have one */ 1680 /* Grab the location if we don't have one */ 1307 1681 if ( (strcmp(attr->name, "printer-location") == 0) 1308 && (attr->value_tag == IPP_TAG_TEXT) 1682 && (attr->value_tag == IPP_TAG_TEXT) 1309 1683 && !strlen(printer->location) ) 1310 1684 { 1685 char *location = NULL; 1686 pull_utf8_talloc(frame, 1687 &location, 1688 attr->values[0].string.text); 1311 1689 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)); 1314 1694 } 1315 1695 … … 1318 1698 1319 1699 /* 1320 * See if we have everything needed...1700 * We have everything needed... 1321 1701 */ 1322 1702 1323 if (name == NULL)1703 if (name != NULL) 1324 1704 break; 1325 1326 1705 } 1327 1706 … … 1338 1717 httpClose(http); 1339 1718 1719 TALLOC_FREE(frame); 1340 1720 return ret; 1341 1721 } -
branches/samba-3.2.x/source/printing/printfsp.c
r133 r228 29 29 30 30 NTSTATUS print_fsp_open(connection_struct *conn, const char *fname, 31 files_struct * *result)31 files_struct *fsp) 32 32 { 33 33 int jobid; 34 34 SMB_STRUCT_STAT sbuf; 35 files_struct *fsp;36 35 fstring name; 37 36 NTSTATUS status; 38 39 status = file_new(conn, &fsp);40 if(!NT_STATUS_IS_OK(status)) {41 return status;42 }43 37 44 38 fstrcpy( name, "Remote Downlevel Document"); … … 55 49 if (jobid == -1) { 56 50 status = map_nt_error_from_unix(errno); 57 file_free(fsp);58 51 return status; 59 52 } … … 64 57 /* We need to delete the entry in the tdb. */ 65 58 pjob_delete(lp_const_servicename(SNUM(conn)), jobid); 66 file_free(fsp);67 59 return NT_STATUS_ACCESS_DENIED; /* No errno around here */ 68 60 } … … 83 75 fsp->is_directory = False; 84 76 string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid)); 85 fsp->wcp = NULL; 77 fsp->wcp = NULL; 86 78 SMB_VFS_FSTAT(fsp, &sbuf); 87 79 fsp->mode = sbuf.st_mode; 88 80 fsp->file_id = vfs_file_id_from_sbuf(conn, &sbuf); 89 81 90 conn->num_files_open++;91 92 *result = fsp;93 82 return NT_STATUS_OK; 94 83 } -
branches/samba-3.2.x/source/printing/printing.c
r141 r228 1395 1395 void start_background_queue(void) 1396 1396 { 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 1397 1403 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 1398 1410 background_lpq_updater_pid = sys_fork(); 1399 1411 … … 1407 1419 DEBUG(5,("start_background_queue: background LPQ thread started\n")); 1408 1420 1421 close(pause_pipe[0]); 1422 pause_pipe[0] = -1; 1423 1409 1424 if (!reinit_after_fork(smbd_messaging_context(), true)) { 1410 1425 DEBUG(0,("reinit_after_fork() failed\n")); … … 1421 1436 messaging_register(smbd_messaging_context(), NULL, 1422 1437 MSG_PRINTER_UPDATE, print_queue_receive); 1423 1438 1424 1439 DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n")); 1425 1440 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 1428 1453 /* check for some essential signals first */ 1429 1454 1430 1455 if (got_sig_term) { 1431 1456 exit_server_cleanly(NULL); … … 1438 1463 reload_after_sighup = 0; 1439 1464 } 1440 1465 1441 1466 /* now check for messages */ 1442 1467 1443 1468 DEBUG(10,("start_background_queue: background LPQ thread got a message\n")); 1444 1469 message_dispatch(smbd_messaging_context()); … … 1450 1475 } 1451 1476 } 1477 1478 close(pause_pipe[1]); 1452 1479 } 1453 1480
Note:
See TracChangeset
for help on using the changeset viewer.