Changeset 988 for vendor/current/source3/printing
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/source3/printing
- Files:
-
- 2 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/printing/load.c
r746 r988 21 21 #include "printing/pcap.h" 22 22 #include "printing/load.h" 23 #include "lib/param/loadparm.h" 23 24 24 25 /*************************************************************************** … … 40 41 return; 41 42 42 auto_serv = lp_auto_services( );43 auto_serv = lp_auto_services(talloc_tos()); 43 44 str = SMB_STRDUP(auto_serv); 44 45 TALLOC_FREE(auto_serv); … … 65 66 struct messaging_context *msg_ctx) 66 67 { 67 SMB_ASSERT(pcap_cache_loaded( ));68 SMB_ASSERT(pcap_cache_loaded(NULL)); 68 69 69 70 add_auto_printers(); … … 71 72 /* load all printcap printers */ 72 73 if (lp_load_printers() && lp_servicenumber(PRINTERS_NAME) >= 0) 73 pcap_printer_ fn(lp_add_one_printer, NULL);74 pcap_printer_read_fn(lp_add_one_printer, NULL); 74 75 } -
vendor/current/source3/printing/lpq_parse.c
r746 r988 802 802 char *p = strrchr_m(tok[6],'/'); 803 803 if (p) { 804 size_t len = strlen(tok[6])+1; 804 805 fstrcpy(tmp,p+1); 805 fstrcpy(tok[6],tmp);806 strlcpy(tok[6],tmp, len); 806 807 } 807 808 } … … 1117 1118 handle them so that most severe condition is shown */ 1118 1119 int i; 1119 strlower_m(line); 1120 if (!strlower_m(line)) { 1121 return false; 1122 } 1120 1123 1121 1124 switch (status->status) { -
vendor/current/source3/printing/notify.c
r740 r988 36 36 struct spoolss_notify_msg *msg; 37 37 struct timeval tv; 38 uint8 *buf;38 uint8_t *buf; 39 39 size_t buflen; 40 40 } *notify_queue_head = NULL; … … 63 63 { 64 64 int snum = lp_servicenumber(qname); 65 if (snum == -1 || !lp_print _ok(snum))65 if (snum == -1 || !lp_printable(snum)) 66 66 return -1; 67 67 return snum; … … 84 84 { 85 85 struct spoolss_notify_msg *msg = q->msg; 86 uint8 *buf = NULL;86 uint8_t *buf = NULL; 87 87 size_t buflen = 0, len; 88 88 … … 95 95 96 96 len += tdb_pack(buf + len, buflen - len, "ddddddd", 97 (uint32 )q->tv.tv_sec, (uint32)q->tv.tv_usec,97 (uint32_t)q->tv.tv_sec, (uint32_t)q->tv.tv_usec, 98 98 msg->type, msg->field, msg->id, msg->len, msg->flags); 99 99 … … 108 108 109 109 if (buflen != len) { 110 buf = (uint8 *)TALLOC_REALLOC(send_ctx, buf, len);110 buf = (uint8_t *)TALLOC_REALLOC(send_ctx, buf, len); 111 111 if (!buf) 112 112 return False; … … 195 195 pid_to_procid(pid_list[i]), 196 196 MSG_PRINTER_NOTIFY2 | MSG_FLAG_LOWPRIORITY, 197 (uint8 *)buf, offset);197 (uint8_t *)buf, offset); 198 198 199 199 if ((timeout != 0) && timeval_expired(&end_time)) { … … 255 255 256 256 if ( from->len ) { 257 to->notify.data = (char *) TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );257 to->notify.data = (char *)talloc_memdup(send_ctx, from->notify.data, from->len ); 258 258 if ( !to->notify.data ) { 259 DEBUG(0,("copy_notify2_msg: TALLOC_MEMDUP() of size [%d] failed!\n", from->len ));259 DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len )); 260 260 return False; 261 261 } … … 306 306 /* Store the message on the pending queue. */ 307 307 308 pnqueue = TALLOC_P(send_ctx, struct notify_queue);308 pnqueue = talloc(send_ctx, struct notify_queue); 309 309 if (!pnqueue) { 310 310 DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n")); … … 314 314 /* allocate a new msg structure and copy the fields */ 315 315 316 if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {316 if ( !(pnqueue->msg = talloc(send_ctx, SPOOLSS_NOTIFY_MSG)) ) { 317 317 DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n", 318 318 (unsigned long)sizeof(SPOOLSS_NOTIFY_MSG))); … … 332 332 */ 333 333 334 DLIST_ADD_END(notify_queue_head, pnqueue , struct notify_queue *);334 DLIST_ADD_END(notify_queue_head, pnqueue); 335 335 num_messages++; 336 336 … … 346 346 static void send_notify_field_values(struct tevent_context *ev, 347 347 struct messaging_context *msg_ctx, 348 const char *sharename, uint32 type,349 uint32 field, uint32 id, uint32 value1,350 uint32 value2, uint32flags)348 const char *sharename, uint32_t type, 349 uint32_t field, uint32_t id, uint32_t value1, 350 uint32_t value2, uint32_t flags) 351 351 { 352 352 struct spoolss_notify_msg *msg; … … 358 358 return; 359 359 360 msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);360 msg = talloc_zero(send_ctx, struct spoolss_notify_msg); 361 361 if (!msg) 362 362 return; 363 364 ZERO_STRUCTP(msg);365 363 366 364 fstrcpy(msg->printer, sharename); … … 377 375 static void send_notify_field_buffer(struct tevent_context *ev, 378 376 struct messaging_context *msg_ctx, 379 const char *sharename, uint32 type,380 uint32 field, uint32 id, uint32len,377 const char *sharename, uint32_t type, 378 uint32_t field, uint32_t id, uint32_t len, 381 379 const char *buffer) 382 380 { … … 389 387 return; 390 388 391 msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);389 msg = talloc_zero(send_ctx, struct spoolss_notify_msg); 392 390 if (!msg) 393 391 return; 394 395 ZERO_STRUCTP(msg);396 392 397 393 fstrcpy(msg->printer, sharename); … … 400 396 msg->id = id; 401 397 msg->len = len; 402 msg->notify.data = CONST_DISCARD(char *,buffer);398 msg->notify.data = discard_const_p(char, buffer); 403 399 404 400 send_spoolss_notify2_msg(ev, msg_ctx, msg); … … 409 405 void notify_printer_status_byname(struct tevent_context *ev, 410 406 struct messaging_context *msg_ctx, 411 const char *sharename, uint32 status)407 const char *sharename, uint32_t status) 412 408 { 413 409 /* Printer status stored in value1 */ … … 422 418 void notify_printer_status(struct tevent_context *ev, 423 419 struct messaging_context *msg_ctx, 424 int snum, uint32 status)425 { 426 const char *sharename = lp_servicename( snum);420 int snum, uint32_t status) 421 { 422 const char *sharename = lp_servicename(talloc_tos(), snum); 427 423 428 424 if (sharename) … … 432 428 void notify_job_status_byname(struct tevent_context *ev, 433 429 struct messaging_context *msg_ctx, 434 const char *sharename, uint32 jobid,435 uint32 status,436 uint32 flags)430 const char *sharename, uint32_t jobid, 431 uint32_t status, 432 uint32_t flags) 437 433 { 438 434 /* Job id stored in id field, status in value1 */ … … 446 442 void notify_job_status(struct tevent_context *ev, 447 443 struct messaging_context *msg_ctx, 448 const char *sharename, uint32 jobid, uint32status)444 const char *sharename, uint32_t jobid, uint32_t status) 449 445 { 450 446 notify_job_status_byname(ev, msg_ctx, sharename, jobid, status, 0); … … 453 449 void notify_job_total_bytes(struct tevent_context *ev, 454 450 struct messaging_context *msg_ctx, 455 const char *sharename, uint32 jobid,456 uint32 size)451 const char *sharename, uint32_t jobid, 452 uint32_t size) 457 453 { 458 454 /* Job id stored in id field, status in value1 */ … … 466 462 void notify_job_total_pages(struct tevent_context *ev, 467 463 struct messaging_context *msg_ctx, 468 const char *sharename, uint32 jobid,469 uint32 pages)464 const char *sharename, uint32_t jobid, 465 uint32_t pages) 470 466 { 471 467 /* Job id stored in id field, status in value1 */ … … 479 475 void notify_job_username(struct tevent_context *ev, 480 476 struct messaging_context *msg_ctx, 481 const char *sharename, uint32 jobid, char *name)477 const char *sharename, uint32_t jobid, char *name) 482 478 { 483 479 send_notify_field_buffer( … … 489 485 void notify_job_name(struct tevent_context *ev, 490 486 struct messaging_context *msg_ctx, 491 const char *sharename, uint32 jobid, char *name)487 const char *sharename, uint32_t jobid, char *name) 492 488 { 493 489 send_notify_field_buffer( … … 499 495 void notify_job_submitted(struct tevent_context *ev, 500 496 struct messaging_context *msg_ctx, 501 const char *sharename, uint32 jobid,497 const char *sharename, uint32_t jobid, 502 498 time_t submitted) 503 499 { … … 512 508 int snum, const char *driver_name) 513 509 { 514 const char *sharename = lp_servicename( snum);510 const char *sharename = lp_servicename(talloc_tos(), snum); 515 511 516 512 send_notify_field_buffer( … … 524 520 int snum, const char *comment) 525 521 { 526 const char *sharename = lp_servicename( snum);522 const char *sharename = lp_servicename(talloc_tos(), snum); 527 523 528 524 send_notify_field_buffer( … … 536 532 int snum, const char *share_name) 537 533 { 538 const char *sharename = lp_servicename( snum);534 const char *sharename = lp_servicename(talloc_tos(), snum); 539 535 540 536 send_notify_field_buffer( … … 548 544 int snum, const char *printername) 549 545 { 550 const char *sharename = lp_servicename( snum);546 const char *sharename = lp_servicename(talloc_tos(), snum); 551 547 552 548 send_notify_field_buffer( … … 560 556 int snum, const char *port_name) 561 557 { 562 const char *sharename = lp_servicename( snum);558 const char *sharename = lp_servicename(talloc_tos(), snum); 563 559 564 560 send_notify_field_buffer( … … 572 568 int snum, const char *location) 573 569 { 574 const char *sharename = lp_servicename( snum);570 const char *sharename = lp_servicename(talloc_tos(), snum); 575 571 576 572 send_notify_field_buffer( … … 584 580 int snum, const char *sepfile) 585 581 { 586 const char *sharename = lp_servicename( snum);582 const char *sharename = lp_servicename(talloc_tos(), snum); 587 583 588 584 send_notify_field_buffer( … … 595 591 void notify_printer_byname(struct tevent_context *ev, 596 592 struct messaging_context *msg_ctx, 597 const char *printername, uint32 change,593 const char *printername, uint32_t change, 598 594 const char *value) 599 595 { … … 633 629 tdb = pdb->tdb; 634 630 635 if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {631 if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) { 636 632 DEBUG(0,("print_notify_pid_list: Failed to lock printer %s database\n", 637 633 printername)); … … 651 647 652 648 if (num_pids) { 653 if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {649 if ((pid_list = talloc_array(mem_ctx, pid_t, num_pids)) == NULL) { 654 650 ret = False; 655 651 goto done; -
vendor/current/source3/printing/notify.h
r740 r988 30 30 void notify_printer_status_byname(struct tevent_context *ev, 31 31 struct messaging_context *msg_ctx, 32 const char *sharename, uint32 status);32 const char *sharename, uint32_t status); 33 33 void notify_printer_status(struct tevent_context *ev, 34 34 struct messaging_context *msg_ctx, 35 int snum, uint32 status);35 int snum, uint32_t status); 36 36 void notify_job_status_byname(struct tevent_context *ev, 37 37 struct messaging_context *msg_ctx, 38 const char *sharename, uint32 jobid,39 uint32 status,40 uint32 flags);38 const char *sharename, uint32_t jobid, 39 uint32_t status, 40 uint32_t flags); 41 41 void notify_job_status(struct tevent_context *ev, 42 42 struct messaging_context *msg_ctx, 43 const char *sharename, uint32 jobid, uint32status);43 const char *sharename, uint32_t jobid, uint32_t status); 44 44 void notify_job_total_bytes(struct tevent_context *ev, 45 45 struct messaging_context *msg_ctx, 46 const char *sharename, uint32 jobid,47 uint32 size);46 const char *sharename, uint32_t jobid, 47 uint32_t size); 48 48 void notify_job_total_pages(struct tevent_context *ev, 49 49 struct messaging_context *msg_ctx, 50 const char *sharename, uint32 jobid,51 uint32 pages);50 const char *sharename, uint32_t jobid, 51 uint32_t pages); 52 52 void notify_job_username(struct tevent_context *ev, 53 53 struct messaging_context *msg_ctx, 54 const char *sharename, uint32 jobid, char *name);54 const char *sharename, uint32_t jobid, char *name); 55 55 void notify_job_name(struct tevent_context *ev, 56 56 struct messaging_context *msg_ctx, 57 const char *sharename, uint32 jobid, char *name);57 const char *sharename, uint32_t jobid, char *name); 58 58 void notify_job_submitted(struct tevent_context *ev, 59 59 struct messaging_context *msg_ctx, 60 const char *sharename, uint32 jobid,60 const char *sharename, uint32_t jobid, 61 61 time_t submitted); 62 62 void notify_printer_driver(struct tevent_context *ev, … … 80 80 void notify_printer_byname(struct tevent_context *ev, 81 81 struct messaging_context *msg_ctx, 82 const char *printername, uint32 change,82 const char *printername, uint32_t change, 83 83 const char *value); 84 84 void notify_printer_sepfile(struct tevent_context *ev, -
vendor/current/source3/printing/nt_printing.c
r746 r988 30 30 #include "passdb/machine_sid.h" 31 31 #include "smbd/smbd.h" 32 #include "smbd/globals.h" 32 33 #include "auth.h" 33 34 #include "messages.h" … … 74 75 }; 75 76 77 static bool print_driver_directories_init(void) 78 { 79 int service, i; 80 char *driver_path; 81 bool ok; 82 TALLOC_CTX *mem_ctx = talloc_stackframe(); 83 84 service = lp_servicenumber("print$"); 85 if (service < 0) { 86 /* We don't have a print$ share */ 87 DEBUG(5, ("No print$ share has been configured.\n")); 88 talloc_free(mem_ctx); 89 return true; 90 } 91 92 driver_path = lp_path(mem_ctx, service); 93 if (driver_path == NULL) { 94 talloc_free(mem_ctx); 95 return false; 96 } 97 98 ok = directory_create_or_exist(driver_path, 0755); 99 if (!ok) { 100 DEBUG(1, ("Failed to create printer driver directory %s\n", 101 driver_path)); 102 talloc_free(mem_ctx); 103 return false; 104 } 105 106 for (i = 0; archi_table[i].long_archi != NULL; i++) { 107 const char *arch_path; 108 109 arch_path = talloc_asprintf(mem_ctx, 110 "%s/%s", 111 driver_path, 112 archi_table[i].short_archi); 113 if (arch_path == NULL) { 114 talloc_free(mem_ctx); 115 return false; 116 } 117 118 ok = directory_create_or_exist(arch_path, 0755); 119 if (!ok) { 120 DEBUG(1, ("Failed to create printer driver " 121 "architecture directory %s\n", 122 arch_path)); 123 talloc_free(mem_ctx); 124 return false; 125 } 126 } 127 128 talloc_free(mem_ctx); 129 return true; 130 } 131 132 /**************************************************************************** 133 Forward a MSG_PRINTER_DRVUPGRADE message from another smbd to the 134 background lpq updater. 135 ****************************************************************************/ 136 137 static void forward_drv_upgrade_printer_msg(struct messaging_context *msg, 138 void *private_data, 139 uint32_t msg_type, 140 struct server_id server_id, 141 DATA_BLOB *data) 142 { 143 extern pid_t background_lpq_updater_pid; 144 145 if (background_lpq_updater_pid == -1) { 146 DEBUG(3,("no background lpq queue updater\n")); 147 return; 148 } 149 150 messaging_send_buf(msg, 151 pid_to_procid(background_lpq_updater_pid), 152 MSG_PRINTER_DRVUPGRADE, 153 data->data, 154 data->length); 155 } 156 76 157 /**************************************************************************** 77 158 Open the NT printing tdbs. Done once before fork(). … … 82 163 WERROR win_rc; 83 164 165 if (!print_driver_directories_init()) { 166 return false; 167 } 168 84 169 if (!nt_printing_tdb_upgrade()) { 85 170 return false; … … 88 173 /* 89 174 * register callback to handle updating printers as new 90 * drivers are installed 175 * drivers are installed. Forwards to background lpq updater. 91 176 */ 92 177 messaging_register(msg_ctx, NULL, MSG_PRINTER_DRVUPGRADE, 93 do_drv_upgrade_printer);178 forward_drv_upgrade_printer_msg); 94 179 95 180 /* of course, none of the message callbacks matter if you don't … … 149 234 i++; 150 235 } while ( (archi_table[i].long_archi!=NULL ) && 151 StrCaseCmp(long_archi, archi_table[i].long_archi) );236 strcasecmp_m(long_archi, archi_table[i].long_archi) ); 152 237 153 238 if (archi_table[i].long_archi==NULL) { … … 173 258 ****************************************************************************/ 174 259 175 static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32*minor)260 static int get_file_version(files_struct *fsp, char *fname,uint32_t *major, uint32_t *minor) 176 261 { 177 262 int i; … … 199 284 200 285 /* Skip OEM header (if any) and the DOS stub to start of Windows header */ 201 if (SMB_VFS_LSEEK(fsp, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == ( SMB_OFF_T)-1) {286 if (SMB_VFS_LSEEK(fsp, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (off_t)-1) { 202 287 DEBUG(3,("get_file_version: File [%s] too short, errno = %d\n", 203 288 fname, errno)); … … 222 307 if (SMB_VFS_LSEEK(fsp, 223 308 SVAL(buf,PE_HEADER_OPTIONAL_HEADER_SIZE)-(NE_HEADER_SIZE-PE_HEADER_SIZE), 224 SEEK_CUR) == ( SMB_OFF_T)-1) {309 SEEK_CUR) == (off_t)-1) { 225 310 DEBUG(3,("get_file_version: File [%s] Windows optional header too short, errno = %d\n", 226 311 fname, errno)); … … 266 351 267 352 /* Seek to the start of the .rsrc section info */ 268 if (SMB_VFS_LSEEK(fsp, section_pos, SEEK_SET) == ( SMB_OFF_T)-1) {353 if (SMB_VFS_LSEEK(fsp, section_pos, SEEK_SET) == (off_t)-1) { 269 354 DEBUG(3,("get_file_version: PE file [%s] too short for section info, errno = %d\n", 270 355 fname, errno)); … … 411 496 bool use_version = true; 412 497 413 uint32 new_major;414 uint32 new_minor;498 uint32_t new_major; 499 uint32_t new_minor; 415 500 time_t new_create_time; 416 501 417 uint32 old_major;418 uint32 old_minor;502 uint32_t old_major; 503 uint32_t old_minor; 419 504 time_t old_create_time; 420 505 … … 447 532 FILE_ATTRIBUTE_NORMAL, /* file_attributes */ 448 533 INTERNAL_OPEN_ONLY, /* oplock_request */ 534 NULL, /* lease */ 449 535 0, /* allocation_size */ 450 536 0, /* private_flags */ … … 452 538 NULL, /* ea_list */ 453 539 &fsp, /* result */ 454 NULL); /* pinfo */ 540 NULL, /* pinfo */ 541 NULL, NULL); /* create context */ 455 542 456 543 if (!NT_STATUS_IS_OK(status)) { … … 500 587 FILE_ATTRIBUTE_NORMAL, /* file_attributes */ 501 588 INTERNAL_OPEN_ONLY, /* oplock_request */ 589 NULL, /* lease */ 502 590 0, /* allocation_size */ 503 591 0, /* private_flags */ … … 505 593 NULL, /* ea_list */ 506 594 &fsp, /* result */ 507 NULL); /* pinfo */ 595 NULL, /* pinfo */ 596 NULL, NULL); /* create context */ 508 597 509 598 if (!NT_STATUS_IS_OK(status)) { … … 575 664 Determine the correct cVersion associated with an architecture and driver 576 665 ****************************************************************************/ 577 static uint32 get_correct_cversion(struct auth_serversupplied_info *session_info,666 static uint32_t get_correct_cversion(struct auth_session_info *session_info, 578 667 const char *architecture, 579 668 const char *driverpath_in, … … 616 705 } 617 706 618 nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum, 619 lp_pathname(printdollar_snum), 620 session_info, &oldcwd); 707 nt_status = create_conn_struct_cwd(talloc_tos(), 708 server_event_context(), 709 server_messaging_context(), 710 &conn, 711 printdollar_snum, 712 lp_path(talloc_tos(), printdollar_snum), 713 session_info, &oldcwd); 621 714 if (!NT_STATUS_IS_OK(nt_status)) { 622 715 DEBUG(0,("get_correct_cversion: create_conn_struct " … … 674 767 FILE_ATTRIBUTE_NORMAL, /* file_attributes */ 675 768 INTERNAL_OPEN_ONLY, /* oplock_request */ 769 NULL, /* lease */ 676 770 0, /* private_flags */ 677 771 0, /* allocation_size */ … … 679 773 NULL, /* ea_list */ 680 774 &fsp, /* result */ 681 NULL); /* pinfo */ 775 NULL, /* pinfo */ 776 NULL, NULL); /* create context */ 682 777 683 778 if (!NT_STATUS_IS_OK(nt_status)) { … … 687 782 goto error_exit; 688 783 } else { 689 uint32 major;690 uint32 minor;784 uint32_t major; 785 uint32_t minor; 691 786 int ret; 692 787 … … 745 840 conn_free(conn); 746 841 } 747 if (! NT_STATUS_IS_OK(*perr)) {842 if (!W_ERROR_IS_OK(*perr)) { 748 843 cversion = -1; 749 844 } … … 763 858 764 859 static WERROR clean_up_driver_struct_level(TALLOC_CTX *mem_ctx, 765 struct auth_se rversupplied_info *session_info,860 struct auth_session_info *session_info, 766 861 const char *architecture, 767 862 const char **driver_path, … … 836 931 837 932 WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx, 838 struct auth_se rversupplied_info *session_info,933 struct auth_session_info *session_info, 839 934 struct spoolss_AddDriverInfoCtr *r) 840 935 { … … 921 1016 922 1017 /* Setup a synthetic smb_filename struct */ 923 smb_fname_new = TALLOC_ZERO_P(mem_ctx, struct smb_filename);1018 smb_fname_new = talloc_zero(mem_ctx, struct smb_filename); 924 1019 if (!smb_fname_new) { 925 1020 ret = WERR_NOMEM; … … 955 1050 } 956 1051 957 WERROR move_driver_to_download_area(struct auth_se rversupplied_info *session_info,1052 WERROR move_driver_to_download_area(struct auth_session_info *session_info, 958 1053 struct spoolss_AddDriverInfoCtr *r) 959 1054 { … … 999 1094 } 1000 1095 1001 nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum, 1002 lp_pathname(printdollar_snum), 1003 session_info, &oldcwd); 1096 nt_status = create_conn_struct_cwd(talloc_tos(), 1097 server_event_context(), 1098 server_messaging_context(), 1099 &conn, 1100 printdollar_snum, 1101 lp_path(talloc_tos(), printdollar_snum), 1102 session_info, &oldcwd); 1004 1103 if (!NT_STATUS_IS_OK(nt_status)) { 1005 1104 DEBUG(0,("move_driver_to_download_area: create_conn_struct " … … 1175 1274 1176 1275 bool printer_driver_in_use(TALLOC_CTX *mem_ctx, 1177 const struct auth_serversupplied_info *session_info, 1178 struct messaging_context *msg_ctx, 1179 const struct spoolss_DriverInfo8 *r) 1276 struct dcerpc_binding_handle *b, 1277 const struct spoolss_DriverInfo8 *r) 1180 1278 { 1181 1279 int snum; … … 1184 1282 struct spoolss_PrinterInfo2 *pinfo2 = NULL; 1185 1283 WERROR result; 1186 struct dcerpc_binding_handle *b = NULL;1187 1284 1188 1285 if (!r) { … … 1195 1292 1196 1293 for (snum=0; snum<n_services && !in_use; snum++) { 1197 if (!lp_snum_ok(snum) || !lp_print _ok(snum)) {1294 if (!lp_snum_ok(snum) || !lp_printable(snum)) { 1198 1295 continue; 1199 1296 } 1200 1297 1201 if (b == NULL) {1202 result = winreg_printer_binding_handle(mem_ctx,1203 session_info,1204 msg_ctx,1205 &b);1206 if (!W_ERROR_IS_OK(result)) {1207 return false;1208 }1209 }1210 1211 1298 result = winreg_get_printer(mem_ctx, b, 1212 lp_servicename( snum),1299 lp_servicename(talloc_tos(), snum), 1213 1300 &pinfo2); 1214 1301 if (!W_ERROR_IS_OK(result)) { … … 1226 1313 1227 1314 if ( in_use ) { 1228 struct spoolss_DriverInfo8 *driver ;1315 struct spoolss_DriverInfo8 *driver = NULL; 1229 1316 WERROR werr; 1230 1317 … … 1414 1501 1415 1502 bool printer_driver_files_in_use(TALLOC_CTX *mem_ctx, 1416 const struct auth_serversupplied_info *session_info, 1417 struct messaging_context *msg_ctx, 1503 struct dcerpc_binding_handle *b, 1418 1504 struct spoolss_DriverInfo8 *info) 1419 1505 { 1420 1506 int i; 1421 uint32 version;1507 uint32_t version; 1422 1508 struct spoolss_DriverInfo8 *driver; 1423 1509 bool in_use = false; … … 1425 1511 const char **drivers; 1426 1512 WERROR result; 1427 struct dcerpc_binding_handle *b;1428 1513 1429 1514 if ( !info ) … … 1437 1522 1438 1523 /* get the list of drivers */ 1439 1440 result = winreg_printer_binding_handle(mem_ctx,1441 session_info,1442 msg_ctx,1443 &b);1444 if (!W_ERROR_IS_OK(result)) {1445 return false;1446 }1447 1524 1448 1525 result = winreg_get_driver_list(mem_ctx, b, … … 1509 1586 } 1510 1587 1511 status = create_synthetic_smb_fname(tmp_ctx, print_dlr_path, 1512 NULL, NULL, &smb_fname); 1513 if (!NT_STATUS_IS_OK(status)) { 1588 smb_fname = synthetic_smb_fname(tmp_ctx, print_dlr_path, NULL, NULL); 1589 if (smb_fname == NULL) { 1514 1590 goto err_out; 1515 1591 } … … 1527 1603 ****************************************************************************/ 1528 1604 1529 bool delete_driver_files(const struct auth_se rversupplied_info *session_info,1605 bool delete_driver_files(const struct auth_session_info *session_info, 1530 1606 const struct spoolss_DriverInfo8 *r) 1531 1607 { … … 1553 1629 } 1554 1630 1555 nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum, 1556 lp_pathname(printdollar_snum), 1557 session_info, &oldcwd); 1631 nt_status = create_conn_struct_cwd(talloc_tos(), 1632 server_event_context(), 1633 server_messaging_context(), 1634 &conn, 1635 printdollar_snum, 1636 lp_path(talloc_tos(), printdollar_snum), 1637 session_info, &oldcwd); 1558 1638 if (!NT_STATUS_IS_OK(nt_status)) { 1559 1639 DEBUG(0,("delete_driver_files: create_conn_struct " … … 1637 1717 3: can't allocate memory 1638 1718 4: can't free memory 1639 5: non exist ant struct1719 5: non existent struct 1640 1720 */ 1641 1721 … … 1715 1795 1716 1796 ****************************************************************************/ 1717 bool print_access_check(const struct auth_serversupplied_info *session_info,1718 struct messaging_context *msg_ctx, int snum,1719 int access_type)1797 WERROR print_access_check(const struct auth_session_info *session_info, 1798 struct messaging_context *msg_ctx, int snum, 1799 int access_type) 1720 1800 { 1721 1801 struct spoolss_security_descriptor *secdesc = NULL; 1722 uint32 access_granted;1802 uint32_t access_granted; 1723 1803 size_t sd_size; 1724 1804 NTSTATUS status; … … 1731 1811 /* Always allow root or SE_PRINT_OPERATROR to do anything */ 1732 1812 1733 if (session_info->utok.uid == sec_initial_uid() 1734 || security_token_has_privilege(session_info->security_token, SEC_PRIV_PRINT_OPERATOR)) { 1735 return True; 1813 if ((session_info->unix_token->uid == sec_initial_uid()) 1814 || security_token_has_privilege(session_info->security_token, 1815 SEC_PRIV_PRINT_OPERATOR)) { 1816 return WERR_OK; 1736 1817 } 1737 1818 1738 1819 /* Get printer name */ 1739 1820 1740 pname = lp_printername( snum);1821 pname = lp_printername(talloc_tos(), snum); 1741 1822 1742 1823 if (!pname || !*pname) { 1743 errno = EACCES; 1744 return False; 1824 return WERR_ACCESS_DENIED; 1745 1825 } 1746 1826 … … 1748 1828 1749 1829 if(!(mem_ctx = talloc_init("print_access_check"))) { 1750 errno = ENOMEM; 1751 return False; 1830 return WERR_NOMEM; 1752 1831 } 1753 1832 … … 1759 1838 if (!W_ERROR_IS_OK(result)) { 1760 1839 talloc_destroy(mem_ctx); 1761 errno = ENOMEM; 1762 return False; 1840 return WERR_NOMEM; 1763 1841 } 1764 1842 … … 1778 1856 if (!NT_STATUS_IS_OK(status)) { 1779 1857 talloc_destroy(mem_ctx); 1780 errno = map_errno_from_nt_status(status); 1781 return False; 1858 return ntstatus_to_werror(status); 1782 1859 } 1783 1860 … … 1793 1870 DEBUG(4, ("access check was %s\n", NT_STATUS_IS_OK(status) ? "SUCCESS" : "FAILURE")); 1794 1871 1795 /* see if we need to try the printer admin list */1796 1797 if (!NT_STATUS_IS_OK(status) &&1798 (token_contains_name_in_list(uidtoname(session_info->utok.uid),1799 session_info->info3->base.domain.string,1800 NULL, session_info->security_token,1801 lp_printer_admin(snum)))) {1802 talloc_destroy(mem_ctx);1803 return True;1804 }1805 1806 1872 talloc_destroy(mem_ctx); 1807 1873 1808 if (!NT_STATUS_IS_OK(status)) { 1809 errno = EACCES; 1810 } 1811 1812 return NT_STATUS_IS_OK(status); 1874 return ntstatus_to_werror(status); 1813 1875 } 1814 1876 … … 1817 1879 *****************************************************************************/ 1818 1880 1819 bool print_time_access_check(const struct auth_se rversupplied_info *session_info,1881 bool print_time_access_check(const struct auth_session_info *session_info, 1820 1882 struct messaging_context *msg_ctx, 1821 1883 const char *servicename) … … 1826 1888 time_t now = time(NULL); 1827 1889 struct tm *t; 1828 uint32 mins;1890 uint32_t mins; 1829 1891 1830 1892 result = winreg_get_printer_internal(NULL, session_info, msg_ctx, … … 1839 1901 1840 1902 t = gmtime(&now); 1841 mins = (uint32 )t->tm_hour*60 + (uint32)t->tm_min;1903 mins = (uint32_t)t->tm_hour*60 + (uint32_t)t->tm_min; 1842 1904 1843 1905 if (mins >= pinfo2->starttime && mins <= pinfo2->untiltime) { … … 1855 1917 1856 1918 void nt_printer_remove(TALLOC_CTX *mem_ctx, 1857 const struct auth_se rversupplied_info *session_info,1919 const struct auth_session_info *session_info, 1858 1920 struct messaging_context *msg_ctx, 1859 1921 const char *printer) … … 1865 1927 if (!W_ERROR_IS_OK(result)) { 1866 1928 DEBUG(0, ("nt_printer_remove: failed to remove printer %s: " 1867 1929 "%s\n", printer, win_errstr(result))); 1868 1930 } 1869 1931 } 1870 1932 1871 1933 void nt_printer_add(TALLOC_CTX *mem_ctx, 1872 const struct auth_se rversupplied_info *session_info,1934 const struct auth_session_info *session_info, 1873 1935 struct messaging_context *msg_ctx, 1874 1936 const char *printer) -
vendor/current/source3/printing/nt_printing_ads.c
r860 r988 36 36 ****************************************************************/ 37 37 38 static void store_printer_guid(struct messaging_context *msg_ctx,39 38 WERROR nt_printer_guid_store(struct messaging_context *msg_ctx, 39 const char *printer, struct GUID guid) 40 40 { 41 41 TALLOC_CTX *tmp_ctx; 42 struct auth_serversupplied_info *session_info = NULL;42 const struct auth_session_info *session_info; 43 43 const char *guid_str; 44 44 DATA_BLOB blob; 45 NTSTATUS status;46 45 WERROR result; 47 46 48 47 tmp_ctx = talloc_new(NULL); 49 48 if (!tmp_ctx) { 50 DEBUG(0, (" store_printer_guid:Out of memory?!\n"));51 return ;52 } 53 54 s tatus = make_session_info_system(tmp_ctx, &session_info);55 if ( !NT_STATUS_IS_OK(status)) {56 DEBUG(0, (" store_printer_guid: "57 "Could not create system session_info\n"));49 DEBUG(0, ("Out of memory?!\n")); 50 return WERR_NOMEM; 51 } 52 53 session_info = get_session_info_system(); 54 if (session_info == NULL) { 55 DEBUG(0, ("Could not get system session_info\n")); 56 result = WERR_NOMEM; 58 57 goto done; 59 58 } … … 61 60 guid_str = GUID_string(tmp_ctx, &guid); 62 61 if (!guid_str) { 63 DEBUG(0, ("store_printer_guid: Out of memory?!\n")); 62 DEBUG(0, ("Out of memory?!\n")); 63 result = WERR_NOMEM; 64 64 goto done; 65 65 } … … 69 69 70 70 if (!push_reg_sz(tmp_ctx, &blob, guid_str)) { 71 DEBUG(0, ("store_printer_guid: " 72 "Could not marshall string %s for objectGUID\n", 71 DEBUG(0, ("Could not marshall string %s for objectGUID\n", 73 72 guid_str)); 73 result = WERR_NOMEM; 74 74 goto done; 75 75 } … … 80 80 REG_SZ, blob.data, blob.length); 81 81 if (!W_ERROR_IS_OK(result)) { 82 DEBUG(0, ("store_printer_guid: " 83 "Failed to store GUID for printer %s\n", printer)); 84 } 85 82 DEBUG(0, ("Failed to store GUID for printer %s\n", printer)); 83 goto done; 84 } 85 86 result = WERR_OK; 86 87 done: 87 88 talloc_free(tmp_ctx); 89 90 return result; 91 } 92 93 static WERROR nt_printer_dn_lookup(TALLOC_CTX *mem_ctx, 94 ADS_STRUCT *ads, 95 const char *printer, 96 char **pprinter_dn) 97 { 98 char *printer_dn = NULL; 99 char *srv_dn = NULL; 100 char *srv_cn_0 = NULL; 101 char *srv_cn_escaped = NULL; 102 char *sharename_escaped = NULL; 103 char *srv_dn_utf8 = NULL; 104 char **srv_cn_utf8 = NULL; 105 size_t converted_size; 106 ADS_STATUS ads_status; 107 LDAPMessage *res; 108 WERROR result; 109 bool ok; 110 111 ads_status = ads_find_machine_acct(ads, &res, lp_netbios_name()); 112 if (!ADS_ERR_OK(ads_status)) { 113 DEBUG(2, ("Failed to find machine account for %s\n", 114 lp_netbios_name())); 115 result = WERR_NOT_FOUND; 116 goto err_out; 117 } 118 119 /* 120 * We use ldap_get_dn here as we need the answer in utf8 to call 121 * ldap_explode_dn(). JRA. 122 */ 123 srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res); 124 ads_msgfree(ads, res); 125 if (srv_dn_utf8 == NULL) { 126 result = WERR_SERVER_UNAVAILABLE; 127 goto err_out; 128 } 129 130 srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1); 131 if (srv_cn_utf8 == NULL) { 132 ldap_memfree(srv_dn_utf8); 133 result = WERR_SERVER_UNAVAILABLE; 134 goto err_out; 135 } 136 137 /* Now convert to CH_UNIX. */ 138 ok = pull_utf8_talloc(mem_ctx, &srv_dn, srv_dn_utf8, &converted_size); 139 ldap_memfree(srv_dn_utf8); 140 if (!ok) { 141 ldap_memfree(srv_cn_utf8); 142 result = WERR_SERVER_UNAVAILABLE; 143 goto err_out; 144 } 145 146 ok = pull_utf8_talloc(mem_ctx, &srv_cn_0, srv_cn_utf8[0], &converted_size); 147 ldap_memfree(srv_cn_utf8); 148 if (!ok) { 149 result = WERR_SERVER_UNAVAILABLE; 150 goto err_out; 151 } 152 153 srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0); 154 if (srv_cn_escaped == NULL) { 155 result = WERR_SERVER_UNAVAILABLE; 156 goto err_out; 157 } 158 159 sharename_escaped = escape_rdn_val_string_alloc(printer); 160 if (sharename_escaped == NULL) { 161 result = WERR_SERVER_UNAVAILABLE; 162 goto err_out; 163 } 164 165 printer_dn = talloc_asprintf(mem_ctx, 166 "cn=%s-%s,%s", 167 srv_cn_escaped, 168 sharename_escaped, 169 srv_dn); 170 if (printer_dn == NULL) { 171 result = WERR_NOMEM; 172 goto err_out; 173 } 174 175 *pprinter_dn = printer_dn; 176 177 result = WERR_OK; 178 err_out: 179 SAFE_FREE(sharename_escaped); 180 SAFE_FREE(srv_cn_escaped); 181 TALLOC_FREE(srv_cn_0); 182 TALLOC_FREE(srv_dn); 183 return result; 184 } 185 186 static WERROR nt_printer_guid_retrieve_internal(ADS_STRUCT *ads, 187 const char *printer_dn, 188 struct GUID *pguid) 189 { 190 ADS_STATUS ads_status; 191 LDAPMessage *res; 192 const char *attrs[] = {"objectGUID", NULL}; 193 struct GUID guid; 194 bool ok; 195 196 ads_status = ads_search_dn(ads, &res, printer_dn, attrs); 197 if (!ADS_ERR_OK(ads_status)) { 198 DEBUG(2, ("Failed to retrieve GUID from DC - %s\n", 199 ads_errstr(ads_status))); 200 return WERR_BADFILE; 201 } 202 203 ZERO_STRUCT(guid); 204 ok = ads_pull_guid(ads, res, &guid); 205 ads_msgfree(ads, res); 206 if (!ok) { 207 return WERR_NOMEM; 208 } 209 210 *pguid = guid; 211 212 return WERR_OK; 213 } 214 215 WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer, 216 struct GUID *pguid) 217 { 218 ADS_STRUCT *ads = NULL; 219 char *old_krb5ccname = NULL; 220 char *printer_dn; 221 WERROR result; 222 ADS_STATUS ads_status; 223 TALLOC_CTX *tmp_ctx; 224 225 tmp_ctx = talloc_new(mem_ctx); 226 if (tmp_ctx == NULL) { 227 return WERR_NOMEM; 228 } 229 230 ads = ads_init(lp_realm(), lp_workgroup(), NULL); 231 if (ads == NULL) { 232 result = WERR_SERVER_UNAVAILABLE; 233 goto out; 234 } 235 236 old_krb5ccname = getenv(KRB5_ENV_CCNAME); 237 setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); 238 SAFE_FREE(ads->auth.password); 239 ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), 240 NULL, NULL); 241 242 ads_status = ads_connect(ads); 243 if (!ADS_ERR_OK(ads_status)) { 244 DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_status))); 245 result = WERR_ACCESS_DENIED; 246 goto out; 247 } 248 249 result = nt_printer_dn_lookup(tmp_ctx, ads, printer, &printer_dn); 250 if (!W_ERROR_IS_OK(result)) { 251 goto out; 252 } 253 254 result = nt_printer_guid_retrieve_internal(ads, printer_dn, pguid); 255 out: 256 TALLOC_FREE(tmp_ctx); 257 ads_destroy(&ads); 258 ads_kdestroy("MEMORY:prtpub_cache"); 259 unsetenv(KRB5_ENV_CCNAME); 260 if (old_krb5ccname != NULL) { 261 setenv(KRB5_ENV_CCNAME, old_krb5ccname, 0); 262 } 263 264 return result; 88 265 } 89 266 90 267 WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx, 91 const struct auth_se rversupplied_info *session_info,268 const struct auth_session_info *session_info, 92 269 struct messaging_context *msg_ctx, 93 270 const char *printer, struct GUID *guid) … … 169 346 170 347 ads_mod_str(ctx, mods, SPOOL_REG_PRINTERNAME, info2->sharename); 171 ads_mod_str(ctx, mods, SPOOL_REG_SHORTSERVERNAME, global_myname());348 ads_mod_str(ctx, mods, SPOOL_REG_SHORTSERVERNAME, lp_netbios_name()); 172 349 ads_mod_str(ctx, mods, SPOOL_REG_SERVERNAME, get_mydnsfullname()); 173 350 … … 247 424 { 248 425 ADS_STATUS ads_rc; 249 LDAPMessage *res;250 char *prt_dn = NULL, *srv_dn, *srv_cn_0, *srv_cn_escaped, *sharename_escaped;251 char *srv_dn_utf8, **srv_cn_utf8;252 426 TALLOC_CTX *ctx; 253 427 ADS_MODLIST mods; 254 const char *attrs[] = {"objectGUID", NULL};255 428 struct GUID guid; 256 429 WERROR win_rc = WERR_OK; 257 size_t converted_size;258 430 const char *printer = pinfo2->sharename; 431 char *printer_dn = NULL; 259 432 260 433 /* build the ads mods */ … … 266 439 DEBUG(5, ("publishing printer %s\n", printer)); 267 440 268 /* figure out where to publish */ 269 ads_rc = ads_find_machine_acct(ads, &res, global_myname()); 270 if (!ADS_ERR_OK(ads_rc)) { 271 DEBUG(0, ("failed to find machine account for %s\n", 272 global_myname())); 441 win_rc = nt_printer_dn_lookup(ctx, ads, printer, &printer_dn); 442 if (!W_ERROR_IS_OK(win_rc)) { 443 DEBUG(2, ("Failed to create printer dn\n")); 273 444 TALLOC_FREE(ctx); 274 return WERR_NOT_FOUND; 275 } 276 277 /* We use ldap_get_dn here as we need the answer 278 * in utf8 to call ldap_explode_dn(). JRA. */ 279 280 srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res); 281 ads_msgfree(ads, res); 282 if (!srv_dn_utf8) { 283 TALLOC_FREE(ctx); 284 return WERR_SERVER_UNAVAILABLE; 285 } 286 srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1); 287 if (!srv_cn_utf8) { 288 TALLOC_FREE(ctx); 289 ldap_memfree(srv_dn_utf8); 290 return WERR_SERVER_UNAVAILABLE; 291 } 292 /* Now convert to CH_UNIX. */ 293 if (!pull_utf8_talloc(ctx, &srv_dn, srv_dn_utf8, &converted_size)) { 294 TALLOC_FREE(ctx); 295 ldap_memfree(srv_dn_utf8); 296 ldap_memfree(srv_cn_utf8); 297 return WERR_SERVER_UNAVAILABLE; 298 } 299 if (!pull_utf8_talloc(ctx, &srv_cn_0, srv_cn_utf8[0], &converted_size)) { 300 TALLOC_FREE(ctx); 301 ldap_memfree(srv_dn_utf8); 302 ldap_memfree(srv_cn_utf8); 303 TALLOC_FREE(srv_dn); 304 return WERR_SERVER_UNAVAILABLE; 305 } 306 307 ldap_memfree(srv_dn_utf8); 308 ldap_memfree(srv_cn_utf8); 309 310 srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0); 311 if (!srv_cn_escaped) { 312 TALLOC_FREE(ctx); 313 return WERR_SERVER_UNAVAILABLE; 314 } 315 sharename_escaped = escape_rdn_val_string_alloc(printer); 316 if (!sharename_escaped) { 317 SAFE_FREE(srv_cn_escaped); 318 TALLOC_FREE(ctx); 319 return WERR_SERVER_UNAVAILABLE; 320 } 321 322 prt_dn = talloc_asprintf(ctx, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn); 323 324 SAFE_FREE(srv_cn_escaped); 325 SAFE_FREE(sharename_escaped); 445 return win_rc; 446 } 326 447 327 448 mods = ads_init_mods(ctx); … … 339 460 340 461 /* publish it */ 341 ads_rc = ads_mod_printer_entry(ads, pr t_dn, ctx, &mods);462 ads_rc = ads_mod_printer_entry(ads, printer_dn, ctx, &mods); 342 463 if (ads_rc.err.rc == LDAP_NO_SUCH_OBJECT) { 343 464 int i; … … 345 466 ; 346 467 mods[i] = (LDAPMod *)-1; 347 ads_rc = ads_add_printer_entry(ads, pr t_dn, ctx, &mods);468 ads_rc = ads_add_printer_entry(ads, printer_dn, ctx, &mods); 348 469 } 349 470 … … 351 472 DEBUG(3, ("error publishing %s: %s\n", 352 473 printer, ads_errstr(ads_rc))); 353 } 354 355 /* retreive the guid and store it locally */ 356 if (ADS_ERR_OK(ads_search_dn(ads, &res, prt_dn, attrs))) { 357 bool guid_ok; 358 ZERO_STRUCT(guid); 359 guid_ok = ads_pull_guid(ads, res, &guid); 360 ads_msgfree(ads, res); 361 if (guid_ok) { 362 store_printer_guid(msg_ctx, printer, guid); 363 } 364 } 474 /* XXX failed to publish, so no guid to retrieve */ 475 } 476 477 win_rc = nt_printer_guid_retrieve_internal(ads, printer_dn, &guid); 478 if (!W_ERROR_IS_OK(win_rc)) { 479 TALLOC_FREE(ctx); 480 return win_rc; 481 } 482 483 win_rc = nt_printer_guid_store(msg_ctx, printer, guid); 484 if (!W_ERROR_IS_OK(win_rc)) { 485 DEBUG(3, ("failed to store printer %s guid\n", 486 printer)); 487 /* not catastrophic, retrieve on next use */ 488 win_rc = WERR_OK; 489 } 490 365 491 TALLOC_FREE(ctx); 366 492 … … 379 505 /* remove the printer from the directory */ 380 506 ads_rc = ads_find_printer_on_server(ads, &res, 381 printer, global_myname());507 printer, lp_netbios_name()); 382 508 383 509 if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) { … … 408 534 409 535 WERROR nt_printer_publish(TALLOC_CTX *mem_ctx, 410 const struct auth_se rversupplied_info *session_info,536 const struct auth_session_info *session_info, 411 537 struct messaging_context *msg_ctx, 412 538 struct spoolss_PrinterInfo2 *pinfo2, … … 418 544 ADS_STRUCT *ads = NULL; 419 545 WERROR win_rc; 546 char *old_krb5ccname = NULL; 420 547 421 548 sinfo2 = talloc_zero(mem_ctx, struct spoolss_SetPrinterInfo2); … … 455 582 goto done; 456 583 } 584 old_krb5ccname = getenv(KRB5_ENV_CCNAME); 457 585 setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); 458 586 SAFE_FREE(ads->auth.password); … … 480 608 done: 481 609 ads_destroy(&ads); 610 ads_kdestroy("MEMORY:prtpub_cache"); 611 unsetenv(KRB5_ENV_CCNAME); 612 if (old_krb5ccname) { 613 setenv(KRB5_ENV_CCNAME, old_krb5ccname, 0); 614 } 482 615 return win_rc; 483 616 } … … 490 623 int n_services = lp_numservices(); 491 624 TALLOC_CTX *tmp_ctx = NULL; 492 struct auth_se rversupplied_info *session_info = NULL;625 struct auth_session_info *session_info = NULL; 493 626 struct spoolss_PrinterInfo2 *pinfo2; 494 627 NTSTATUS status; 495 628 WERROR result; 629 char *old_krb5ccname = NULL; 496 630 497 631 tmp_ctx = talloc_new(NULL); … … 503 637 return WERR_SERVER_UNAVAILABLE; 504 638 } 639 old_krb5ccname = getenv(KRB5_ENV_CCNAME); 505 640 setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); 506 641 SAFE_FREE(ads->auth.password); … … 525 660 526 661 for (snum = 0; snum < n_services; snum++) { 527 if (!lp_snum_ok(snum) || !lp_print _ok(snum)) {662 if (!lp_snum_ok(snum) || !lp_printable(snum)) { 528 663 continue; 529 664 } 530 665 531 666 result = winreg_get_printer_internal(tmp_ctx, session_info, msg_ctx, 532 lp_servicename( snum),667 lp_servicename(talloc_tos(), snum), 533 668 &pinfo2); 534 669 if (!W_ERROR_IS_OK(result)) { … … 547 682 ads_destroy(&ads); 548 683 ads_kdestroy("MEMORY:prtpub_cache"); 684 unsetenv(KRB5_ENV_CCNAME); 685 if (old_krb5ccname) { 686 setenv(KRB5_ENV_CCNAME, old_krb5ccname, 0); 687 } 549 688 talloc_free(tmp_ctx); 550 689 return result; … … 552 691 553 692 bool is_printer_published(TALLOC_CTX *mem_ctx, 554 const struct auth_se rversupplied_info *session_info,693 const struct auth_session_info *session_info, 555 694 struct messaging_context *msg_ctx, 556 695 const char *servername, … … 588 727 } 589 728 #else 729 WERROR nt_printer_guid_store(struct messaging_context *msg_ctx, 730 const char *printer, struct GUID guid) 731 { 732 return WERR_NOT_SUPPORTED; 733 } 734 735 WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer, 736 struct GUID *pguid) 737 { 738 return WERR_NOT_SUPPORTED; 739 } 740 590 741 WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx, 591 const struct auth_se rversupplied_info *session_info,742 const struct auth_session_info *session_info, 592 743 struct messaging_context *msg_ctx, 593 744 const char *printer, struct GUID *guid) … … 597 748 598 749 WERROR nt_printer_publish(TALLOC_CTX *mem_ctx, 599 const struct auth_se rversupplied_info *session_info,750 const struct auth_session_info *session_info, 600 751 struct messaging_context *msg_ctx, 601 752 struct spoolss_PrinterInfo2 *pinfo2, … … 611 762 612 763 bool is_printer_published(TALLOC_CTX *mem_ctx, 613 const struct auth_se rversupplied_info *session_info,764 const struct auth_session_info *session_info, 614 765 struct messaging_context *msg_ctx, 615 766 const char *servername, -
vendor/current/source3/printing/nt_printing_migrate.c
r860 r988 4 4 * 5 5 * Copyright (c) Andreas Schneider 2010. 6 * Copyright (C) Bjoern Baumbach <bb@sernet.de> 20117 6 * 8 7 * This program is free software; you can redistribute it and/or modify … … 28 27 #include "librpc/gen_ndr/ndr_security.h" 29 28 #include "rpc_client/cli_winreg_spoolss.h" 30 31 static const char *driver_file_basename(const char *file)32 {33 const char *basefile;34 35 basefile = strrchr(file, '\\');36 if (basefile == NULL) {37 basefile = file;38 } else {39 basefile++;40 }41 42 return basefile;43 }44 29 45 30 NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx, … … 117 102 const char *driver_name; 118 103 uint32_t driver_version; 119 int i;120 104 121 105 blob = data_blob_const(data, length); … … 140 124 ZERO_STRUCT(a); 141 125 142 /* remove paths from file names */143 if (r.dependent_files != NULL) {144 for (i = 0 ; r.dependent_files[i] != NULL; i++) {145 r.dependent_files[i] = driver_file_basename(r.dependent_files[i]);146 }147 }148 126 a.string = r.dependent_files; 149 150 r.driverpath = driver_file_basename(r.driverpath);151 r.configfile = driver_file_basename(r.configfile);152 r.datafile = driver_file_basename(r.datafile);153 r.helpfile = driver_file_basename(r.helpfile);154 127 155 128 d3.architecture = r.environment; … … 290 263 291 264 devmode_ctr.devmode = &dm; 292 293 info2.devmode_ptr = 1;294 265 } 295 266 … … 310 281 for (j = 0; j < r.count; j++) { 311 282 char *valuename; 312 c har *keyname;283 const char *keyname; 313 284 314 285 if (r.printer_data[j].type == REG_NONE) { … … 316 287 } 317 288 318 keyname = CONST_DISCARD(char *, r.printer_data[j].name);289 keyname = r.printer_data[j].name; 319 290 valuename = strchr(keyname, '\\'); 320 291 if (valuename == NULL) { -
vendor/current/source3/printing/nt_printing_migrate_internal.c
r860 r988 187 187 bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx) 188 188 { 189 const char *drivers_path = state_path("ntdrivers.tdb");190 const char *printers_path = state_path("ntprinters.tdb");191 const char *forms_path = state_path("ntforms.tdb");192 bool drivers_exists = file_exist(drivers_path);193 bool printers_exists = file_exist(printers_path);194 bool forms_exists = file_exist(forms_path);195 struct auth_se rversupplied_info *session_info;189 const char *drivers_path; 190 const char *printers_path; 191 const char *forms_path; 192 bool drivers_exists; 193 bool printers_exists; 194 bool forms_exists; 195 struct auth_session_info *session_info; 196 196 struct rpc_pipe_client *winreg_pipe = NULL; 197 197 TALLOC_CTX *tmp_ctx = talloc_stackframe(); 198 198 NTSTATUS status; 199 199 200 /* paths talloced on new stackframe */ 201 drivers_path = state_path("ntdrivers.tdb"); 202 printers_path = state_path("ntprinters.tdb"); 203 forms_path = state_path("ntforms.tdb"); 204 if ((drivers_path == NULL) || (printers_path == NULL) 205 || (forms_path == NULL)) { 206 talloc_free(tmp_ctx); 207 return false; 208 } 209 drivers_exists = file_exist(drivers_path); 210 printers_exists = file_exist(printers_path); 211 forms_exists = file_exist(forms_path); 212 200 213 if (!drivers_exists && !printers_exists && !forms_exists) { 214 talloc_free(tmp_ctx); 201 215 return true; 202 216 } … … 211 225 212 226 status = rpc_pipe_open_interface(tmp_ctx, 213 &ndr_table_winreg .syntax_id,227 &ndr_table_winreg, 214 228 session_info, 215 229 NULL, -
vendor/current/source3/printing/nt_printing_os2.c
r740 r988 74 74 WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername) 75 75 { 76 const char *mapfile = lp_os2_driver_map( );76 const char *mapfile = lp_os2_driver_map(talloc_tos()); 77 77 char **lines = NULL; 78 78 const char *drivername; -
vendor/current/source3/printing/nt_printing_tdb.c
r740 r988 55 55 56 56 fstrcpy(share, sharename); 57 strlower_m(share);57 (void)strlower_m(share); 58 58 59 59 keystr = talloc_asprintf(ctx, "%s%s", PRINTERS_PREFIX, share); … … 75 75 76 76 fstrcpy(share, sharename ); 77 strlower_m(share);77 (void)strlower_m(share); 78 78 79 79 keystr = talloc_asprintf(ctx, "%s%s", SECDESC_PREFIX, share); … … 94 94 95 95 for (kbuf = tdb_firstkey(tdb_drivers); kbuf.dptr; 96 96 newkey = tdb_nextkey(tdb_drivers, kbuf), free(kbuf.dptr), kbuf=newkey) { 97 97 98 98 dbuf = tdb_fetch(tdb_drivers, kbuf); … … 163 163 TALLOC_CTX *ctx = state; 164 164 int result, i; 165 uint32 sd_size;166 165 size_t size_new_sec; 167 166 … … 237 236 /* store it back */ 238 237 239 sd_size = ndr_size_security_descriptor(sd_store->sd, 0)240 + sizeof(struct sec_desc_buf);241 242 238 status = marshall_sec_desc_buf(ctx, sd_store, &data.dptr, &data.dsize); 243 239 if (!NT_STATUS_IS_OK(status)) { … … 250 246 /* 0 to continue and non-zero to stop traversal */ 251 247 252 return (result == -1);248 return (result != 0); 253 249 } 254 250 … … 271 267 talloc_destroy( ctx ); 272 268 273 return ( result != -1);269 return ( result >= 0 ); 274 270 } 275 271 … … 339 335 talloc_destroy( ctx ); 340 336 341 return ( result != -1);337 return ( result >= 0 ); 342 338 } 343 339 344 340 bool nt_printing_tdb_upgrade(void) 345 341 { 346 c onst char *drivers_path = state_path("ntdrivers.tdb");347 c onst char *printers_path = state_path("ntprinters.tdb");348 c onst char *forms_path = state_path("ntforms.tdb");349 bool drivers_exists = file_exist(drivers_path);350 bool printers_exists = file_exist(printers_path);351 bool forms_exists = file_exist(forms_path);342 char *drivers_path; 343 char *printers_path; 344 char *forms_path; 345 bool drivers_exists; 346 bool printers_exists; 347 bool forms_exists; 352 348 const char *vstring = "INFO/version"; 353 349 int32_t vers_id; 350 bool ret; 351 352 drivers_path = state_path("ntdrivers.tdb"); 353 if (drivers_path == NULL) { 354 ret = false; 355 goto err_out; 356 } 357 printers_path = state_path("ntprinters.tdb"); 358 if (printers_path == NULL) { 359 ret = false; 360 goto err_drvdb_free; 361 } 362 forms_path = state_path("ntforms.tdb"); 363 if (forms_path == NULL) { 364 ret = false; 365 goto err_prdb_free; 366 } 367 368 drivers_exists = file_exist(drivers_path); 369 printers_exists = file_exist(printers_path); 370 forms_exists = file_exist(forms_path); 354 371 355 372 if (!drivers_exists && !printers_exists && !forms_exists) { 356 return true; 373 ret = true; 374 goto err_formsdb_free; 357 375 } 358 376 … … 366 384 "database %s (%s)\n", 367 385 drivers_path, strerror(errno))); 368 return false; 386 ret = false; 387 goto err_formsdb_free; 369 388 } 370 389 … … 378 397 "database %s (%s)\n", 379 398 printers_path, strerror(errno))); 380 return false; 399 ret = false; 400 goto err_drvdb_close; 381 401 } 382 402 … … 390 410 "database %s (%s)\n", 391 411 forms_path, strerror(errno))); 392 return false; 412 ret = false; 413 goto err_prdb_close; 393 414 } 394 415 … … 405 426 (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) { 406 427 if (!upgrade_to_version_3()) { 407 return false; 428 ret = false; 429 goto err_formsdb_close; 408 430 } 409 431 … … 425 447 if (vers_id == NTDRIVERS_DATABASE_VERSION_3) { 426 448 if (!upgrade_to_version_4()) { 427 return false; 449 ret = false; 450 goto err_formsdb_close; 428 451 } 429 452 tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_4); … … 433 456 if (vers_id == NTDRIVERS_DATABASE_VERSION_4 ) { 434 457 if (!upgrade_to_version_5()) { 435 return false; 458 ret = false; 459 goto err_formsdb_close; 436 460 } 437 461 tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5); … … 441 465 if (vers_id != NTDRIVERS_DATABASE_VERSION_5) { 442 466 DEBUG(0,("nt_printing_init: Unknown printer database version [%d]\n", vers_id)); 443 return false; 444 } 445 } 446 467 ret = false; 468 goto err_formsdb_close; 469 } 470 } 471 ret = true; 472 473 err_formsdb_close: 474 if (tdb_forms) { 475 tdb_close(tdb_forms); 476 tdb_forms = NULL; 477 } 478 err_prdb_close: 479 if (tdb_printers) { 480 tdb_close(tdb_printers); 481 tdb_printers = NULL; 482 } 483 err_drvdb_close: 447 484 if (tdb_drivers) { 448 485 tdb_close(tdb_drivers); 449 486 tdb_drivers = NULL; 450 487 } 451 452 if (tdb_printers) { 453 tdb_close(tdb_printers); 454 tdb_printers = NULL; 455 } 456 457 if (tdb_forms) { 458 tdb_close(tdb_forms); 459 tdb_forms = NULL; 460 } 461 462 return true; 463 } 488 err_formsdb_free: 489 talloc_free(forms_path); 490 err_prdb_free: 491 talloc_free(printers_path); 492 err_drvdb_free: 493 talloc_free(drivers_path); 494 err_out: 495 return ret; 496 } -
vendor/current/source3/printing/pcap.c
r740 r988 84 84 } 85 85 86 bool pcap_cache_add(const char *name, const char *comment, const char *location) 87 { 86 bool pcap_cache_loaded(time_t *_last_change) 87 { 88 NTSTATUS status; 89 time_t last; 90 91 status = printer_list_get_last_refresh(&last); 92 if (!NT_STATUS_IS_OK(status)) { 93 return false; 94 } 95 if (_last_change != NULL) { 96 *_last_change = last; 97 } 98 return true; 99 } 100 101 bool pcap_cache_replace(const struct pcap_cache *pcache) 102 { 103 const struct pcap_cache *p; 88 104 NTSTATUS status; 89 105 time_t t = time_mono(NULL); 90 106 91 status = printer_list_set_printer(talloc_tos(), name, comment, location, t);92 return NT_STATUS_IS_OK(status);93 }94 95 bool pcap_cache_loaded(void)96 {97 NTSTATUS status;98 time_t last;99 100 status = printer_list_get_last_refresh(&last);101 return NT_STATUS_IS_OK(status);102 }103 104 bool pcap_cache_replace(const struct pcap_cache *pcache)105 {106 const struct pcap_cache *p;107 NTSTATUS status;108 109 107 status = printer_list_mark_reload(); 110 108 if (!NT_STATUS_IS_OK(status)) { … … 114 112 115 113 for (p = pcache; p; p = p->next) { 116 pcap_cache_add(p->name, p->comment, p->location); 114 status = printer_list_set_printer(talloc_tos(), p->name, 115 p->comment, p->location, t); 116 if (!NT_STATUS_IS_OK(status)) { 117 return false; 118 } 117 119 } 118 120 … … 133 135 const char *pcap_name = lp_printcapname(); 134 136 bool pcap_reloaded = False; 135 NTSTATUS status;136 137 bool post_cache_fill_fn_handled = false; 138 struct pcap_cache *pcache = NULL; 137 139 138 140 DEBUG(3, ("reloading printcap cache\n")); … … 141 143 if (pcap_name == NULL || *pcap_name == 0) { 142 144 DEBUG(0, ("No printcap file name configured!\n")); 143 return;144 }145 146 status = printer_list_mark_reload();147 if (!NT_STATUS_IS_OK(status)) {148 DEBUG(0, ("Failed to mark printer list for reload!\n"));149 145 return; 150 146 } … … 165 161 #ifdef HAVE_IPRINT 166 162 if (strequal(pcap_name, "iprint")) { 167 pcap_reloaded = iprint_cache_reload( );163 pcap_reloaded = iprint_cache_reload(&pcache); 168 164 goto done; 169 165 } … … 172 168 #if defined(SYSV) || defined(HPUX) 173 169 if (strequal(pcap_name, "lpstat")) { 174 pcap_reloaded = sysv_cache_reload( );170 pcap_reloaded = sysv_cache_reload(&pcache); 175 171 goto done; 176 172 } … … 179 175 #ifdef AIX 180 176 if (strstr_m(pcap_name, "/qconfig") != NULL) { 181 pcap_reloaded = aix_cache_reload(); 182 goto done; 183 } 184 #endif 185 186 pcap_reloaded = std_pcap_cache_reload(pcap_name); 187 177 pcap_reloaded = aix_cache_reload(&pcache); 178 goto done; 179 } 180 #endif 181 182 pcap_reloaded = std_pcap_cache_reload(pcap_name, &pcache); 183 184 /* Fix silly compiler warning about done not being used if none of the above 185 * ifdefs are used */ 186 #if defined(HAVE_CUPS) || defined(HAVE_IPRINT) || defined(SYSV) || defined(HPUX) || defined(AIX) 188 187 done: 188 #endif 189 189 DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error")); 190 190 … … 192 192 /* cleanup old entries only if the operation was successful, 193 193 * otherwise keep around the old entries until we can 194 * successful y reaload */195 status = printer_list_clean_old(); 196 if (! NT_STATUS_IS_OK(status)) {197 DEBUG(0, ("Failed to cleanupprinter list!\n"));194 * successfully reload */ 195 196 if (!pcap_cache_replace(pcache)) { 197 DEBUG(0, ("Failed to replace printer list!\n")); 198 198 } 199 199 200 if (post_cache_fill_fn != NULL) { 200 201 post_cache_fill_fn(ev, msg_ctx); 201 202 } 202 203 } 204 pcap_cache_destroy_specific(&pcache); 203 205 204 206 return; … … 230 232 } 231 233 232 void pcap_printer_ fn(void (*fn)(const char *, const char *, const char *, void *), void *pdata)233 { 234 NTSTATUS status; 235 236 status = printer_list_r un_fn(fn, pdata);234 void pcap_printer_read_fn(void (*fn)(const char *, const char *, const char *, void *), void *pdata) 235 { 236 NTSTATUS status; 237 238 status = printer_list_read_run_fn(fn, pdata); 237 239 if (!NT_STATUS_IS_OK(status)) { 238 240 DEBUG(3, ("Failed to run fn for all printers!\n")); -
vendor/current/source3/printing/pcap.h
r740 r988 36 36 bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment, const char *location); 37 37 void pcap_cache_destroy_specific(struct pcap_cache **ppcache); 38 bool pcap_cache_add(const char *name, const char *comment, const char *location); 39 bool pcap_cache_loaded(void); 38 bool pcap_cache_loaded(time_t *_last_change); 40 39 bool pcap_cache_replace(const struct pcap_cache *cache); 41 40 void pcap_printer_fn_specific(const struct pcap_cache *, void (*fn)(const char *, const char *, const char *, void *), void *); 42 void pcap_printer_ fn(void (*fn)(const char *, const char *, const char *, void *), void *);41 void pcap_printer_read_fn(void (*fn)(const char *, const char *, const char *, void *), void *); 43 42 44 43 void pcap_cache_reload(struct tevent_context *ev, … … 50 49 /* The following definitions come from printing/print_aix.c */ 51 50 52 bool aix_cache_reload( void);51 bool aix_cache_reload(struct pcap_cache **_pcache); 53 52 54 53 /* The following definitions come from printing/print_cups.c */ … … 61 60 /* The following definitions come from printing/print_iprint.c */ 62 61 63 bool iprint_cache_reload( void);62 bool iprint_cache_reload(struct pcap_cache **_pcache); 64 63 65 64 /* The following definitions come from printing/print_svid.c */ 66 65 67 bool sysv_cache_reload( void);66 bool sysv_cache_reload(struct pcap_cache **_pcache); 68 67 69 68 /* The following definitions come from printing/print_standard.c */ 70 bool std_pcap_cache_reload(const char *pcap_name );69 bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache); 71 70 72 71 #endif /* _PRINTING_PCAP_H_ */ -
vendor/current/source3/printing/print_aix.c
r740 r988 30 30 31 31 #ifdef AIX 32 bool aix_cache_reload( void)32 bool aix_cache_reload(struct pcap_cache **_pcache) 33 33 { 34 34 int iEtat; … … 36 36 char *line = NULL, *p; 37 37 char *name = NULL; 38 struct pcap_cache *pcache = NULL; 38 39 TALLOC_CTX *ctx = talloc_init("aix_cache_reload"); 39 40 … … 53 54 /* scan qconfig file for searching <printername>: */ 54 55 for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) { 56 bool ok; 57 55 58 if (*line == '*' || *line == 0) 56 59 continue; … … 68 71 name = talloc_strdup(ctx, p); 69 72 if (!name) { 73 pcap_cache_destroy_specific(&pcache); 70 74 SAFE_FREE(line); 71 75 x_fclose(pfile); … … 87 91 /* probably a good printer ??? */ 88 92 iEtat = 0; 89 if (!pcap_cache_add(name, NULL, NULL)) { 93 ok = pcap_cache_add_specific(&pcache, 94 name, NULL, NULL); 95 if (!ok) { 96 pcap_cache_destroy_specific(&pcache); 90 97 SAFE_FREE(line); 91 98 x_fclose(pfile); … … 102 109 /* it's a good virtual printer */ 103 110 iEtat = 0; 104 if (!pcap_cache_add(name, NULL, NULL)) { 111 ok = pcap_cache_add_specific(&pcache, 112 name, NULL, NULL); 113 if (!ok) { 114 pcap_cache_destroy_specific(&pcache); 105 115 SAFE_FREE(line); 106 116 x_fclose(pfile); … … 114 124 } 115 125 126 *_pcache = pcache; 116 127 x_fclose(pfile); 117 128 TALLOC_FREE(ctx); -
vendor/current/source3/printing/print_cups.c
r746 r988 27 27 #include "printing/pcap.h" 28 28 #include "librpc/gen_ndr/ndr_printcap.h" 29 #include "lib/util/sys_rw.h" 29 30 30 31 #ifdef HAVE_CUPS … … 108 109 size_t size; 109 110 110 if (lp_cups_server( ) != NULL && strlen(lp_cups_server()) > 0) {111 if (!push_utf8_talloc(frame, &server, lp_cups_server( ), &size)) {111 if (lp_cups_server(talloc_tos()) != NULL && strlen(lp_cups_server(talloc_tos())) > 0) { 112 if (!push_utf8_talloc(frame, &server, lp_cups_server(talloc_tos()), &size)) { 112 113 return NULL; 113 114 } … … 148 149 149 150 if (http == NULL) { 150 DEBUG( 0,("Unable to connect to CUPS server %s:%d - %s\n",151 DEBUG(3,("Unable to connect to CUPS server %s:%d - %s\n", 151 152 server, port, strerror(errno))); 152 153 } … … 429 430 } 430 431 431 static struct fd_event*cache_fd_event;432 static struct tevent_fd *cache_fd_event; 432 433 433 434 static bool cups_pcap_load_async(struct tevent_context *ev, … … 453 454 } 454 455 455 pid = sys_fork();456 pid = fork(); 456 457 if (pid == (pid_t)-1) { 457 458 DEBUG(10,("cups_pcap_load_async: fork failed %s\n", … … 475 476 close_all_print_db(); 476 477 477 status = reinit_after_fork(msg_ctx, ev, procid_self(), true);478 status = reinit_after_fork(msg_ctx, ev, true, NULL); 478 479 if (!NT_STATUS_IS_OK(status)) { 479 480 DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n")); … … 484 485 cups_cache_reload_async(fds[1]); 485 486 close(fds[1]); 487 TALLOC_FREE(msg_ctx); 486 488 _exit(0); 487 489 } … … 489 491 struct cups_async_cb_args { 490 492 int pipe_fd; 491 struct event_context *event_ctx;493 struct tevent_context *event_ctx; 492 494 struct messaging_context *msg_ctx; 493 void (*post_cache_fill_fn)(struct event_context *,495 void (*post_cache_fill_fn)(struct tevent_context *, 494 496 struct messaging_context *); 495 497 }; 496 498 497 static void cups_async_callback(struct event_context *event_ctx,498 struct fd_event*event,499 uint16 flags,499 static void cups_async_callback(struct tevent_context *event_ctx, 500 struct tevent_fd *event, 501 uint16_t flags, 500 502 void *p) 501 503 { … … 525 527 526 528 if (!NT_STATUS_IS_OK(pcap_data.status)) { 527 DEBUG( 0,("failed to retrieve printer list: %s\n",529 DEBUG(3,("failed to retrieve printer list: %s\n", 528 530 nt_errstr(pcap_data.status))); 529 531 goto err_out; … … 566 568 int *p_pipe_fd; 567 569 568 cb_args = TALLOC_P(NULL, struct cups_async_cb_args);570 cb_args = talloc(NULL, struct cups_async_cb_args); 569 571 if (cb_args == NULL) { 570 572 return false; … … 587 589 588 590 /* Trigger an event when the pipe can be read. */ 589 cache_fd_event = event_add_fd(ev,591 cache_fd_event = tevent_add_fd(ev, 590 592 NULL, *p_pipe_fd, 591 EVENT_FD_READ,593 TEVENT_FD_READ, 592 594 cups_async_callback, 593 595 (void *)cb_args); … … 956 958 "attributes-natural-language", NULL, language->language); 957 959 958 if (!push_utf8_talloc(frame, &printername, lp_printername(snum), 960 if (!push_utf8_talloc(frame, &printername, 961 lp_printername(talloc_tos(), snum), 959 962 &size)) { 960 963 goto out; … … 993 996 */ 994 997 995 if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) { 998 if (!push_utf8_talloc(frame, &cupsoptions, 999 lp_cups_options(talloc_tos(), snum), &size)) { 996 1000 goto out; 997 1001 } … … 1015 1019 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1016 1020 DEBUG(0,("Unable to print file to %s - %s\n", 1017 lp_printername( snum),1021 lp_printername(talloc_tos(), snum), 1018 1022 ippErrorString(cupsLastError()))); 1019 1023 } else { … … 1029 1033 } else { 1030 1034 DEBUG(0,("Unable to print file to `%s' - %s\n", 1031 lp_printername( snum),1035 lp_printername(talloc_tos(), snum), 1032 1036 ippErrorString(cupsLastError()))); 1033 1037 } … … 1154 1158 "attributes-natural-language", NULL, language->language); 1155 1159 1156 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_ NAME,1160 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, 1157 1161 "requested-attributes", 1158 1162 (sizeof(jattrs) / sizeof(jattrs[0])), … … 1454 1458 "attributes-natural-language", NULL, language->language); 1455 1459 1456 if (!push_utf8_talloc(frame, &printername, lp_printername(snum),1457 &size)) {1460 if (!push_utf8_talloc(frame, &printername, 1461 lp_printername(talloc_tos(), snum), &size)) { 1458 1462 goto out; 1459 1463 } … … 1476 1480 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1477 1481 DEBUG(0,("Unable to pause printer %s - %s\n", 1478 lp_printername( snum),1482 lp_printername(talloc_tos(), snum), 1479 1483 ippErrorString(cupsLastError()))); 1480 1484 } else { … … 1483 1487 } else { 1484 1488 DEBUG(0,("Unable to pause printer %s - %s\n", 1485 lp_printername( snum),1489 lp_printername(talloc_tos(), snum), 1486 1490 ippErrorString(cupsLastError()))); 1487 1491 } … … 1558 1562 "attributes-natural-language", NULL, language->language); 1559 1563 1560 if (!push_utf8_talloc(frame, &printername, lp_printername( snum),1564 if (!push_utf8_talloc(frame, &printername, lp_printername(talloc_tos(), snum), 1561 1565 &size)) { 1562 1566 goto out; … … 1580 1584 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 1581 1585 DEBUG(0,("Unable to resume printer %s - %s\n", 1582 lp_printername( snum),1586 lp_printername(talloc_tos(), snum), 1583 1587 ippErrorString(cupsLastError()))); 1584 1588 } else { … … 1587 1591 } else { 1588 1592 DEBUG(0,("Unable to resume printer %s - %s\n", 1589 lp_printername( snum),1593 lp_printername(talloc_tos(), snum), 1590 1594 ippErrorString(cupsLastError()))); 1591 1595 } -
vendor/current/source3/printing/print_generic.c
r746 r988 74 74 if (do_sub && snum != -1) { 75 75 syscmd = talloc_sub_advanced(ctx, 76 lp_servicename( snum),76 lp_servicename(talloc_tos(), snum), 77 77 current_user_info.unix_name, 78 78 "", … … 118 118 /* need to pause the spooled entry */ 119 119 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob); 120 return print_run_command(snum, lp_printername( snum), True,121 lp_lppause command(snum), NULL,120 return print_run_command(snum, lp_printername(talloc_tos(), snum), True, 121 lp_lppause_command(talloc_tos(), snum), NULL, 122 122 "%j", jobstr, 123 123 NULL); … … 133 133 /* need to pause the spooled entry */ 134 134 slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob); 135 return print_run_command(snum, lp_printername( snum), True,136 lp_lpresume command(snum), NULL,135 return print_run_command(snum, lp_printername(talloc_tos(), snum), True, 136 lp_lpresume_command(talloc_tos(), snum), NULL, 137 137 "%j", jobstr, 138 138 NULL); … … 216 216 /* we print from the directory path to give the best chance of 217 217 parsing the lpq output */ 218 current_directory = TALLOC_ARRAY(ctx, 219 char, 220 PATH_MAX+1); 218 wd = sys_getwd(); 219 if (!wd) { 220 return -1; 221 } 222 223 current_directory = talloc_strdup(ctx, wd); 224 SAFE_FREE(wd); 225 221 226 if (!current_directory) { 222 227 return -1; 223 228 } 224 wd = sys_getwd(current_directory);225 if (!wd) {226 return -1;227 }228 229 229 print_directory = talloc_strdup(ctx, pjob->filename); 230 230 if (!print_directory) { … … 255 255 256 256 /* send it to the system spooler */ 257 ret = print_run_command(snum, lp_printername( snum), True,258 lp_print command(snum), NULL,257 ret = print_run_command(snum, lp_printername(talloc_tos(), snum), True, 258 lp_print_command(talloc_tos(), snum), NULL, 259 259 "%s", p, 260 260 "%J", jobname, … … 273 273 */ 274 274 pjob->sysjob = -1; 275 ret = generic_queue_get(lp_printername( snum), printing_type, lpq_cmd,276 &q, &status);275 ret = generic_queue_get(lp_printername(talloc_tos(), snum), 276 printing_type, lpq_cmd, &q, &status); 277 277 if (ret > 0) { 278 278 int i; … … 296 296 out: 297 297 298 if (chdir( wd) == -1) {298 if (chdir(current_directory) == -1) { 299 299 smb_panic("chdir failed in generic_job_submit"); 300 300 } … … 308 308 static int generic_queue_pause(int snum) 309 309 { 310 return print_run_command(snum, lp_printername( snum), True,311 lp_queuepause command(snum), NULL, NULL);310 return print_run_command(snum, lp_printername(talloc_tos(), snum), True, 311 lp_queuepause_command(talloc_tos(), snum), NULL, NULL); 312 312 } 313 313 … … 317 317 static int generic_queue_resume(int snum) 318 318 { 319 return print_run_command(snum, lp_printername( snum), True,320 lp_queueresume command(snum), NULL, NULL);319 return print_run_command(snum, lp_printername(talloc_tos(), snum), True, 320 lp_queueresume_command(talloc_tos(), snum), NULL, NULL); 321 321 } 322 322 -
vendor/current/source3/printing/print_iprint.c
r746 r988 94 94 static const char *iprint_server(void) 95 95 { 96 if ((lp_iprint_server() != NULL) && (strlen(lp_iprint_server()) > 0)) { 96 const char *server = lp_iprint_server(talloc_tos()); 97 98 if ((server != NULL) && (strlen(server) > 0)) { 97 99 DEBUG(10, ("iprint server explicitly set to %s\n", 98 lp_iprint_server()));99 return lp_iprint_server();100 server)); 101 return server; 100 102 } 101 103 … … 205 207 static int iprint_cache_add_printer(http_t *http, 206 208 int reqId, 207 char* url) 209 const char *url, 210 struct pcap_cache **pcache) 208 211 { 209 212 ipp_t *request = NULL, /* IPP Request */ … … 211 214 ipp_attribute_t *attr; /* Current attribute */ 212 215 cups_lang_t *language = NULL; /* Default language */ 213 c har*name, /* printer-name attribute */214 *info ,/* printer-info attribute */215 smb_enabled, /* smb-enabled attribute */216 const char *name, /* printer-name attribute */ 217 *info; /* printer-info attribute */ 218 char smb_enabled, /* smb-enabled attribute */ 216 219 secure; /* security-enabled attrib. */ 217 220 218 c har*httpPath; /* path portion of the printer-uri */221 const char *httpPath; /* path portion of the printer-uri */ 219 222 220 223 static const char *pattrs[] = /* Requested printer attributes */ … … 341 344 342 345 if (name != NULL && !secure && smb_enabled) 343 pcap_cache_add (name, info, NULL);346 pcap_cache_add_specific(pcache, name, info, NULL); 344 347 } 345 348 … … 350 353 } 351 354 352 bool iprint_cache_reload( void)355 bool iprint_cache_reload(struct pcap_cache **_pcache) 353 356 { 354 357 http_t *http = NULL; /* HTTP connection to server */ … … 358 361 cups_lang_t *language = NULL; /* Default language */ 359 362 int i; 360 bool ret = False; 363 bool ret = false; 364 struct pcap_cache *pcache = NULL; 361 365 362 366 DEBUG(5, ("reloading iprint printcap cache\n")); … … 437 441 for (i = 0; i<ippGetCount(attr); i++) 438 442 { 439 c har *url = ippGetString(attr, i, NULL);443 const char *url = ippGetString(attr, i, NULL); 440 444 if (!url || !strlen(url)) 441 445 continue; 442 iprint_cache_add_printer(http, i+2, url); 446 iprint_cache_add_printer(http, i+2, url, 447 &pcache); 443 448 } 444 449 } … … 447 452 } 448 453 449 ret = True; 454 ret = true; 455 *_pcache = pcache; 450 456 451 457 out: … … 619 625 620 626 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), 621 lp_printername( snum));627 lp_printername(talloc_tos(), snum)); 622 628 623 629 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); … … 633 639 634 640 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", 635 lp_printername( snum));641 lp_printername(talloc_tos(), snum)); 636 642 637 643 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) { … … 719 725 720 726 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), 721 lp_printername( snum));727 lp_printername(talloc_tos(), snum)); 722 728 723 729 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri); … … 733 739 734 740 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", 735 lp_printername( snum));741 lp_printername(talloc_tos(), snum)); 736 742 737 743 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) { … … 820 826 821 827 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), 822 lp_printername( snum));828 lp_printername(talloc_tos(), snum)); 823 829 824 830 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, … … 839 845 */ 840 846 841 slprintf(uri, sizeof(uri) - 1, "/ipp/%s", lp_printername( snum));847 slprintf(uri, sizeof(uri) - 1, "/ipp/%s", lp_printername(talloc_tos(), snum)); 842 848 843 849 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) { 844 850 if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) { 845 851 DEBUG(0,("Unable to print file to %s - %s\n", 846 lp_printername( snum),852 lp_printername(talloc_tos(), snum), 847 853 ippErrorString(cupsLastError()))); 848 854 } else { … … 851 857 } else { 852 858 DEBUG(0,("Unable to print file to `%s' - %s\n", 853 lp_printername( snum),859 lp_printername(talloc_tos(), snum), 854 860 ippErrorString(cupsLastError()))); 855 861 } -
vendor/current/source3/printing/print_standard.c
r740 r988 60 60 61 61 /* handle standard printcap - moved from pcap_printer_fn() */ 62 bool std_pcap_cache_reload(const char *pcap_name )62 bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache) 63 63 { 64 64 XFILE *pcap_file; 65 65 char *pcap_line; 66 struct pcap_cache *pcache = NULL; 66 67 67 68 if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) { … … 118 119 } 119 120 120 if (*name && !pcap_cache_add(name, comment, NULL)) { 121 if ((*name != '\0') 122 && !pcap_cache_add_specific(&pcache, name, comment, NULL)) { 121 123 x_fclose(pcap_file); 124 pcap_cache_destroy_specific(&pcache); 122 125 return false; 123 126 } … … 125 128 126 129 x_fclose(pcap_file); 130 *_pcache = pcache; 127 131 return true; 128 132 } -
vendor/current/source3/printing/print_svid.c
r740 r988 36 36 37 37 #if defined(SYSV) || defined(HPUX) 38 bool sysv_cache_reload( void)38 bool sysv_cache_reload(struct pcap_cache **_pcache) 39 39 { 40 40 char **lines; 41 41 int i; 42 struct pcap_cache *pcache = NULL; 42 43 43 44 #if defined(HPUX) … … 112 113 113 114 /* add it to the cache */ 114 if (!pcap_cache_add (name, NULL, NULL)) {115 if (!pcap_cache_add_specific(&pcache, name, NULL, NULL)) { 115 116 TALLOC_FREE(lines); 116 return False; 117 pcap_cache_destroy_specific(&pcache); 118 return false; 117 119 } 118 120 } 119 121 120 122 TALLOC_FREE(lines); 121 return True; 123 *_pcache = pcache; 124 return true; 122 125 } 123 126 -
vendor/current/source3/printing/printer_list.c
r746 r988 20 20 #include "includes.h" 21 21 #include "system/filesys.h" 22 #include "dbwrap.h" 22 #include "dbwrap/dbwrap.h" 23 #include "dbwrap/dbwrap_open.h" 23 24 #include "util_tdb.h" 24 25 #include "printer_list.h" 25 26 26 #define PL_DB_NAME() lock_path("printer_list.tdb")27 27 #define PL_KEY_PREFIX "PRINTERLIST/PRN/" 28 28 #define PL_KEY_FORMAT PL_KEY_PREFIX"%s" … … 34 34 { 35 35 static struct db_context *db; 36 char *db_path; 36 37 37 38 if (db != NULL) { 38 39 return db; 39 40 } 40 db = db_open(NULL, PL_DB_NAME(), 0, 41 42 db_path = lock_path("printer_list.tdb"); 43 if (db_path == NULL) { 44 return NULL; 45 } 46 47 db = db_open(NULL, db_path, 0, 41 48 TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, 42 O_RDWR|O_CREAT, 0644); 49 O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_1, 50 DBWRAP_FLAG_NONE); 51 TALLOC_FREE(db_path); 43 52 return db; 44 53 } … … 90 99 } 91 100 92 data = dbwrap_fetch_bystring_upper(db, key, key);93 if ( data.dptr == NULL) {101 status = dbwrap_fetch_bystring_upper(db, key, key, &data); 102 if (!NT_STATUS_IS_OK(status)) { 94 103 DEBUG(6, ("Failed to fetch record! " 95 104 "The printer database is empty?\n")); 96 status = NT_STATUS_NOT_FOUND;97 105 goto done; 98 106 } … … 134 142 SAFE_FREE(nstr); 135 143 SAFE_FREE(cstr); 144 SAFE_FREE(lstr); 136 145 TALLOC_FREE(key); 137 146 return status; … … 149 158 uint64_t time_64; 150 159 uint32_t time_h, time_l; 151 const char *str = NULL;152 const char *str2 = NULL;153 160 NTSTATUS status; 154 161 int len; … … 165 172 } 166 173 167 if (comment) { 168 str = comment; 169 } else { 170 str = ""; 171 } 172 173 if (location) { 174 str2 = location; 175 } else { 176 str2 = ""; 177 } 178 174 if (comment == NULL) { 175 comment = ""; 176 } 177 178 if (location == NULL) { 179 location = ""; 180 } 179 181 180 182 time_64 = last_refresh; … … 182 184 time_h = time_64 >> 32; 183 185 184 len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str, str2); 186 len = tdb_pack(NULL, 0, 187 PL_DATA_FORMAT, 188 time_h, 189 time_l, 190 name, 191 comment, 192 location); 185 193 186 194 data.dptr = talloc_array(key, uint8_t, len); … … 193 201 194 202 len = tdb_pack(data.dptr, data.dsize, 195 PL_DATA_FORMAT, time_h, time_l, name, str, str2); 203 PL_DATA_FORMAT, 204 time_h, 205 time_l, 206 name, 207 comment, 208 location); 196 209 197 210 status = dbwrap_store_bystring_upper(db, key, data, TDB_REPLACE); … … 217 230 ZERO_STRUCT(data); 218 231 219 data = dbwrap_fetch_bystring(db, talloc_tos(), PL_TIMESTAMP_KEY);220 if ( data.dptr == NULL) {232 status = dbwrap_fetch_bystring(db, talloc_tos(), PL_TIMESTAMP_KEY, &data); 233 if (!NT_STATUS_IS_OK(status)) { 221 234 DEBUG(1, ("Failed to fetch record!\n")); 222 status = NT_STATUS_NOT_FOUND;223 235 goto done; 224 236 } … … 226 238 ret = tdb_unpack(data.dptr, data.dsize, 227 239 PL_TSTAMP_FORMAT, &time_h, &time_l); 240 TALLOC_FREE(data.dptr); 228 241 if (ret == -1) { 229 242 DEBUG(1, ("Failed to un pack printer data")); … … 280 293 281 294 static NTSTATUS printer_list_traverse(printer_list_trv_fn_t *fn, 282 void *private_data) 283 { 284 struct db_context *db; 285 int ret; 295 void *private_data, 296 bool read_only) 297 { 298 struct db_context *db; 299 NTSTATUS status; 286 300 287 301 db = get_printer_list_db(); … … 290 304 } 291 305 292 ret = db->traverse(db, fn, private_data); 293 if (ret < 0) { 294 return NT_STATUS_UNSUCCESSFUL; 295 } 296 297 return NT_STATUS_OK; 306 if (read_only) { 307 status = dbwrap_traverse_read(db, fn, private_data, NULL); 308 } else { 309 status = dbwrap_traverse(db, fn, private_data, NULL); 310 } 311 312 return status; 298 313 } 299 314 … … 313 328 char *location; 314 329 int ret; 330 TDB_DATA key; 331 TDB_DATA value; 332 333 key = dbwrap_record_get_key(rec); 315 334 316 335 /* skip anything that does not contain PL_DATA_FORMAT data */ 317 if (strncmp((char *) rec->key.dptr,336 if (strncmp((char *)key.dptr, 318 337 PL_KEY_PREFIX, sizeof(PL_KEY_PREFIX)-1)) { 319 338 return 0; 320 339 } 321 340 322 ret = tdb_unpack(rec->value.dptr, rec->value.dsize, 341 value = dbwrap_record_get_value(rec); 342 343 ret = tdb_unpack(value.dptr, value.dsize, 323 344 PL_DATA_FORMAT, &time_h, &time_l, &name, &comment, 324 345 &location); … … 336 357 337 358 if (refresh < state->last_refresh) { 338 state->status = rec->delete_rec(rec);359 state->status = dbwrap_record_delete(rec); 339 360 if (!NT_STATUS_IS_OK(state->status)) { 340 361 return -1; … … 357 378 state.status = NT_STATUS_OK; 358 379 359 status = printer_list_traverse(printer_list_clean_fn, &state );380 status = printer_list_traverse(printer_list_clean_fn, &state, false); 360 381 if (NT_STATUS_EQUAL(status, NT_STATUS_UNSUCCESSFUL) && 361 382 !NT_STATUS_IS_OK(state.status)) { … … 381 402 char *location; 382 403 int ret; 404 TDB_DATA key; 405 TDB_DATA value; 406 407 key = dbwrap_record_get_key(rec); 383 408 384 409 /* always skip PL_TIMESTAMP_KEY key */ 385 if (strequal((const char *) rec->key.dptr, PL_TIMESTAMP_KEY)) {410 if (strequal((const char *)key.dptr, PL_TIMESTAMP_KEY)) { 386 411 return 0; 387 412 } 388 413 389 ret = tdb_unpack(rec->value.dptr, rec->value.dsize, 414 value = dbwrap_record_get_value(rec); 415 416 ret = tdb_unpack(value.dptr, value.dsize, 390 417 PL_DATA_FORMAT, &time_h, &time_l, &name, &comment, 391 418 &location); … … 404 431 } 405 432 406 NTSTATUS printer_list_r un_fn(void (*fn)(const char *, const char *, const char *, void *),407 433 NTSTATUS printer_list_read_run_fn(void (*fn)(const char *, const char *, const char *, void *), 434 void *private_data) 408 435 { 409 436 struct printer_list_exec_state state; … … 414 441 state.status = NT_STATUS_OK; 415 442 416 status = printer_list_traverse(printer_list_exec_fn, &state );443 status = printer_list_traverse(printer_list_exec_fn, &state, true); 417 444 if (NT_STATUS_EQUAL(status, NT_STATUS_UNSUCCESSFUL) && 418 445 !NT_STATUS_IS_OK(state.status)) { -
vendor/current/source3/printing/printer_list.h
r740 r988 101 101 NTSTATUS printer_list_clean_old(void); 102 102 103 NTSTATUS printer_list_r un_fn(void (*fn)(const char *, const char *, const char *, void *),104 103 NTSTATUS printer_list_read_run_fn(void (*fn)(const char *, const char *, const char *, void *), 104 void *private_data); 105 105 #endif /* _PRINTER_LIST_H_ */ -
vendor/current/source3/printing/printing.c
r860 r988 29 29 #include "printing/notify.h" 30 30 #include "printing/pcap.h" 31 #include "printing/printer_list.h" 32 #include "printing/queue_process.h" 31 33 #include "serverid.h" 32 34 #include "smbd/smbd.h" … … 34 36 #include "messages.h" 35 37 #include "util_tdb.h" 38 #include "lib/param/loadparm.h" 39 #include "lib/util/sys_rw_data.h" 36 40 37 41 extern struct current_user current_user; … … 39 43 40 44 /* Current printer interface */ 41 static bool remove_from_jobs_added(const char* sharename, uint32 jobid);45 static bool remove_from_jobs_added(const char* sharename, uint32_t jobid); 42 46 43 47 /* … … 56 60 57 61 static TDB_CONTEXT *rap_tdb; 58 static uint16 next_rap_jobid;62 static uint16_t next_rap_jobid; 59 63 struct rap_jobid_key { 60 64 fstring sharename; 61 uint32 jobid;65 uint32_t jobid; 62 66 }; 63 67 … … 67 71 ***************************************************************************/ 68 72 69 uint16 pjobid_to_rap(const char* sharename, uint32jobid)70 { 71 uint16 rap_jobid;73 uint16_t pjobid_to_rap(const char* sharename, uint32_t jobid) 74 { 75 uint16_t rap_jobid; 72 76 TDB_DATA data, key; 73 77 struct rap_jobid_key jinfo; 74 uint8 buf[2];78 uint8_t buf[2]; 75 79 76 80 DEBUG(10,("pjobid_to_rap: called.\n")); … … 86 90 fstrcpy( jinfo.sharename, sharename ); 87 91 jinfo.jobid = jobid; 88 key.dptr = (uint8 *)&jinfo;92 key.dptr = (uint8_t *)&jinfo; 89 93 key.dsize = sizeof(jinfo); 90 94 91 95 data = tdb_fetch(rap_tdb, key); 92 if (data.dptr && data.dsize == sizeof(uint16 )) {96 if (data.dptr && data.dsize == sizeof(uint16_t)) { 93 97 rap_jobid = SVAL(data.dptr, 0); 94 98 SAFE_FREE(data.dptr); … … 113 117 } 114 118 115 bool rap_to_pjobid(uint16 rap_jobid, fstring sharename, uint32*pjobid)119 bool rap_to_pjobid(uint16_t rap_jobid, fstring sharename, uint32_t *pjobid) 116 120 { 117 121 TDB_DATA data, key; 118 uint8 buf[2];122 uint8_t buf[2]; 119 123 120 124 DEBUG(10,("rap_to_pjobid called.\n")); … … 146 150 } 147 151 148 void rap_jobid_delete(const char* sharename, uint32 jobid)152 void rap_jobid_delete(const char* sharename, uint32_t jobid) 149 153 { 150 154 TDB_DATA key, data; 151 uint16 rap_jobid;155 uint16_t rap_jobid; 152 156 struct rap_jobid_key jinfo; 153 uint8 buf[2];157 uint8_t buf[2]; 154 158 155 159 DEBUG(10,("rap_jobid_delete: called.\n")); … … 161 165 fstrcpy( jinfo.sharename, sharename ); 162 166 jinfo.jobid = jobid; 163 key.dptr = (uint8 *)&jinfo;167 key.dptr = (uint8_t *)&jinfo; 164 168 key.dsize = sizeof(jinfo); 165 169 166 170 data = tdb_fetch(rap_tdb, key); 167 if (!data.dptr || (data.dsize != sizeof(uint16 ))) {171 if (!data.dptr || (data.dsize != sizeof(uint16_t))) { 168 172 DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n", 169 173 (unsigned int)jobid )); … … 195 199 int services = lp_numservices(); 196 200 int snum; 197 198 unlink(cache_path("printing.tdb")); 199 mkdir(cache_path("printing"),0755); 201 bool ok; 202 char *print_cache_path; 203 204 if (!printer_list_parent_init()) { 205 return false; 206 } 207 208 print_cache_path = cache_path("printing"); 209 if (print_cache_path == NULL) { 210 return false; 211 } 212 ok = directory_create_or_exist(print_cache_path, 0755); 213 TALLOC_FREE(print_cache_path); 214 if (!ok) { 215 return false; 216 } 217 218 print_cache_path = cache_path("printing.tdb"); 219 if (print_cache_path == NULL) { 220 return false; 221 } 222 unlink(print_cache_path); 223 TALLOC_FREE(print_cache_path); 200 224 201 225 /* handle a Samba upgrade */ … … 203 227 for (snum = 0; snum < services; snum++) { 204 228 struct tdb_print_db *pdb; 205 if (!lp_print _ok(snum))229 if (!lp_printable(snum)) 206 230 continue; 207 231 … … 209 233 if (!pdb) 210 234 continue; 211 if (tdb_lock_bystring(pdb->tdb, sversion) == -1) {235 if (tdb_lock_bystring(pdb->tdb, sversion) != 0) { 212 236 DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) )); 213 237 release_print_db(pdb); … … 277 301 ****************************************************************************/ 278 302 279 static TDB_DATA print_key(uint32 jobid, uint32*tmp)303 static TDB_DATA print_key(uint32_t jobid, uint32_t *tmp) 280 304 { 281 305 TDB_DATA ret; 282 306 283 307 SIVAL(tmp, 0, jobid); 284 ret.dptr = (uint8 *)tmp;308 ret.dptr = (uint8_t *)tmp; 285 309 ret.dsize = sizeof(*tmp); 286 310 return ret; … … 290 314 Pack the devicemode to store it in a tdb. 291 315 ****************************************************************************/ 292 static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)316 static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8_t *buf, int buflen) 293 317 { 294 318 enum ndr_err_code ndr_err; … … 324 348 ****************************************************************************/ 325 349 static int unpack_devicemode(TALLOC_CTX *mem_ctx, 326 const uint8 *buf, int buflen,350 const uint8_t *buf, int buflen, 327 351 struct spoolss_DeviceMode **devmode) 328 352 { … … 374 398 ***********************************************************************/ 375 399 376 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,400 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8_t *buf, int buflen, 377 401 struct printjob *pjob) 378 402 { 379 403 int len = 0; 380 404 int used; 381 uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;382 uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;405 uint32_t pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus; 406 uint32_t pjsize, pjpage_count, pjspooled, pjsmbjob; 383 407 384 408 if (!buf || !pjob) { … … 435 459 static struct printjob *print_job_find(TALLOC_CTX *mem_ctx, 436 460 const char *sharename, 437 uint32 jobid)461 uint32_t jobid) 438 462 { 439 463 struct printjob *pjob; … … 479 503 } 480 504 481 /* Convert a unix jobid to a smb jobid */ 482 483 struct unixjob_traverse_state { 505 struct job_traverse_state { 484 506 int sysjob; 485 uint32 sysjob_to_jobid_value;507 uint32_t jobid; 486 508 }; 487 509 488 static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, 489 TDB_DATA data, void *private_data) 510 /* find spoolss jobid based on sysjob */ 511 static int sysjob_to_jobid_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, 512 TDB_DATA data, void *private_data) 490 513 { 491 514 struct printjob *pjob; 492 struct unixjob_traverse_state *state =493 (struct unixjob_traverse_state *)private_data;515 struct job_traverse_state *state = 516 (struct job_traverse_state *)private_data; 494 517 495 518 if (!data.dptr || data.dsize == 0) … … 497 520 498 521 pjob = (struct printjob *)data.dptr; 499 if (key.dsize != sizeof(uint32 ))522 if (key.dsize != sizeof(uint32_t)) 500 523 return 0; 501 524 502 525 if (state->sysjob == pjob->sysjob) { 503 state-> sysjob_to_jobid_value= pjob->jobid;526 state->jobid = pjob->jobid; 504 527 return 1; 505 528 } … … 508 531 } 509 532 510 static uint32sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)511 { 512 struct unixjob_traverse_state state;533 uint32_t sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob) 534 { 535 struct job_traverse_state state; 513 536 514 537 state.sysjob = sysjob; 515 state. sysjob_to_jobid_value = (uint32)-1;516 517 tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);518 519 return state. sysjob_to_jobid_value;538 state.jobid = (uint32_t)-1; 539 540 tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state); 541 542 return state.jobid; 520 543 } 521 544 … … 525 548 ****************************************************************************/ 526 549 527 uint32 sysjob_to_jobid(int unix_jobid)550 uint32_t sysjob_to_jobid(int unix_jobid) 528 551 { 529 552 int services = lp_numservices(); 530 553 int snum; 531 struct unixjob_traverse_state state;554 struct job_traverse_state state; 532 555 533 556 state.sysjob = unix_jobid; 534 state. sysjob_to_jobid_value = (uint32)-1;557 state.jobid = (uint32_t)-1; 535 558 536 559 for (snum = 0; snum < services; snum++) { 537 560 struct tdb_print_db *pdb; 538 if (!lp_print _ok(snum))561 if (!lp_printable(snum)) 539 562 continue; 540 563 pdb = get_print_db_byname(lp_const_servicename(snum)); … … 542 565 continue; 543 566 } 544 tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);567 tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state); 545 568 release_print_db(pdb); 546 if (state.sysjob_to_jobid_value != (uint32)-1) 547 return state.sysjob_to_jobid_value; 548 } 549 return (uint32)-1; 569 if (state.jobid != (uint32_t)-1) 570 return state.jobid; 571 } 572 return (uint32_t)-1; 573 } 574 575 /* find sysjob based on spoolss jobid */ 576 static int jobid_to_sysjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key, 577 TDB_DATA data, void *private_data) 578 { 579 struct printjob *pjob; 580 struct job_traverse_state *state = 581 (struct job_traverse_state *)private_data; 582 583 if (!data.dptr || data.dsize == 0) 584 return 0; 585 586 pjob = (struct printjob *)data.dptr; 587 if (key.dsize != sizeof(uint32_t)) 588 return 0; 589 590 if (state->jobid == pjob->jobid) { 591 state->sysjob = pjob->sysjob; 592 return 1; 593 } 594 595 return 0; 596 } 597 598 int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid) 599 { 600 struct job_traverse_state state; 601 602 state.sysjob = -1; 603 state.jobid = jobid; 604 605 tdb_traverse(pdb->tdb, jobid_to_sysjob_traverse_fn, &state); 606 607 return state.sysjob; 550 608 } 551 609 … … 575 633 appropriate win32 API constant. */ 576 634 577 static uint32 map_to_spoolss_status(uint32lpq_status)635 static uint32_t map_to_spoolss_status(uint32_t lpq_status) 578 636 { 579 637 int i = 0; … … 598 656 599 657 SIVAL(&store_jobid, 0, jobid); 600 data.dptr = (uint8 *) &store_jobid;658 data.dptr = (uint8_t *) &store_jobid; 601 659 data.dsize = 4; 602 660 … … 627 685 key = string_tdb_data("INFO/jobs_changed"); 628 686 629 if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)687 if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0) 630 688 goto out; 631 689 … … 639 697 job_count = data.dsize / 4; 640 698 for (i = 0; i < job_count; i++) { 641 uint32 ch_jobid;699 uint32_t ch_jobid; 642 700 643 701 ch_jobid = IVAL(data.dptr, i*4); … … 646 704 memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 ); 647 705 data.dsize -= 4; 648 if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)706 if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0) 649 707 goto out; 650 708 break; … … 668 726 static void pjob_store_notify(struct tevent_context *ev, 669 727 struct messaging_context *msg_ctx, 670 const char* sharename, uint32 jobid,728 const char* sharename, uint32_t jobid, 671 729 struct printjob *old_data, 672 730 struct printjob *new_data, … … 734 792 static bool pjob_store(struct tevent_context *ev, 735 793 struct messaging_context *msg_ctx, 736 const char* sharename, uint32 jobid,794 const char* sharename, uint32_t jobid, 737 795 struct printjob *pjob) 738 796 { … … 741 799 bool ret = False; 742 800 struct tdb_print_db *pdb = get_print_db_byname(sharename); 743 uint8 *buf = NULL;801 uint8_t *buf = NULL; 744 802 int len, newlen, buflen; 745 803 … … 760 818 buflen = newlen; 761 819 len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff", 762 (uint32 )pjob->pid,763 (uint32 )pjob->jobid,764 (uint32 )pjob->sysjob,765 (uint32 )pjob->fd,766 (uint32 )pjob->starttime,767 (uint32 )pjob->status,768 (uint32 )pjob->size,769 (uint32 )pjob->page_count,770 (uint32 )pjob->spooled,771 (uint32 )pjob->smbjob,820 (uint32_t)pjob->pid, 821 (uint32_t)pjob->jobid, 822 (uint32_t)pjob->sysjob, 823 (uint32_t)pjob->fd, 824 (uint32_t)pjob->starttime, 825 (uint32_t)pjob->status, 826 (uint32_t)pjob->size, 827 (uint32_t)pjob->page_count, 828 (uint32_t)pjob->spooled, 829 (uint32_t)pjob->smbjob, 772 830 pjob->filename, 773 831 pjob->jobname, … … 779 837 780 838 if (buflen != len) { 781 buf = (uint8 *)SMB_REALLOC(buf, len);839 buf = (uint8_t *)SMB_REALLOC(buf, len); 782 840 if (!buf) { 783 841 DEBUG(0,("pjob_store: failed to enlarge buffer!\n")); … … 843 901 static void pjob_delete(struct tevent_context *ev, 844 902 struct messaging_context *msg_ctx, 845 const char* sharename, uint32 jobid)903 const char* sharename, uint32_t jobid) 846 904 { 847 905 uint32_t tmp; 848 906 struct printjob *pjob; 849 uint32 job_status = 0;907 uint32_t job_status = 0; 850 908 struct tdb_print_db *pdb; 851 909 TALLOC_CTX *tmp_ctx = talloc_new(ev); … … 891 949 struct messaging_context *msg_ctx, 892 950 const char *sharename, print_queue_struct *q, 893 uint32 jobid)951 uint32_t jobid) 894 952 { 895 953 struct printjob pj, *old_pj; … … 899 957 } 900 958 901 if (jobid == (uint32 )-1) {959 if (jobid == (uint32_t)-1) { 902 960 jobid = q->sysjob + UNIX_JOB_START; 903 961 } … … 953 1011 struct traverse_struct *ts = (struct traverse_struct *)state; 954 1012 struct printjob pjob; 955 uint32 jobid;1013 uint32_t jobid; 956 1014 int i = 0; 957 1015 … … 1133 1191 TDB_DATA key; 1134 1192 TDB_DATA data; 1135 pid_t updating_pid = sys_getpid();1136 uint8 buffer[4];1193 pid_t updating_pid = getpid(); 1194 uint8_t buffer[4]; 1137 1195 1138 1196 struct tdb_print_db *pdb = get_print_db_byname(sharename); … … 1144 1202 key = string_tdb_data(keystr); 1145 1203 1146 DEBUG(5, ("set_updating_pid: %s 1204 DEBUG(5, ("set_updating_pid: %supdating lpq cache for print share %s\n", 1147 1205 updating ? "" : "not ", 1148 1206 sharename )); … … 1192 1250 { 1193 1251 TDB_DATA data; 1194 int max_reported_jobs = lp_max_reported_ jobs(pts->snum);1252 int max_reported_jobs = lp_max_reported_print_jobs(pts->snum); 1195 1253 print_queue_struct *queue = pts->queue; 1196 1254 size_t len; … … 1212 1270 qcount++; 1213 1271 data.dsize += tdb_pack(NULL, 0, "ddddddff", 1214 (uint32 )queue[i].sysjob,1215 (uint32 )queue[i].size,1216 (uint32 )queue[i].page_count,1217 (uint32 )queue[i].status,1218 (uint32 )queue[i].priority,1219 (uint32 )queue[i].time,1272 (uint32_t)queue[i].sysjob, 1273 (uint32_t)queue[i].size, 1274 (uint32_t)queue[i].page_count, 1275 (uint32_t)queue[i].status, 1276 (uint32_t)queue[i].priority, 1277 (uint32_t)queue[i].time, 1220 1278 queue[i].fs_user, 1221 1279 queue[i].fs_file); 1222 1280 } 1223 1281 1224 if ((data.dptr = (uint8 *)SMB_MALLOC(data.dsize)) == NULL)1282 if ((data.dptr = (uint8_t *)SMB_MALLOC(data.dsize)) == NULL) 1225 1283 return; 1226 1284 … … 1232 1290 1233 1291 len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff", 1234 (uint32 )queue[i].sysjob,1235 (uint32 )queue[i].size,1236 (uint32 )queue[i].page_count,1237 (uint32 )queue[i].status,1238 (uint32 )queue[i].priority,1239 (uint32 )queue[i].time,1292 (uint32_t)queue[i].sysjob, 1293 (uint32_t)queue[i].size, 1294 (uint32_t)queue[i].page_count, 1295 (uint32_t)queue[i].status, 1296 (uint32_t)queue[i].priority, 1297 (uint32_t)queue[i].time, 1240 1298 queue[i].fs_user, 1241 1299 queue[i].fs_file); … … 1263 1321 } 1264 1322 1265 static void check_job_added(const char *sharename, TDB_DATA data, uint32 jobid)1323 static void check_job_added(const char *sharename, TDB_DATA data, uint32_t jobid) 1266 1324 { 1267 1325 unsigned int i; … … 1269 1327 1270 1328 for (i = 0; i < job_count; i++) { 1271 uint32 ch_jobid;1329 uint32_t ch_jobid; 1272 1330 1273 1331 ch_jobid = IVAL(data.dptr, i*4); … … 1305 1363 1306 1364 if (last_qscan_time == ((time_t)-1) 1307 || (time_now - last_qscan_time) >= lp_lpq cachetime()1365 || (time_now - last_qscan_time) >= lp_lpq_cache_time() 1308 1366 || last_qscan_time > (time_now + MAX_CACHE_VALID_TIME)) 1309 1367 { 1310 uint32 u;1368 uint32_t u; 1311 1369 time_t msg_pending_time; 1312 1370 … … 1314 1372 "(last_qscan_time = %d, time now = %d, qcachetime = %d)\n", 1315 1373 sharename, (int)last_qscan_time, (int)time_now, 1316 (int)lp_lpq cachetime() ));1374 (int)lp_lpq_cache_time() )); 1317 1375 1318 1376 /* check if another smbd has already sent a message to update the … … 1408 1466 1409 1467 for (i=0; i<qcount; i++) { 1410 uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);1411 if (jobid == (uint32 )-1) {1468 uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob); 1469 if (jobid == (uint32_t)-1) { 1412 1470 /* assume its a unix print job */ 1413 1471 print_unix_job(ev, msg_ctx, … … 1478 1536 1479 1537 status.qcount = qcount; 1480 data.dptr = (uint8 *)&status;1538 data.dptr = (uint8_t *)&status; 1481 1539 data.dsize = sizeof(status); 1482 1540 tdb_store(pdb->tdb, key, data, TDB_REPLACE); … … 1488 1546 1489 1547 slprintf(keystr, sizeof(keystr)-1, "CACHE/%s", sharename); 1490 tdb_store_int32(pdb->tdb, keystr, (int32 )time(NULL));1548 tdb_store_int32(pdb->tdb, keystr, (int32_t)time(NULL)); 1491 1549 1492 1550 /* clear the msg pending record for this queue */ … … 1546 1604 slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", sharename); 1547 1605 /* Only wait 10 seconds for this. */ 1548 if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) == -1) {1606 if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) != 0) { 1549 1607 DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename)); 1550 1608 release_print_db(pdb); … … 1606 1664 size_t len; 1607 1665 1608 len = tdb_unpack( (uint8 *)data->data, data->length, "fdPP",1666 len = tdb_unpack( (uint8_t *)data->data, data->length, "fdPP", 1609 1667 sharename, 1610 1668 &printing_type, … … 1628 1686 } 1629 1687 1630 static void printing_pause_fd_handler(struct tevent_context *ev,1631 struct tevent_fd *fde,1632 uint16_t flags,1633 void *private_data)1634 {1635 /*1636 * If pause_pipe[1] is closed it means the parent smbd1637 * and children exited or aborted.1638 */1639 exit_server_cleanly(NULL);1640 }1641 1642 extern struct child_pid *children;1643 extern int num_children;1644 1645 static void add_child_pid(pid_t pid)1646 {1647 struct child_pid *child;1648 1649 child = SMB_MALLOC_P(struct child_pid);1650 if (child == NULL) {1651 DEBUG(0, ("Could not add child struct -- malloc failed\n"));1652 return;1653 }1654 child->pid = pid;1655 DLIST_ADD(children, child);1656 num_children += 1;1657 }1658 1659 /****************************************************************************1660 Notify smbds of new printcap data1661 **************************************************************************/1662 static void reload_pcap_change_notify(struct tevent_context *ev,1663 struct messaging_context *msg_ctx)1664 {1665 /*1666 * Reload the printers first in the background process so that1667 * newly added printers get default values created in the registry.1668 *1669 * This will block the process for some time (~1 sec per printer), but1670 * it doesn't block smbd's servering clients.1671 */1672 reload_printers_full(ev, msg_ctx);1673 1674 message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);1675 }1676 1677 static bool printer_housekeeping_fn(const struct timeval *now,1678 void *private_data)1679 {1680 static time_t last_pcap_reload_time = 0;1681 time_t printcap_cache_time = (time_t)lp_printcap_cache_time();1682 time_t t = time_mono(NULL);1683 1684 DEBUG(5, ("printer housekeeping\n"));1685 1686 /* if periodic printcap rescan is enabled, see if it's time to reload */1687 if ((printcap_cache_time != 0)1688 && (t >= (last_pcap_reload_time + printcap_cache_time))) {1689 DEBUG( 3,( "Printcap cache time expired.\n"));1690 pcap_cache_reload(server_event_context(),1691 smbd_messaging_context(),1692 &reload_pcap_change_notify);1693 last_pcap_reload_time = t;1694 }1695 1696 return true;1697 }1698 1699 static void printing_sig_term_handler(struct tevent_context *ev,1700 struct tevent_signal *se,1701 int signum,1702 int count,1703 void *siginfo,1704 void *private_data)1705 {1706 exit_server_cleanly("termination signal");1707 }1708 1709 static void printing_sig_hup_handler(struct tevent_context *ev,1710 struct tevent_signal *se,1711 int signum,1712 int count,1713 void *siginfo,1714 void *private_data)1715 {1716 struct messaging_context *msg_ctx = talloc_get_type_abort(1717 private_data, struct messaging_context);1718 1719 DEBUG(1,("Reloading printers after SIGHUP\n"));1720 pcap_cache_reload(ev, msg_ctx,1721 &reload_pcap_change_notify);1722 }1723 1724 static void printing_conf_updated(struct messaging_context *msg,1725 void *private_data,1726 uint32_t msg_type,1727 struct server_id server_id,1728 DATA_BLOB *data)1729 {1730 DEBUG(5,("Reloading printers after conf change\n"));1731 pcap_cache_reload(messaging_event_context(msg), msg,1732 &reload_pcap_change_notify);1733 }1734 1735 1736 static pid_t background_lpq_updater_pid = -1;1737 1738 /****************************************************************************1739 main thread of the background lpq updater1740 ****************************************************************************/1741 void start_background_queue(struct tevent_context *ev,1742 struct messaging_context *msg_ctx)1743 {1744 /* Use local variables for this as we don't1745 * need to save the parent side of this, just1746 * ensure it closes when the process exits.1747 */1748 int pause_pipe[2];1749 1750 DEBUG(3,("start_background_queue: Starting background LPQ thread\n"));1751 1752 if (pipe(pause_pipe) == -1) {1753 DEBUG(5,("start_background_queue: cannot create pipe. %s\n", strerror(errno) ));1754 exit(1);1755 }1756 1757 background_lpq_updater_pid = sys_fork();1758 1759 if (background_lpq_updater_pid == -1) {1760 DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));1761 exit(1);1762 }1763 1764 /* Track the printing pid along with other smbd children */1765 add_child_pid(background_lpq_updater_pid);1766 1767 if(background_lpq_updater_pid == 0) {1768 struct tevent_fd *fde;1769 int ret;1770 NTSTATUS status;1771 struct tevent_signal *se;1772 1773 /* Child. */1774 DEBUG(5,("start_background_queue: background LPQ thread started\n"));1775 1776 close(pause_pipe[0]);1777 pause_pipe[0] = -1;1778 1779 status = reinit_after_fork(msg_ctx, ev, procid_self(), true);1780 1781 if (!NT_STATUS_IS_OK(status)) {1782 DEBUG(0,("reinit_after_fork() failed\n"));1783 smb_panic("reinit_after_fork() failed");1784 }1785 1786 se = tevent_add_signal(ev, ev, SIGTERM, 0,1787 printing_sig_term_handler,1788 NULL);1789 if (se == NULL) {1790 smb_panic("failed to setup SIGTERM handler");1791 }1792 se = tevent_add_signal(ev, ev, SIGHUP, 0,1793 printing_sig_hup_handler,1794 msg_ctx);1795 if (se == NULL) {1796 smb_panic("failed to setup SIGHUP handler");1797 }1798 1799 if (!serverid_register(procid_self(),1800 FLAG_MSG_GENERAL|FLAG_MSG_SMBD1801 |FLAG_MSG_PRINT_GENERAL)) {1802 exit(1);1803 }1804 1805 if (!locking_init()) {1806 exit(1);1807 }1808 1809 messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,1810 print_queue_receive);1811 messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED,1812 printing_conf_updated);1813 1814 fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,1815 printing_pause_fd_handler,1816 NULL);1817 if (!fde) {1818 DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));1819 smb_panic("tevent_add_fd() failed for pause_pipe");1820 }1821 1822 /* reload on startup to ensure parent smbd is refreshed */1823 pcap_cache_reload(server_event_context(),1824 smbd_messaging_context(),1825 &reload_pcap_change_notify);1826 1827 if (!(event_add_idle(ev, NULL,1828 timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),1829 "printer_housekeeping",1830 printer_housekeeping_fn,1831 NULL))) {1832 DEBUG(0, ("Could not add printing housekeeping event\n"));1833 exit(1);1834 }1835 1836 DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));1837 ret = tevent_loop_wait(ev);1838 /* should not be reached */1839 DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",1840 ret, (ret == 0) ? "out of events" : strerror(errno)));1841 exit(1);1842 }1843 1844 close(pause_pipe[1]);1845 }1846 1847 1688 /**************************************************************************** 1848 1689 update the internal database from the system print queue for a queue 1849 1690 ****************************************************************************/ 1691 1692 extern pid_t background_lpq_updater_pid; 1850 1693 1851 1694 static void print_queue_update(struct messaging_context *msg_ctx, … … 1856 1699 char *lpqcommand = NULL; 1857 1700 char *lprmcommand = NULL; 1858 uint8 *buffer = NULL;1701 uint8_t *buffer = NULL; 1859 1702 size_t len = 0; 1860 1703 size_t newlen; … … 1869 1712 1870 1713 lpqcommand = talloc_string_sub2(ctx, 1871 lp_lpq command(snum),1714 lp_lpq_command(talloc_tos(), snum), 1872 1715 "%p", 1873 lp_printername( snum),1716 lp_printername(talloc_tos(), snum), 1874 1717 false, false, false); 1875 1718 if (!lpqcommand) { … … 1877 1720 } 1878 1721 lpqcommand = talloc_sub_advanced(ctx, 1879 lp_servicename( snum),1722 lp_servicename(talloc_tos(), snum), 1880 1723 current_user_info.unix_name, 1881 1724 "", … … 1889 1732 1890 1733 lprmcommand = talloc_string_sub2(ctx, 1891 lp_lprm command(snum),1734 lp_lprm_command(talloc_tos(), snum), 1892 1735 "%p", 1893 lp_printername( snum),1736 lp_printername(talloc_tos(), snum), 1894 1737 false, false, false); 1895 1738 if (!lprmcommand) { … … 1897 1740 } 1898 1741 lprmcommand = talloc_sub_advanced(ctx, 1899 lp_servicename( snum),1742 lp_servicename(talloc_tos(), snum), 1900 1743 current_user_info.unix_name, 1901 1744 "", … … 1933 1776 lprmcommand ); 1934 1777 1935 buffer = SMB_XMALLOC_ARRAY( uint8 , len );1778 buffer = SMB_XMALLOC_ARRAY( uint8_t, len ); 1936 1779 1937 1780 /* now pack the buffer */ … … 1972 1815 1973 1816 messaging_send_buf(msg_ctx, pid_to_procid(background_lpq_updater_pid), 1974 MSG_PRINTER_UPDATE, (uint8 *)buffer, len);1817 MSG_PRINTER_UPDATE, (uint8_t *)buffer, len); 1975 1818 1976 1819 SAFE_FREE( buffer ); … … 1990 1833 TDB_CONTEXT *tdb = NULL; 1991 1834 const char *printername; 1992 uint32 mypid = (uint32)sys_getpid();1835 uint32_t mypid = (uint32_t)getpid(); 1993 1836 bool ret = False; 1994 1837 size_t i; … … 2004 1847 2005 1848 for ( idx=0; idx<num_services; idx++ ) { 2006 if (lp_snum_ok(idx) && lp_print _ok(idx) )1849 if (lp_snum_ok(idx) && lp_printable(idx) ) 2007 1850 print_notify_register_pid(idx); 2008 1851 } … … 2019 1862 } 2020 1863 2021 if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {1864 if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) { 2022 1865 DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n", 2023 1866 printername)); … … 2033 1876 for (i = 0; i < data.dsize; i += 8) { 2034 1877 if (IVAL(data.dptr,i) == mypid) { 2035 uint32 new_refcount = IVAL(data.dptr, i+4) + 1;1878 uint32_t new_refcount = IVAL(data.dptr, i+4) + 1; 2036 1879 SIVAL(data.dptr, i+4, new_refcount); 2037 1880 break; … … 2041 1884 if (i == data.dsize) { 2042 1885 /* We weren't in the list. Realloc. */ 2043 data.dptr = (uint8 *)SMB_REALLOC(data.dptr, data.dsize + 8);1886 data.dptr = (uint8_t *)SMB_REALLOC(data.dptr, data.dsize + 8); 2044 1887 if (!data.dptr) { 2045 1888 DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n", … … 2053 1896 2054 1897 /* Store back the record. */ 2055 if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {1898 if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) { 2056 1899 DEBUG(0,("print_notify_register_pid: Failed to update pid \ 2057 1900 list for printer %s\n", printername)); … … 2081 1924 TDB_CONTEXT *tdb = NULL; 2082 1925 const char *printername; 2083 uint32 mypid = (uint32)sys_getpid();1926 uint32_t mypid = (uint32_t)getpid(); 2084 1927 size_t i; 2085 1928 bool ret = False; … … 2094 1937 2095 1938 for ( idx=0; idx<num_services; idx++ ) { 2096 if ( lp_snum_ok(idx) && lp_print _ok(idx) )1939 if ( lp_snum_ok(idx) && lp_printable(idx) ) 2097 1940 print_notify_deregister_pid(idx); 2098 1941 } … … 2109 1952 } 2110 1953 2111 if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {1954 if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) { 2112 1955 DEBUG(0,("print_notify_register_pid: Failed to lock \ 2113 1956 printer %s database\n", printername)); … … 2123 1966 for (i = 0; i < data.dsize; ) { 2124 1967 if (IVAL(data.dptr,i) == mypid) { 2125 uint32 refcount = IVAL(data.dptr, i+4);1968 uint32_t refcount = IVAL(data.dptr, i+4); 2126 1969 2127 1970 refcount--; … … 2143 1986 2144 1987 /* Store back the record. */ 2145 if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {1988 if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) { 2146 1989 DEBUG(0,("print_notify_register_pid: Failed to update pid \ 2147 1990 list for printer %s\n", printername)); … … 2164 2007 ****************************************************************************/ 2165 2008 2166 bool print_job_exists(const char* sharename, uint32 jobid)2009 bool print_job_exists(const char* sharename, uint32_t jobid) 2167 2010 { 2168 2011 struct tdb_print_db *pdb = get_print_db_byname(sharename); … … 2185 2028 struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx, 2186 2029 const char *sharename, 2187 uint32 jobid)2030 uint32_t jobid) 2188 2031 { 2189 2032 struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid); … … 2201 2044 bool print_job_set_name(struct tevent_context *ev, 2202 2045 struct messaging_context *msg_ctx, 2203 const char *sharename, uint32 jobid, const char *name)2046 const char *sharename, uint32_t jobid, const char *name) 2204 2047 { 2205 2048 struct printjob *pjob; … … 2211 2054 2212 2055 pjob = print_job_find(tmp_ctx, sharename, jobid); 2213 if (!pjob || pjob->pid != sys_getpid()) {2056 if (!pjob || pjob->pid != getpid()) { 2214 2057 ret = false; 2215 2058 goto err_out; … … 2232 2075 2233 2076 pjob = print_job_find(mem_ctx, sharename, jobid); 2234 if (!pjob || pjob->pid != sys_getpid()) {2077 if (!pjob || pjob->pid != getpid()) { 2235 2078 return false; 2236 2079 } … … 2245 2088 ***************************************************************************/ 2246 2089 2247 static bool remove_from_jobs_added(const char* sharename, uint32 jobid)2090 static bool remove_from_jobs_added(const char* sharename, uint32_t jobid) 2248 2091 { 2249 2092 struct tdb_print_db *pdb = get_print_db_byname(sharename); … … 2261 2104 key = string_tdb_data("INFO/jobs_added"); 2262 2105 2263 if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)2106 if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0) 2264 2107 goto out; 2265 2108 … … 2273 2116 job_count = data.dsize / 4; 2274 2117 for (i = 0; i < job_count; i++) { 2275 uint32 ch_jobid;2118 uint32_t ch_jobid; 2276 2119 2277 2120 ch_jobid = IVAL(data.dptr, i*4); … … 2280 2123 memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 ); 2281 2124 data.dsize -= 4; 2282 if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)2125 if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0) 2283 2126 goto out; 2284 2127 break; … … 2306 2149 static bool print_job_delete1(struct tevent_context *ev, 2307 2150 struct messaging_context *msg_ctx, 2308 int snum, uint32 jobid)2151 int snum, uint32_t jobid) 2309 2152 { 2310 2153 const char* sharename = lp_const_servicename(snum); … … 2350 2193 { 2351 2194 result = (*(current_printif->job_delete))( 2352 lp_printername( snum),2353 lp_lprm command(snum),2195 lp_printername(talloc_tos(), snum), 2196 lp_lprm_command(talloc_tos(), snum), 2354 2197 pjob); 2355 2198 … … 2384 2227 ****************************************************************************/ 2385 2228 2386 static bool is_owner(const struct auth_se rversupplied_info *server_info,2229 static bool is_owner(const struct auth_session_info *server_info, 2387 2230 const char *servicename, 2388 uint32 jobid)2231 uint32_t jobid) 2389 2232 { 2390 2233 struct printjob *pjob; … … 2401 2244 } 2402 2245 2403 ret = strequal(pjob->user, server_info-> sanitized_username);2246 ret = strequal(pjob->user, server_info->unix_info->sanitized_username); 2404 2247 err_out: 2405 2248 talloc_free(tmp_ctx); … … 2411 2254 ****************************************************************************/ 2412 2255 2413 WERROR print_job_delete(const struct auth_se rversupplied_info *server_info,2256 WERROR print_job_delete(const struct auth_session_info *server_info, 2414 2257 struct messaging_context *msg_ctx, 2415 2258 int snum, uint32_t jobid) … … 2430 2273 2431 2274 if (!owner && 2432 !print_access_check(server_info, msg_ctx, snum, 2433 JOB_ACCESS_ADMINISTER)) { 2434 DEBUG(3, ("delete denied by security descriptor\n")); 2435 2436 /* BEGIN_ADMIN_LOG */ 2437 sys_adminlog( LOG_ERR, 2438 "Permission denied-- user not allowed to delete, \ 2439 pause, or resume print job. User name: %s. Printer name: %s.", 2440 uidtoname(server_info->utok.uid), 2441 lp_printername(snum) ); 2442 /* END_ADMIN_LOG */ 2275 !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum, 2276 JOB_ACCESS_ADMINISTER))) { 2277 DEBUG(0, ("print job delete denied." 2278 "User name: %s, Printer name: %s.", 2279 uidtoname(server_info->unix_token->uid), 2280 lp_printername(tmp_ctx, snum))); 2443 2281 2444 2282 werr = WERR_ACCESS_DENIED; … … 2490 2328 ****************************************************************************/ 2491 2329 2492 WERROR print_job_pause(const struct auth_se rversupplied_info *server_info,2330 WERROR print_job_pause(const struct auth_session_info *server_info, 2493 2331 struct messaging_context *msg_ctx, 2494 int snum, uint32 jobid)2332 int snum, uint32_t jobid) 2495 2333 { 2496 2334 const char* sharename = lp_const_servicename(snum); … … 2520 2358 2521 2359 if (!is_owner(server_info, lp_const_servicename(snum), jobid) && 2522 !print_access_check(server_info, msg_ctx, snum, 2523 JOB_ACCESS_ADMINISTER)) { 2524 DEBUG(3, ("pause denied by security descriptor\n")); 2525 2526 /* BEGIN_ADMIN_LOG */ 2527 sys_adminlog( LOG_ERR, 2528 "Permission denied-- user not allowed to delete, \ 2529 pause, or resume print job. User name: %s. Printer name: %s.", 2530 uidtoname(server_info->utok.uid), 2531 lp_printername(snum) ); 2532 /* END_ADMIN_LOG */ 2360 !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum, 2361 JOB_ACCESS_ADMINISTER))) { 2362 DEBUG(0, ("print job pause denied." 2363 "User name: %s, Printer name: %s.", 2364 uidtoname(server_info->unix_token->uid), 2365 lp_printername(tmp_ctx, snum))); 2533 2366 2534 2367 werr = WERR_ACCESS_DENIED; … … 2563 2396 ****************************************************************************/ 2564 2397 2565 WERROR print_job_resume(const struct auth_se rversupplied_info *server_info,2398 WERROR print_job_resume(const struct auth_session_info *server_info, 2566 2399 struct messaging_context *msg_ctx, 2567 int snum, uint32 jobid)2400 int snum, uint32_t jobid) 2568 2401 { 2569 2402 const char *sharename = lp_const_servicename(snum); … … 2592 2425 2593 2426 if (!is_owner(server_info, lp_const_servicename(snum), jobid) && 2594 !print_access_check(server_info, msg_ctx, snum, 2595 JOB_ACCESS_ADMINISTER)) { 2596 DEBUG(3, ("resume denied by security descriptor\n")); 2597 2598 /* BEGIN_ADMIN_LOG */ 2599 sys_adminlog( LOG_ERR, 2600 "Permission denied-- user not allowed to delete, \ 2601 pause, or resume print job. User name: %s. Printer name: %s.", 2602 uidtoname(server_info->utok.uid), 2603 lp_printername(snum) ); 2604 /* END_ADMIN_LOG */ 2427 !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum, 2428 JOB_ACCESS_ADMINISTER))) { 2429 DEBUG(0, ("print job resume denied." 2430 "User name: %s, Printer name: %s.", 2431 uidtoname(server_info->unix_token->uid), 2432 lp_printername(tmp_ctx, snum))); 2433 2605 2434 werr = WERR_ACCESS_DENIED; 2606 2435 goto err_out; … … 2634 2463 ssize_t print_job_write(struct tevent_context *ev, 2635 2464 struct messaging_context *msg_ctx, 2636 int snum, uint32 jobid, const char *buf, size_t size)2465 int snum, uint32_t jobid, const char *buf, size_t size) 2637 2466 { 2638 2467 const char* sharename = lp_const_servicename(snum); … … 2651 2480 2652 2481 /* don't allow another process to get this info - it is meaningless */ 2653 if (pjob->pid != sys_getpid()) {2482 if (pjob->pid != getpid()) { 2654 2483 return_code = -1; 2655 2484 goto err_out; … … 2738 2567 2739 2568 static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum, 2740 const char *sharename, uint32 *pjobid)2569 const char *sharename, uint32_t *pjobid) 2741 2570 { 2742 2571 int i; 2743 uint32 jobid;2572 uint32_t jobid; 2744 2573 enum TDB_ERROR terr; 2745 2574 int ret; 2746 2575 2747 *pjobid = (uint32 )-1;2576 *pjobid = (uint32_t)-1; 2748 2577 2749 2578 for (i = 0; i < 3; i++) { … … 2751 2580 ret = tdb_lock_bystring_with_timeout(pdb->tdb, 2752 2581 "INFO/nextjob", 20); 2753 if (ret == -1) {2582 if (ret != 0) { 2754 2583 DEBUG(0, ("allocate_print_jobid: " 2755 2584 "Failed to lock printing database %s\n", … … 2779 2608 2780 2609 ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid); 2781 if (ret == -1) {2610 if (ret != 0) { 2782 2611 terr = tdb_error(pdb->tdb); 2783 2612 DEBUG(3, ("allocate_print_jobid: " … … 2812 2641 dum.dsize = 0; 2813 2642 if (tdb_store(pdb->tdb, print_key(jobid, &tmp), dum, 2814 TDB_INSERT) == -1) {2643 TDB_INSERT) != 0) { 2815 2644 DEBUG(3, ("allocate_print_jobid: " 2816 2645 "jobid (%d) failed to store placeholder.\n", … … 2829 2658 ***************************************************************************/ 2830 2659 2831 static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32 jobid)2660 static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32_t jobid) 2832 2661 { 2833 2662 TDB_DATA data; 2834 uint32 store_jobid;2663 uint32_t store_jobid; 2835 2664 2836 2665 SIVAL(&store_jobid, 0, jobid); 2837 data.dptr = (uint8 *)&store_jobid;2666 data.dptr = (uint8_t *)&store_jobid; 2838 2667 data.dsize = 4; 2839 2668 … … 2849 2678 ***************************************************************************/ 2850 2679 2851 static WERROR print_job_checks(const struct auth_se rversupplied_info *server_info,2680 static WERROR print_job_checks(const struct auth_session_info *server_info, 2852 2681 struct messaging_context *msg_ctx, 2853 2682 int snum, int *njobs) … … 2858 2687 int ret; 2859 2688 2860 if (! print_access_check(server_info, msg_ctx, snum,2861 PRINTER_ACCESS_USE)) {2689 if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum, 2690 PRINTER_ACCESS_USE))) { 2862 2691 DEBUG(3, ("print_job_checks: " 2863 2692 "job start denied by security descriptor\n")); … … 2872 2701 2873 2702 /* see if we have sufficient disk space */ 2874 if (lp_min printspace(snum)) {2875 minspace = lp_min printspace(snum);2876 ret = sys_fsusage(lp_path name(snum), &dspace, &dsize);2703 if (lp_min_print_space(snum)) { 2704 minspace = lp_min_print_space(snum); 2705 ret = sys_fsusage(lp_path(talloc_tos(), snum), &dspace, &dsize); 2877 2706 if (ret == 0 && dspace < 2*minspace) { 2878 2707 DEBUG(3, ("print_job_checks: " … … 2913 2742 const char *path; 2914 2743 int len; 2744 mode_t mask; 2915 2745 2916 2746 /* if this file is within the printer path, it means that smbd … … 2919 2749 * already already there */ 2920 2750 if (output_file) { 2921 path = lp_path name(snum);2751 path = lp_path(talloc_tos(), snum); 2922 2752 len = strlen(path); 2923 2753 if (strncmp(output_file, path, len) == 0 && … … 2937 2767 2938 2768 DEBUG(3, ("print_job_spool_file:" 2939 "External spooling activated "));2769 "External spooling activated\n")); 2940 2770 2941 2771 /* we do not open the file until spooling is done */ … … 2948 2778 2949 2779 slprintf(pjob->filename, sizeof(pjob->filename)-1, 2950 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX); 2780 "%s/%sXXXXXX", lp_path(talloc_tos(), snum), 2781 PRINT_SPOOL_PREFIX); 2782 mask = umask(S_IRWXO | S_IRWXG); 2951 2783 pjob->fd = mkstemp(pjob->filename); 2784 umask(mask); 2952 2785 2953 2786 if (pjob->fd == -1) { … … 2974 2807 ***************************************************************************/ 2975 2808 2976 WERROR print_job_start(const struct auth_se rversupplied_info *server_info,2809 WERROR print_job_start(const struct auth_session_info *server_info, 2977 2810 struct messaging_context *msg_ctx, 2978 2811 const char *clientmachine, … … 2992 2825 } 2993 2826 2994 path = lp_path name(snum);2827 path = lp_path(talloc_tos(), snum); 2995 2828 2996 2829 werr = print_job_checks(server_info, msg_ctx, snum, &njobs); … … 3013 2846 ZERO_STRUCT(pjob); 3014 2847 3015 pjob.pid = sys_getpid();2848 pjob.pid = getpid(); 3016 2849 pjob.jobid = jobid; 3017 2850 pjob.sysjob = -1; … … 3029 2862 3030 2863 fstrcpy(pjob.user, lp_printjob_username(snum)); 3031 standard_sub_advanced(sharename, server_info->sanitized_username, 3032 path, server_info->utok.gid, 3033 server_info->sanitized_username, 3034 server_info->info3->base.domain.string, 3035 pjob.user, sizeof(pjob.user)-1); 3036 /* ensure NULL termination */ 3037 pjob.user[sizeof(pjob.user)-1] = '\0'; 2864 standard_sub_advanced(sharename, server_info->unix_info->sanitized_username, 2865 path, server_info->unix_token->gid, 2866 server_info->unix_info->sanitized_username, 2867 server_info->info->domain_name, 2868 pjob.user, sizeof(pjob.user)); 3038 2869 3039 2870 fstrcpy(pjob.queuename, lp_const_servicename(snum)); … … 3075 2906 3076 2907 void print_job_endpage(struct messaging_context *msg_ctx, 3077 int snum, uint32 jobid)2908 int snum, uint32_t jobid) 3078 2909 { 3079 2910 const char* sharename = lp_const_servicename(snum); … … 3089 2920 } 3090 2921 /* don't allow another process to get this info - it is meaningless */ 3091 if (pjob->pid != sys_getpid()) {2922 if (pjob->pid != getpid()) { 3092 2923 goto err_out; 3093 2924 } … … 3106 2937 3107 2938 NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum, 3108 uint32 jobid, enum file_close_type close_type)2939 uint32_t jobid, enum file_close_type close_type) 3109 2940 { 3110 2941 const char* sharename = lp_const_servicename(snum); … … 3126 2957 } 3127 2958 3128 if (pjob->spooled || pjob->pid != sys_getpid()) {2959 if (pjob->spooled || pjob->pid != getpid()) { 3129 2960 status = NT_STATUS_ACCESS_DENIED; 3130 2961 goto err_out; … … 3184 3015 /* don't strip out characters like '$' from the printername */ 3185 3016 lpq_cmd = talloc_string_sub2(tmp_ctx, 3186 lp_lpq command(snum),3017 lp_lpq_command(talloc_tos(), snum), 3187 3018 "%p", 3188 lp_printername( snum),3019 lp_printername(talloc_tos(), snum), 3189 3020 false, false, false); 3190 3021 if (lpq_cmd == NULL) { … … 3193 3024 } 3194 3025 lpq_cmd = talloc_sub_advanced(tmp_ctx, 3195 lp_servicename( snum),3026 lp_servicename(talloc_tos(), snum), 3196 3027 current_user_info.unix_name, 3197 3028 "", … … 3246 3077 TDB_DATA data, cgdata, jcdata; 3247 3078 print_queue_struct *queue = NULL; 3248 uint32 qcount = 0;3249 uint32 extra_count = 0;3079 uint32_t qcount = 0; 3080 uint32_t extra_count = 0; 3250 3081 uint32_t changed_count = 0; 3251 3082 int total_count = 0; 3252 3083 size_t len = 0; 3253 uint32 i;3254 int max_reported_jobs = lp_max_reported_ jobs(snum);3255 bool ret = False;3256 const char* sharename = lp_servicename( snum);3084 uint32_t i; 3085 int max_reported_jobs = lp_max_reported_print_jobs(snum); 3086 bool ret = false; 3087 const char* sharename = lp_servicename(talloc_tos(), snum); 3257 3088 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3258 3089 if (tmp_ctx == NULL) { … … 3297 3128 /* Retrieve the linearised queue data. */ 3298 3129 3299 for( i= 0; i < qcount; i++) {3300 uint32 qjob, qsize, qpage_count, qstatus, qpriority, qtime;3130 for(i = 0; i < qcount; i++) { 3131 uint32_t qjob, qsize, qpage_count, qstatus, qpriority, qtime; 3301 3132 len += tdb_unpack(data.dptr + len, data.dsize - len, "ddddddff", 3302 3133 &qjob, … … 3319 3150 3320 3151 /* Add new jobids to the queue. */ 3321 for ( i= 0; i < extra_count; i++) {3322 uint32 jobid;3152 for (i = 0; i < extra_count; i++) { 3153 uint32_t jobid; 3323 3154 struct printjob *pjob; 3324 3155 … … 3332 3163 } 3333 3164 3334 queue[total_count].sysjob = jobid;3165 queue[total_count].sysjob = pjob->sysjob; 3335 3166 queue[total_count].size = pjob->size; 3336 3167 queue[total_count].page_count = pjob->page_count; … … 3347 3178 for (i = 0; i < changed_count; i++) { 3348 3179 uint32_t jobid = IVAL(jcdata.dptr, i * 4); 3180 struct printjob *pjob; 3349 3181 uint32_t j; 3350 3182 bool found = false; 3351 3183 3184 pjob = print_job_find(tmp_ctx, sharename, jobid); 3185 if (pjob == NULL) { 3186 DEBUG(5,("get_stored_queue_info: failed to find " 3187 "changed job = %u\n", 3188 (unsigned int)jobid)); 3189 remove_from_jobs_changed(sharename, jobid); 3190 continue; 3191 } 3192 3352 3193 for (j = 0; j < total_count; j++) { 3353 if (queue[j].sysjob == jobid) {3194 if (queue[j].sysjob == pjob->sysjob) { 3354 3195 found = true; 3355 3196 break; … … 3358 3199 3359 3200 if (found) { 3360 struct printjob *pjob;3361 3362 3201 DEBUG(5,("get_stored_queue_info: changed job: %u\n", 3363 (unsigned int) jobid)); 3364 3365 pjob = print_job_find(tmp_ctx, sharename, jobid); 3366 if (pjob == NULL) { 3367 DEBUG(5,("get_stored_queue_info: failed to find " 3368 "changed job = %u\n", 3369 (unsigned int) jobid)); 3370 remove_from_jobs_changed(sharename, jobid); 3371 continue; 3372 } 3373 3374 queue[j].sysjob = jobid; 3202 (unsigned int)jobid)); 3203 3204 queue[j].sysjob = pjob->sysjob; 3375 3205 queue[j].size = pjob->size; 3376 3206 queue[j].page_count = pjob->page_count; … … 3382 3212 talloc_free(pjob); 3383 3213 3384 DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n", 3385 (unsigned int) j, (unsigned int) jobid, pjob->jobname)); 3214 DEBUG(5,("updated queue[%u], jobid: %u, sysjob: %u, " 3215 "jobname: %s\n", 3216 (unsigned int)j, (unsigned int)jobid, 3217 (unsigned int)queue[j].sysjob, pjob->jobname)); 3386 3218 } 3387 3219 … … 3402 3234 *pcount = total_count; 3403 3235 3404 ret = True;3236 ret = true; 3405 3237 3406 3238 out: … … 3480 3312 ****************************************************************************/ 3481 3313 3482 WERROR print_queue_pause(const struct auth_se rversupplied_info *server_info,3314 WERROR print_queue_pause(const struct auth_session_info *server_info, 3483 3315 struct messaging_context *msg_ctx, int snum) 3484 3316 { … … 3486 3318 struct printif *current_printif = get_printer_fns( snum ); 3487 3319 3488 if (! print_access_check(server_info, msg_ctx, snum,3489 PRINTER_ACCESS_ADMINISTER)) {3320 if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum, 3321 PRINTER_ACCESS_ADMINISTER))) { 3490 3322 return WERR_ACCESS_DENIED; 3491 3323 } … … 3517 3349 ****************************************************************************/ 3518 3350 3519 WERROR print_queue_resume(const struct auth_se rversupplied_info *server_info,3351 WERROR print_queue_resume(const struct auth_session_info *server_info, 3520 3352 struct messaging_context *msg_ctx, int snum) 3521 3353 { … … 3523 3355 struct printif *current_printif = get_printer_fns( snum ); 3524 3356 3525 if (! print_access_check(server_info, msg_ctx, snum,3526 PRINTER_ACCESS_ADMINISTER)) {3357 if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum, 3358 PRINTER_ACCESS_ADMINISTER))) { 3527 3359 return WERR_ACCESS_DENIED; 3528 3360 } … … 3554 3386 ****************************************************************************/ 3555 3387 3556 WERROR print_queue_purge(const struct auth_se rversupplied_info *server_info,3388 WERROR print_queue_purge(const struct auth_session_info *server_info, 3557 3389 struct messaging_context *msg_ctx, int snum) 3558 3390 { … … 3565 3397 print_queue_update(msg_ctx, snum, True); 3566 3398 3567 can_job_admin = print_access_check(server_info,3568 3569 3570 JOB_ACCESS_ADMINISTER);3399 can_job_admin = W_ERROR_IS_OK(print_access_check(server_info, 3400 msg_ctx, 3401 snum, 3402 JOB_ACCESS_ADMINISTER)); 3571 3403 njobs = print_queue_status(msg_ctx, snum, &queue, &status); 3572 3404 … … 3574 3406 become_root(); 3575 3407 3576 for (i=0;i<njobs;i++) { 3577 bool owner = is_owner(server_info, lp_const_servicename(snum), 3578 queue[i].sysjob); 3408 for (i = 0; i < njobs; i++) { 3409 struct tdb_print_db *pdb; 3410 int jobid; 3411 bool owner; 3412 pdb = get_print_db_byname(lp_const_servicename(snum)); 3413 if (pdb == NULL) { 3414 DEBUG(1, ("failed to find printdb for %s\n", 3415 lp_const_servicename(snum))); 3416 continue; 3417 } 3418 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob); 3419 if (jobid == (uint32_t)-1) { 3420 DEBUG(2, ("jobid for system job %d not found\n", 3421 queue[i].sysjob)); 3422 continue; /* unix job */ 3423 } 3424 owner = is_owner(server_info, lp_const_servicename(snum), 3425 jobid); 3579 3426 3580 3427 if (owner || can_job_admin) { 3581 3428 print_job_delete1(server_event_context(), msg_ctx, 3582 snum, queue[i].sysjob);3429 snum, jobid); 3583 3430 } 3584 3431 } -
vendor/current/source3/printing/printing_db.c
r740 r988 21 21 22 22 #include "includes.h" 23 #include "system/passwd.h" /* uid_wrapper */ 23 24 #include "system/filesys.h" 24 25 #include "printing.h" … … 38 39 char *printdb_path = NULL; 39 40 bool done_become_root = False; 41 char *print_cache_path; 42 int ret; 40 43 41 44 SMB_ASSERT(printername != NULL); … … 65 68 continue; 66 69 if (p->tdb) { 67 if (tdb_close(p rint_db_head->tdb)) {70 if (tdb_close(p->tdb)) { 68 71 DEBUG(0,("get_print_db: Failed to close tdb for printer %s\n", 69 p rint_db_head->printer_name ));72 p->printer_name )); 70 73 return NULL; 71 74 } … … 93 96 } 94 97 95 if (asprintf(&printdb_path, "%s%s.tdb", 96 cache_path("printing/"), 97 printername) < 0) { 98 print_cache_path = cache_path("printing/"); 99 if (print_cache_path == NULL) { 100 DLIST_REMOVE(print_db_head, p); 101 SAFE_FREE(p); 102 return NULL; 103 } 104 ret = asprintf(&printdb_path, "%s%s.tdb", 105 print_cache_path, printername); 106 TALLOC_FREE(print_cache_path); 107 if (ret < 0) { 98 108 DLIST_REMOVE(print_db_head, p); 99 109 SAFE_FREE(p); … … 161 171 ****************************************************************************/ 162 172 163 structTDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist)173 TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist) 164 174 { 165 175 TDB_DATA data; … … 193 203 pid_t pid = (pid_t)IVAL(data.dptr, i); 194 204 195 if (pid == sys_getpid())205 if (pid == getpid()) 196 206 continue; 197 207 -
vendor/current/source3/printing/printspoolss.c
r746 r988 19 19 20 20 #include "includes.h" 21 #include "system/filesys.h" 21 22 #include "printing.h" 22 23 #include "rpc_client/rpc_client.h" … … 26 27 #include "../libcli/security/security.h" 27 28 29 struct print_file_data { 30 char *svcname; 31 char *docname; 32 char *filename; 33 struct policy_handle handle; 34 uint32_t jobid; 35 uint16_t rap_jobid; 36 }; 37 38 uint16_t print_spool_rap_jobid(struct print_file_data *print_file) 39 { 40 if (print_file == NULL) { 41 return 0; 42 } 43 44 return print_file->rap_jobid; 45 } 46 28 47 void print_spool_terminate(struct connection_struct *conn, 29 48 struct print_file_data *print_file); … … 40 59 NTSTATUS print_spool_open(files_struct *fsp, 41 60 const char *fname, 42 uint 16_t current_vuid)61 uint64_t current_vuid) 43 62 { 44 63 NTSTATUS status; … … 47 66 struct dcerpc_binding_handle *b = NULL; 48 67 struct spoolss_DevmodeContainer devmode_ctr; 49 union spoolss_DocumentInfo info; 68 struct spoolss_DocumentInfoCtr info_ctr; 69 struct spoolss_DocumentInfo1 *info1; 50 70 int fd = -1; 51 71 WERROR werr; 72 mode_t mask; 52 73 53 74 tmp_ctx = talloc_new(fsp); … … 61 82 goto done; 62 83 } 63 pf->svcname = talloc_strdup(pf, lp_servicename(SNUM(fsp->conn)));84 pf->svcname = lp_servicename(pf, SNUM(fsp->conn)); 64 85 65 86 /* the document name is derived from the file name. … … 101 122 102 123 pf->filename = talloc_asprintf(pf, "%s/%sXXXXXX", 103 lp_pathname(SNUM(fsp->conn)), 124 lp_path(talloc_tos(), 125 SNUM(fsp->conn)), 104 126 PRINT_SPOOL_PREFIX); 105 127 if (!pf->filename) { … … 108 130 } 109 131 errno = 0; 132 mask = umask(S_IRWXO | S_IRWXG); 110 133 fd = mkstemp(pf->filename); 134 umask(mask); 111 135 if (fd == -1) { 112 136 if (errno == EACCES) { … … 131 155 132 156 status = rpc_pipe_open_interface(fsp->conn, 133 &ndr_table_spoolss .syntax_id,157 &ndr_table_spoolss, 134 158 fsp->conn->session_info, 135 &fsp->conn->sconn->client_id,159 fsp->conn->sconn->remote_address, 136 160 fsp->conn->sconn->msg_ctx, 137 161 &fsp->conn->spoolss_pipe); … … 155 179 } 156 180 157 info.info1 = talloc(tmp_ctx, struct spoolss_DocumentInfo1); 158 if (!info.info1) { 159 status = NT_STATUS_NO_MEMORY; 160 goto done; 161 } 162 info.info1->document_name = pf->docname; 163 info.info1->output_file = pf->filename; 164 info.info1->datatype = "RAW"; 165 166 status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx, &pf->handle, 167 1, info, &pf->jobid, &werr); 181 info1 = talloc(tmp_ctx, struct spoolss_DocumentInfo1); 182 if (info1 == NULL) { 183 status = NT_STATUS_NO_MEMORY; 184 goto done; 185 } 186 info1->document_name = pf->docname; 187 info1->output_file = pf->filename; 188 info1->datatype = "RAW"; 189 190 info_ctr.level = 1; 191 info_ctr.info.info1 = info1; 192 193 status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx, 194 &pf->handle, 195 &info_ctr, 196 &pf->jobid, 197 &werr); 168 198 if (!NT_STATUS_IS_OK(status)) { 169 199 goto done; … … 183 213 184 214 /* setup a full fsp */ 185 status = create_synthetic_smb_fname(fsp, pf->filename, NULL,186 NULL, &fsp->fsp_name);187 if (!NT_STATUS_IS_OK(status)) {215 fsp->fsp_name = synthetic_smb_fname(fsp, pf->filename, NULL, NULL); 216 if (fsp->fsp_name == NULL) { 217 status = NT_STATUS_NO_MEMORY; 188 218 goto done; 189 219 } … … 195 225 196 226 fsp->file_id = vfs_file_id_from_sbuf(fsp->conn, &fsp->fsp_name->st); 197 fsp->mode = fsp->fsp_name->st.st_ex_mode;198 227 fsp->fh->fd = fd; 199 228 … … 220 249 } 221 250 /* We need to delete the job from spoolss too */ 222 if (pf ->jobid) {251 if (pf && pf->jobid) { 223 252 print_spool_terminate(fsp->conn, pf); 224 253 } … … 230 259 int print_spool_write(files_struct *fsp, 231 260 const char *data, uint32_t size, 232 SMB_OFF_Toffset, uint32_t *written)261 off_t offset, uint32_t *written) 233 262 { 234 263 SMB_STRUCT_STAT st; … … 315 344 316 345 status = rpc_pipe_open_interface(conn, 317 &ndr_table_spoolss .syntax_id,346 &ndr_table_spoolss, 318 347 conn->session_info, 319 &conn->sconn->client_id,348 conn->sconn->remote_address, 320 349 conn->sconn->msg_ctx, 321 350 &conn->spoolss_pipe); -
vendor/current/source3/printing/spoolssd.c
r860 r988 2 2 Unix SMB/Netbios implementation. 3 3 SPOOLSS Daemon 4 Copyright (C) Simo Sorce 20104 Copyright (C) Simo Sorce <idra@samba.org> 2010-2011 5 5 6 6 This program is free software; you can redistribute it and/or modify … … 24 24 #include "include/printing.h" 25 25 #include "printing/nt_printing_migrate_internal.h" 26 #include "printing/queue_process.h" 27 #include "printing/pcap.h" 28 #include "printing/load.h" 26 29 #include "ntdomain.h" 27 30 #include "librpc/gen_ndr/srv_winreg.h" 28 31 #include "librpc/gen_ndr/srv_spoolss.h" 29 32 #include "rpc_server/rpc_server.h" 30 #include "rpc_server/rpc_ep_setup.h" 33 #include "rpc_server/rpc_ep_register.h" 34 #include "rpc_server/rpc_config.h" 31 35 #include "rpc_server/spoolss/srv_spoolss_nt.h" 36 #include "librpc/rpc/dcerpc_ep.h" 37 #include "lib/server_prefork.h" 38 #include "lib/server_prefork_util.h" 32 39 33 40 #define SPOOLSS_PIPE_NAME "spoolss" 34 41 #define DAEMON_NAME "spoolssd" 35 42 36 void start_spoolssd(struct tevent_context *ev_ctx, 37 struct messaging_context *msg_ctx); 38 39 static void spoolss_reopen_logs(void) 40 { 41 char *lfile = lp_logfile(); 43 static struct server_id parent_id; 44 static struct prefork_pool *spoolss_pool = NULL; 45 static int spoolss_child_id = 0; 46 47 static struct pf_daemon_config default_pf_spoolss_cfg = { 48 .prefork_status = PFH_INIT, 49 .min_children = 5, 50 .max_children = 25, 51 .spawn_rate = 5, 52 .max_allowed_clients = 100, 53 .child_min_life = 60 /* 1 minute minimum life time */ 54 }; 55 static struct pf_daemon_config pf_spoolss_cfg = { 0 }; 56 57 pid_t start_spoolssd(struct tevent_context *ev_ctx, 58 struct messaging_context *msg_ctx); 59 60 static void spoolss_reopen_logs(int child_id) 61 { 62 char *lfile = lp_logfile(talloc_tos()); 63 char *ext; 42 64 int rc; 43 65 66 if (child_id) { 67 rc = asprintf(&ext, "%s.%d", DAEMON_NAME, child_id); 68 } else { 69 rc = asprintf(&ext, "%s", DAEMON_NAME); 70 } 71 72 if (rc == -1) { 73 return; 74 } 75 76 rc = 0; 44 77 if (lfile == NULL || lfile[0] == '\0') { 45 rc = asprintf(&lfile, "%s/log.%s", get_dyn_LOGFILEBASE(), DAEMON_NAME); 46 if (rc > 0) { 47 lp_set_logfile(lfile); 48 SAFE_FREE(lfile); 49 } 78 rc = asprintf(&lfile, "%s/log.%s", 79 get_dyn_LOGFILEBASE(), ext); 50 80 } else { 51 if (strstr(lfile, DAEMON_NAME) == NULL) { 52 rc = asprintf(&lfile, "%s.%s", lp_logfile(), DAEMON_NAME); 53 if (rc > 0) { 54 lp_set_logfile(lfile); 55 SAFE_FREE(lfile); 81 if (strstr(lfile, ext) == NULL) { 82 if (child_id) { 83 rc = asprintf(&lfile, "%s.%d", 84 lp_logfile(talloc_tos()), 85 child_id); 86 } else { 87 rc = asprintf(&lfile, "%s.%s", 88 lp_logfile(talloc_tos()), 89 ext); 56 90 } 57 91 } 58 92 } 59 93 94 if (rc > 0) { 95 lp_set_logfile(lfile); 96 SAFE_FREE(lfile); 97 } 98 99 SAFE_FREE(ext); 100 60 101 reopen_logs(); 102 } 103 104 static void update_conf(struct tevent_context *ev, 105 struct messaging_context *msg) 106 { 107 change_to_root_user(); 108 lp_load_global(get_dyn_CONFIGFILE()); 109 load_printers(ev, msg); 110 111 spoolss_reopen_logs(spoolss_child_id); 112 if (spoolss_child_id == 0) { 113 pfh_daemon_config(DAEMON_NAME, 114 &pf_spoolss_cfg, 115 &default_pf_spoolss_cfg); 116 pfh_manage_pool(ev, msg, &pf_spoolss_cfg, spoolss_pool); 117 } 61 118 } 62 119 … … 71 128 72 129 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n")); 73 change_to_root_user(); 74 spoolss_reopen_logs(); 75 } 76 77 static void spoolss_pcap_updated(struct messaging_context *msg, 78 void *private_data, 79 uint32_t msg_type, 80 struct server_id server_id, 81 DATA_BLOB *data) 82 { 83 struct tevent_context *ev_ctx = talloc_get_type_abort(private_data, 84 struct tevent_context); 85 86 DEBUG(10, ("Got message saying pcap was updated. Reloading.\n")); 87 change_to_root_user(); 88 reload_printers(ev_ctx, msg); 130 update_conf(ev_ctx, msg); 89 131 } 90 132 … … 118 160 int count, 119 161 void *siginfo, 120 void *p rivate_data)121 { 122 struct messaging_context *msg_ctx = talloc_get_type_abort(private_data,123 struct messaging_context); 124 125 change_to_root_user(); 162 void *pvt) 163 { 164 struct messaging_context *msg_ctx; 165 166 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context); 167 126 168 DEBUG(1,("Reloading printers after SIGHUP\n")); 127 spoolss_reopen_logs(); 169 update_conf(ev, msg_ctx); 170 171 /* relay to all children */ 172 if (spoolss_pool) { 173 prefork_send_signal_to_all(spoolss_pool, SIGHUP); 174 } 128 175 } 129 176 … … 158 205 } 159 206 160 void start_spoolssd(struct tevent_context *ev_ctx, 161 struct messaging_context *msg_ctx) 162 { 207 /* Children */ 208 209 static void spoolss_chld_sig_hup_handler(struct tevent_context *ev, 210 struct tevent_signal *se, 211 int signum, 212 int count, 213 void *siginfo, 214 void *pvt) 215 { 216 struct messaging_context *msg_ctx; 217 218 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context); 219 220 change_to_root_user(); 221 DEBUG(1,("Reloading printers after SIGHUP\n")); 222 load_printers(ev, msg_ctx); 223 spoolss_reopen_logs(spoolss_child_id); 224 } 225 226 static bool spoolss_setup_chld_hup_handler(struct tevent_context *ev_ctx, 227 struct messaging_context *msg_ctx, 228 struct pf_worker_data *pf) 229 { 230 struct tevent_signal *se; 231 232 se = tevent_add_signal(ev_ctx, 233 ev_ctx, 234 SIGHUP, 0, 235 spoolss_chld_sig_hup_handler, 236 msg_ctx); 237 if (!se) { 238 DEBUG(1, ("failed to setup SIGHUP handler")); 239 return false; 240 } 241 242 return true; 243 } 244 245 static void parent_ping(struct messaging_context *msg_ctx, 246 void *private_data, 247 uint32_t msg_type, 248 struct server_id server_id, 249 DATA_BLOB *data) 250 { 251 252 /* The fact we received this message is enough to let make the event 253 * loop if it was idle. spoolss_children_main will cycle through 254 * spoolss_next_client at least once. That function will take whatever 255 * action is necessary */ 256 257 DEBUG(10, ("Got message that the parent changed status.\n")); 258 return; 259 } 260 261 static bool spoolss_child_init(struct tevent_context *ev_ctx, 262 int child_id, struct pf_worker_data *pf) 263 { 264 NTSTATUS status; 163 265 struct rpc_srv_callbacks spoolss_cb; 164 pid_t pid; 165 NTSTATUS status; 166 int ret; 167 168 DEBUG(1, ("Forking SPOOLSS Daemon\n")); 169 170 pid = sys_fork(); 171 172 if (pid == -1) { 173 DEBUG(0, ("Failed to fork SPOOLSS [%s], aborting ...\n", 174 strerror(errno))); 175 exit(1); 176 } 177 178 if (pid) { 179 /* parent */ 180 return; 181 } 182 183 /* child */ 184 close_low_fds(false); 185 186 status = reinit_after_fork(msg_ctx, 187 ev_ctx, 188 procid_self(), true); 266 struct messaging_context *msg_ctx = server_messaging_context(); 267 bool ok; 268 269 status = reinit_after_fork(msg_ctx, ev_ctx, true, "spoolssd-child"); 189 270 if (!NT_STATUS_IS_OK(status)) { 190 271 DEBUG(0,("reinit_after_fork() failed\n")); … … 192 273 } 193 274 194 spoolss_reopen_logs(); 195 196 spoolss_setup_sig_term_handler(ev_ctx); 197 spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx); 198 199 if (!serverid_register(procid_self(), 200 FLAG_MSG_GENERAL|FLAG_MSG_SMBD 201 |FLAG_MSG_PRINT_GENERAL)) { 202 exit(1); 275 spoolss_child_id = child_id; 276 spoolss_reopen_logs(child_id); 277 278 ok = spoolss_setup_chld_hup_handler(ev_ctx, msg_ctx, pf); 279 if (!ok) { 280 return false; 281 } 282 283 if (!serverid_register(messaging_server_id(msg_ctx), 284 FLAG_MSG_GENERAL | 285 FLAG_MSG_PRINT_GENERAL)) { 286 return false; 203 287 } 204 288 205 289 if (!locking_init()) { 206 exit(1); 207 } 208 209 messaging_register(msg_ctx, NULL, 210 MSG_PRINTER_UPDATE, print_queue_receive); 290 return false; 291 } 292 211 293 messaging_register(msg_ctx, ev_ctx, 212 294 MSG_SMB_CONF_UPDATED, smb_conf_updated); 213 295 messaging_register(msg_ctx, ev_ctx, 214 MSG_PRINTER_PCAP, spoolss_pcap_updated); 296 MSG_PREFORK_PARENT_EVENT, parent_ping); 297 298 /* As soon as messaging is up check if pcap has been loaded already. 299 * If so then we probably missed a message and should load_printers() 300 * ourselves. If pcap has not been loaded yet, then ignore, we will get 301 * a message as soon as the bq process completes the reload. */ 302 if (pcap_cache_loaded(NULL)) { 303 load_printers(ev_ctx, msg_ctx); 304 } 305 306 /* try to reinit rpc queues */ 307 spoolss_cb.init = spoolss_init_cb; 308 spoolss_cb.shutdown = spoolss_shutdown_cb; 309 spoolss_cb.private_data = msg_ctx; 310 311 status = rpc_winreg_init(NULL); 312 if (!NT_STATUS_IS_OK(status)) { 313 DEBUG(0, ("Failed to register winreg rpc interface! (%s)\n", 314 nt_errstr(status))); 315 return false; 316 } 317 318 status = rpc_spoolss_init(&spoolss_cb); 319 if (!NT_STATUS_IS_OK(status)) { 320 DEBUG(0, ("Failed to register spoolss rpc interface! (%s)\n", 321 nt_errstr(status))); 322 return false; 323 } 324 325 return true; 326 } 327 328 struct spoolss_children_data { 329 struct tevent_context *ev_ctx; 330 struct messaging_context *msg_ctx; 331 struct pf_worker_data *pf; 332 int listen_fd_size; 333 int *listen_fds; 334 }; 335 336 static void spoolss_next_client(void *pvt); 337 338 static int spoolss_children_main(struct tevent_context *ev_ctx, 339 struct messaging_context *msg_ctx, 340 struct pf_worker_data *pf, 341 int child_id, 342 int listen_fd_size, 343 int *listen_fds, 344 void *private_data) 345 { 346 struct spoolss_children_data *data; 347 bool ok; 348 int ret = 0; 349 350 ok = spoolss_child_init(ev_ctx, child_id, pf); 351 if (!ok) { 352 return 1; 353 } 354 355 data = talloc(ev_ctx, struct spoolss_children_data); 356 if (!data) { 357 return 1; 358 } 359 data->pf = pf; 360 data->ev_ctx = ev_ctx; 361 data->msg_ctx = msg_ctx; 362 data->listen_fd_size = listen_fd_size; 363 data->listen_fds = listen_fds; 364 365 /* loop until it is time to exit */ 366 while (pf->status != PF_WORKER_EXITING) { 367 /* try to see if it is time to schedule the next client */ 368 spoolss_next_client(data); 369 370 ret = tevent_loop_once(ev_ctx); 371 if (ret != 0) { 372 DEBUG(0, ("tevent_loop_once() exited with %d: %s\n", 373 ret, strerror(errno))); 374 pf->status = PF_WORKER_EXITING; 375 } 376 } 377 378 return ret; 379 } 380 381 static void spoolss_client_terminated(void *pvt) 382 { 383 struct spoolss_children_data *data; 384 385 data = talloc_get_type_abort(pvt, struct spoolss_children_data); 386 387 pfh_client_terminated(data->pf); 388 389 spoolss_next_client(pvt); 390 } 391 392 struct spoolss_new_client { 393 struct spoolss_children_data *data; 394 struct tsocket_address *srv_addr; 395 struct tsocket_address *cli_addr; 396 }; 397 398 static void spoolss_handle_client(struct tevent_req *req); 399 400 static void spoolss_next_client(void *pvt) 401 { 402 struct tevent_req *req; 403 struct spoolss_children_data *data; 404 struct spoolss_new_client *next; 405 406 data = talloc_get_type_abort(pvt, struct spoolss_children_data); 407 408 if (!pfh_child_allowed_to_accept(data->pf)) { 409 /* nothing to do for now we are already listening 410 * or we are not allowed to listen further */ 411 return; 412 } 413 414 next = talloc_zero(data, struct spoolss_new_client); 415 if (!next) { 416 DEBUG(1, ("Out of memory!?\n")); 417 return; 418 } 419 next->data = data; 420 421 req = prefork_listen_send(next, data->ev_ctx, data->pf, 422 data->listen_fd_size, 423 data->listen_fds); 424 if (!req) { 425 DEBUG(1, ("Failed to make listening request!?\n")); 426 talloc_free(next); 427 return; 428 } 429 tevent_req_set_callback(req, spoolss_handle_client, next); 430 } 431 432 static void spoolss_handle_client(struct tevent_req *req) 433 { 434 struct spoolss_children_data *data; 435 struct spoolss_new_client *client; 436 const DATA_BLOB ping = data_blob_null; 437 int ret; 438 int sd; 439 440 client = tevent_req_callback_data(req, struct spoolss_new_client); 441 data = client->data; 442 443 ret = prefork_listen_recv(req, client, &sd, 444 &client->srv_addr, &client->cli_addr); 445 446 /* this will free the request too */ 447 talloc_free(client); 448 449 if (ret != 0) { 450 DEBUG(6, ("No client connection was available after all!\n")); 451 return; 452 } 453 454 /* Warn parent that our status changed */ 455 messaging_send(data->msg_ctx, parent_id, 456 MSG_PREFORK_CHILD_EVENT, &ping); 457 458 DEBUG(2, ("Spoolss preforked child %d got client connection!\n", 459 (int)(data->pf->pid))); 460 461 named_pipe_accept_function(data->ev_ctx, data->msg_ctx, 462 SPOOLSS_PIPE_NAME, sd, 463 spoolss_client_terminated, data); 464 } 465 466 /* ==== Main Process Functions ==== */ 467 468 extern pid_t background_lpq_updater_pid; 469 static char *bq_logfile; 470 471 static void check_updater_child(struct tevent_context *ev_ctx, 472 struct messaging_context *msg_ctx) 473 { 474 int status; 475 pid_t pid; 476 477 if (background_lpq_updater_pid == -1) { 478 return; 479 } 480 481 pid = sys_waitpid(background_lpq_updater_pid, &status, WNOHANG); 482 if (pid > 0) { 483 DEBUG(2, ("The background queue child died... Restarting!\n")); 484 pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile); 485 background_lpq_updater_pid = pid; 486 } 487 } 488 489 static void child_ping(struct messaging_context *msg_ctx, 490 void *private_data, 491 uint32_t msg_type, 492 struct server_id server_id, 493 DATA_BLOB *data) 494 { 495 struct tevent_context *ev_ctx; 496 497 ev_ctx = talloc_get_type_abort(private_data, struct tevent_context); 498 499 DEBUG(10, ("Got message that a child changed status.\n")); 500 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool); 501 } 502 503 static bool spoolssd_schedule_check(struct tevent_context *ev_ctx, 504 struct messaging_context *msg_ctx, 505 struct timeval current_time); 506 static void spoolssd_check_children(struct tevent_context *ev_ctx, 507 struct tevent_timer *te, 508 struct timeval current_time, 509 void *pvt); 510 511 static void spoolssd_sigchld_handler(struct tevent_context *ev_ctx, 512 struct prefork_pool *pfp, 513 void *pvt) 514 { 515 struct messaging_context *msg_ctx; 516 517 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context); 518 519 /* run pool management so we can fork/retire or increase 520 * the allowed connections per child based on load */ 521 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool); 522 523 /* also check if the updater child is alive and well */ 524 check_updater_child(ev_ctx, msg_ctx); 525 } 526 527 static bool spoolssd_setup_children_monitor(struct tevent_context *ev_ctx, 528 struct messaging_context *msg_ctx) 529 { 530 bool ok; 531 532 /* add our oun sigchld callback */ 533 prefork_set_sigchld_callback(spoolss_pool, 534 spoolssd_sigchld_handler, msg_ctx); 535 536 ok = spoolssd_schedule_check(ev_ctx, msg_ctx, 537 tevent_timeval_current()); 538 return ok; 539 } 540 541 static bool spoolssd_schedule_check(struct tevent_context *ev_ctx, 542 struct messaging_context *msg_ctx, 543 struct timeval current_time) 544 { 545 struct tevent_timer *te; 546 struct timeval next_event; 547 548 /* check situation again in 10 seconds */ 549 next_event = tevent_timeval_current_ofs(10, 0); 550 551 /* TODO: check when the socket becomes readable, so that children 552 * are checked only when there is some activity ? */ 553 te = tevent_add_timer(ev_ctx, spoolss_pool, next_event, 554 spoolssd_check_children, msg_ctx); 555 if (!te) { 556 DEBUG(2, ("Failed to set up children monitoring!\n")); 557 return false; 558 } 559 560 return true; 561 } 562 563 static void spoolssd_check_children(struct tevent_context *ev_ctx, 564 struct tevent_timer *te, 565 struct timeval current_time, 566 void *pvt) 567 { 568 struct messaging_context *msg_ctx; 569 570 msg_ctx = talloc_get_type_abort(pvt, struct messaging_context); 571 572 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool); 573 574 spoolssd_schedule_check(ev_ctx, msg_ctx, current_time); 575 } 576 577 static void print_queue_forward(struct messaging_context *msg, 578 void *private_data, 579 uint32_t msg_type, 580 struct server_id server_id, 581 DATA_BLOB *data) 582 { 583 messaging_send_buf(msg, pid_to_procid(background_lpq_updater_pid), 584 MSG_PRINTER_UPDATE, data->data, data->length); 585 } 586 587 static char *get_bq_logfile(void) 588 { 589 char *lfile = lp_logfile(talloc_tos()); 590 int rc; 591 592 if (lfile == NULL || lfile[0] == '\0') { 593 rc = asprintf(&lfile, "%s/log.%s.bq", 594 get_dyn_LOGFILEBASE(), DAEMON_NAME); 595 } else { 596 rc = asprintf(&lfile, "%s.bq", lp_logfile(talloc_tos())); 597 } 598 if (rc == -1) { 599 lfile = NULL; 600 } 601 return lfile; 602 } 603 604 pid_t start_spoolssd(struct tevent_context *ev_ctx, 605 struct messaging_context *msg_ctx) 606 { 607 enum rpc_service_mode_e epm_mode = rpc_epmapper_mode(); 608 struct rpc_srv_callbacks spoolss_cb; 609 struct dcerpc_binding_vector *v; 610 TALLOC_CTX *mem_ctx; 611 pid_t pid; 612 NTSTATUS status; 613 int listen_fd; 614 int ret; 615 bool ok; 616 617 DEBUG(1, ("Forking SPOOLSS Daemon\n")); 618 619 /* 620 * Block signals before forking child as it will have to 621 * set its own handlers. Child will re-enable SIGHUP as 622 * soon as the handlers are set up. 623 */ 624 BlockSignals(true, SIGTERM); 625 BlockSignals(true, SIGHUP); 626 627 pid = fork(); 628 629 if (pid == -1) { 630 DEBUG(0, ("Failed to fork SPOOLSS [%s]\n", 631 strerror(errno))); 632 } 633 634 /* parent or error */ 635 if (pid != 0) { 636 637 /* Re-enable SIGHUP before returnig */ 638 BlockSignals(false, SIGTERM); 639 BlockSignals(false, SIGHUP); 640 return pid; 641 } 642 643 status = smbd_reinit_after_fork(msg_ctx, ev_ctx, true, 644 "spoolssd-master"); 645 if (!NT_STATUS_IS_OK(status)) { 646 DEBUG(0,("reinit_after_fork() failed\n")); 647 smb_panic("reinit_after_fork() failed"); 648 } 649 650 /* save the parent process id so the children can use it later */ 651 parent_id = messaging_server_id(msg_ctx); 652 653 spoolss_reopen_logs(0); 654 pfh_daemon_config(DAEMON_NAME, 655 &pf_spoolss_cfg, 656 &default_pf_spoolss_cfg); 657 658 spoolss_setup_sig_term_handler(ev_ctx); 659 spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx); 660 661 BlockSignals(false, SIGTERM); 662 BlockSignals(false, SIGHUP); 663 664 /* always start the backgroundqueue listner in spoolssd */ 665 bq_logfile = get_bq_logfile(); 666 pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile); 667 if (pid > 0) { 668 background_lpq_updater_pid = pid; 669 } 670 671 /* the listening fd must be created before the children are actually 672 * forked out. */ 673 listen_fd = create_named_pipe_socket(SPOOLSS_PIPE_NAME); 674 if (listen_fd == -1) { 675 exit(1); 676 } 677 678 ret = listen(listen_fd, pf_spoolss_cfg.max_allowed_clients); 679 if (ret == -1) { 680 DEBUG(0, ("Failed to listen on spoolss pipe - %s\n", 681 strerror(errno))); 682 exit(1); 683 } 684 685 /* start children before any more initialization is done */ 686 ok = prefork_create_pool(ev_ctx, /* mem_ctx */ 687 ev_ctx, msg_ctx, 688 1, &listen_fd, 689 pf_spoolss_cfg.min_children, 690 pf_spoolss_cfg.max_children, 691 &spoolss_children_main, NULL, 692 &spoolss_pool); 693 if (!ok) { 694 exit(1); 695 } 696 697 if (!serverid_register(messaging_server_id(msg_ctx), 698 FLAG_MSG_GENERAL | 699 FLAG_MSG_PRINT_GENERAL)) { 700 exit(1); 701 } 702 703 if (!locking_init()) { 704 exit(1); 705 } 706 707 messaging_register(msg_ctx, ev_ctx, 708 MSG_SMB_CONF_UPDATED, smb_conf_updated); 709 messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE, 710 print_queue_forward); 711 messaging_register(msg_ctx, ev_ctx, 712 MSG_PREFORK_CHILD_EVENT, child_ping); 713 714 /* 715 * As soon as messaging is up check if pcap has been loaded already. 716 * If pcap has not been loaded yet, then ignore, as we will reload on 717 * client enumeration anyway. 718 */ 719 if (pcap_cache_loaded(NULL)) { 720 load_printers(ev_ctx, msg_ctx); 721 } 722 723 mem_ctx = talloc_new(NULL); 724 if (mem_ctx == NULL) { 725 exit(1); 726 } 215 727 216 728 /* … … 225 737 status = rpc_winreg_init(NULL); 226 738 if (!NT_STATUS_IS_OK(status)) { 227 DEBUG(0, ("Failed to register winreg rpc inte face! (%s)\n",739 DEBUG(0, ("Failed to register winreg rpc interface! (%s)\n", 228 740 nt_errstr(status))); 229 741 exit(1); … … 232 744 status = rpc_spoolss_init(&spoolss_cb); 233 745 if (!NT_STATUS_IS_OK(status)) { 234 DEBUG(0, ("Failed to register spoolss rpc inte face! (%s)\n",746 DEBUG(0, ("Failed to register spoolss rpc interface! (%s)\n", 235 747 nt_errstr(status))); 236 748 exit(1); 237 749 } 238 750 239 if (!setup_named_pipe_socket(SPOOLSS_PIPE_NAME, ev_ctx)) { 240 exit(1); 241 } 242 243 status = rpc_ep_setup_register(ev_ctx, msg_ctx, &ndr_table_spoolss, NULL, 0); 244 if (!NT_STATUS_IS_OK(status)) { 245 DEBUG(0, ("Failed to register spoolss endpoint! (%s)\n", 246 nt_errstr(status))); 247 exit(1); 248 } 249 250 DEBUG(1, ("SPOOLSS Daemon Started (%d)\n", getpid())); 751 if (epm_mode != RPC_SERVICE_MODE_DISABLED && 752 (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) { 753 status = dcerpc_binding_vector_new(mem_ctx, &v); 754 if (!NT_STATUS_IS_OK(status)) { 755 DEBUG(0, ("Failed to create binding vector (%s)\n", 756 nt_errstr(status))); 757 exit(1); 758 } 759 760 status = dcerpc_binding_vector_add_np_default(&ndr_table_spoolss, v); 761 if (!NT_STATUS_IS_OK(status)) { 762 DEBUG(0, ("Failed to add np to binding vector (%s)\n", 763 nt_errstr(status))); 764 exit(1); 765 } 766 767 status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_spoolss, v); 768 if (!NT_STATUS_IS_OK(status)) { 769 DEBUG(0, ("Failed to register spoolss endpoint! (%s)\n", 770 nt_errstr(status))); 771 exit(1); 772 } 773 } 774 775 talloc_free(mem_ctx); 776 777 ok = spoolssd_setup_children_monitor(ev_ctx, msg_ctx); 778 if (!ok) { 779 DEBUG(0, ("Failed to setup children monitoring!\n")); 780 exit(1); 781 } 782 783 DEBUG(1, ("SPOOLSS Daemon Started (%u)\n", (unsigned int)getpid())); 784 785 pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool); 251 786 252 787 /* loop forever */ … … 254 789 255 790 /* should not be reached */ 256 DEBUG(0,(" background_queue:tevent_loop_wait() exited with %d - %s\n",791 DEBUG(0,("spoolssd tevent_loop_wait() exited with %d - %s\n", 257 792 ret, (ret == 0) ? "out of events" : strerror(errno))); 258 793 exit(1); -
vendor/current/source3/printing/tests/vlp.c
r746 r988 112 112 { 113 113 fstring keystr; 114 int result;115 114 116 115 slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer); 117 result =tdb_store_int32(tdb, keystr, status);116 tdb_store_int32(tdb, keystr, status); 118 117 } 119 118 … … 395 394 } 396 395 396 /* FIXME: We should *never* open a tdb without logging! */ 397 397 if (!(tdb = tdb_open(printdb_path, 0, 0, O_RDWR | O_CREAT, 398 398 0666))) {
Note:
See TracChangeset
for help on using the changeset viewer.