Changeset 988 for vendor/current/source3/printing/printing.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.