Changeset 746 for vendor/current/source3/printing/printing.c
- Timestamp:
- Nov 27, 2012, 4:56:06 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/printing/printing.c
r740 r746 374 374 ***********************************************************************/ 375 375 376 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob ) 376 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen, 377 struct printjob *pjob) 377 378 { 378 379 int len = 0; 379 380 int used; 380 uint32 pjpid, pj sysjob, pjfd, pjstarttime, pjstatus;381 uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus; 381 382 uint32 pjsize, pjpage_count, pjspooled, pjsmbjob; 382 383 383 if ( !buf || !pjob )384 if (!buf || !pjob) { 384 385 return -1; 385 386 len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff", 386 } 387 388 len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff", 387 389 &pjpid, 390 &pjjobid, 388 391 &pjsysjob, 389 392 &pjfd, … … 400 403 pjob->queuename); 401 404 402 if ( len == -1 )405 if (len == -1) { 403 406 return -1; 404 405 used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode); 407 } 408 409 used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode); 406 410 if (used == -1) { 407 411 return -1; … … 411 415 412 416 pjob->pid = pjpid; 417 pjob->jobid = pjjobid; 413 418 pjob->sysjob = pjsysjob; 414 419 pjob->fd = pjfd; … … 428 433 ****************************************************************************/ 429 434 430 static struct printjob *print_job_find(const char *sharename, uint32 jobid) 431 { 432 static struct printjob pjob; 435 static struct printjob *print_job_find(TALLOC_CTX *mem_ctx, 436 const char *sharename, 437 uint32 jobid) 438 { 439 struct printjob *pjob; 433 440 uint32_t tmp; 434 441 TDB_DATA ret; … … 446 453 447 454 if (!ret.dptr) { 448 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid )); 455 DEBUG(10, ("print_job_find: failed to find jobid %u.\n", 456 jobid)); 449 457 return NULL; 450 458 } 451 459 452 talloc_free(pjob.devmode); 453 454 ZERO_STRUCT( pjob ); 455 456 if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) { 457 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid )); 458 SAFE_FREE(ret.dptr); 459 return NULL; 460 } 461 460 pjob = talloc_zero(mem_ctx, struct printjob); 461 if (pjob == NULL) { 462 goto err_out; 463 } 464 465 if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) { 466 DEBUG(10, ("failed to unpack jobid %u.\n", jobid)); 467 talloc_free(pjob); 468 pjob = NULL; 469 goto err_out; 470 } 471 472 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n", 473 pjob->sysjob, jobid)); 474 SMB_ASSERT(pjob->jobid == jobid); 475 476 err_out: 462 477 SAFE_FREE(ret.dptr); 463 464 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n", 465 (int)pjob.sysjob, (unsigned int)jobid )); 466 467 return &pjob; 478 return pjob; 468 479 } 469 480 … … 490 501 491 502 if (state->sysjob == pjob->sysjob) { 492 uint32 jobid = IVAL(key.dptr,0); 493 494 state->sysjob_to_jobid_value = jobid; 503 state->sysjob_to_jobid_value = pjob->jobid; 495 504 return 1; 496 505 } 497 506 498 507 return 0; 508 } 509 510 static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob) 511 { 512 struct unixjob_traverse_state state; 513 514 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; 499 520 } 500 521 … … 738 759 len = 0; 739 760 buflen = newlen; 740 len += tdb_pack(buf+len, buflen-len, "ddddddddd fffff",761 len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff", 741 762 (uint32)pjob->pid, 763 (uint32)pjob->jobid, 742 764 (uint32)pjob->sysjob, 743 765 (uint32)pjob->fd, … … 776 798 /* Send notify updates for what has changed */ 777 799 778 if ( ret) {800 if (ret) { 779 801 bool changed = false; 780 802 struct printjob old_pjob; 781 803 782 if ( old_data.dsize ) 783 { 784 if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 ) 785 { 786 pjob_store_notify(server_event_context(), 804 if (old_data.dsize) { 805 TALLOC_CTX *tmp_ctx = talloc_new(ev); 806 if (tmp_ctx == NULL) 807 goto done; 808 809 len = unpack_pjob(tmp_ctx, old_data.dptr, 810 old_data.dsize, &old_pjob); 811 if (len != -1 ) { 812 pjob_store_notify(ev, 787 813 msg_ctx, 788 814 sharename, jobid, &old_pjob, 789 815 pjob, 790 816 &changed); 791 talloc_free(old_pjob.devmode);792 793 817 if (changed) { 794 818 add_to_jobs_changed(pdb, jobid); 795 819 } 796 820 } 797 798 } 799 else {821 talloc_free(tmp_ctx); 822 823 } else { 800 824 /* new job */ 801 pjob_store_notify( server_event_context(), msg_ctx,825 pjob_store_notify(ev, msg_ctx, 802 826 sharename, jobid, NULL, pjob, 803 827 &changed); … … 805 829 } 806 830 831 done: 807 832 release_print_db(pdb); 808 done:809 833 SAFE_FREE( old_data.dptr ); 810 834 SAFE_FREE( buf ); … … 825 849 uint32 job_status = 0; 826 850 struct tdb_print_db *pdb; 827 828 pdb = get_print_db_byname( sharename ); 829 830 if (!pdb) 851 TALLOC_CTX *tmp_ctx = talloc_new(ev); 852 if (tmp_ctx == NULL) { 831 853 return; 832 833 pjob = print_job_find( sharename, jobid ); 834 854 } 855 856 pdb = get_print_db_byname(sharename); 857 if (!pdb) { 858 goto err_out; 859 } 860 861 pjob = print_job_find(tmp_ctx, sharename, jobid); 835 862 if (!pjob) { 836 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n", 837 (unsigned int)jobid)); 838 release_print_db(pdb); 839 return; 863 DEBUG(5, ("we were asked to delete nonexistent job %u\n", 864 jobid)); 865 goto err_release; 840 866 } 841 867 … … 851 877 tdb_delete(pdb->tdb, print_key(jobid, &tmp)); 852 878 remove_from_jobs_added(sharename, jobid); 853 release_print_db( pdb );854 879 rap_jobid_delete(sharename, jobid); 880 err_release: 881 release_print_db(pdb); 882 err_out: 883 talloc_free(tmp_ctx); 855 884 } 856 885 … … 865 894 { 866 895 struct printjob pj, *old_pj; 867 868 if (jobid == (uint32)-1) 869 jobid = q->job + UNIX_JOB_START; 896 TALLOC_CTX *tmp_ctx = talloc_new(ev); 897 if (tmp_ctx == NULL) { 898 return; 899 } 900 901 if (jobid == (uint32)-1) { 902 jobid = q->sysjob + UNIX_JOB_START; 903 } 870 904 871 905 /* Preserve the timestamp on an existing unix print job */ 872 906 873 old_pj = print_job_find( sharename, jobid);907 old_pj = print_job_find(tmp_ctx, sharename, jobid); 874 908 875 909 ZERO_STRUCT(pj); 876 910 877 911 pj.pid = (pid_t)-1; 878 pj.sysjob = q->job; 912 pj.jobid = jobid; 913 pj.sysjob = q->sysjob; 879 914 pj.fd = -1; 880 915 pj.starttime = old_pj ? old_pj->starttime : q->time; … … 894 929 895 930 pjob_store(ev, msg_ctx, sharename, jobid, &pj); 931 talloc_free(tmp_ctx); 896 932 } 897 933 … … 906 942 struct tevent_context *ev; 907 943 struct messaging_context *msg_ctx; 944 TALLOC_CTX *mem_ctx; 908 945 }; 909 946 … … 922 959 return 0; 923 960 924 jobid = IVAL(key.dptr, 0); 925 if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 ) 961 if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1) 926 962 return 0; 927 963 talloc_free(pjob.devmode); 928 964 jobid = pjob.jobid; 929 965 930 966 if (!pjob.smbjob) { 931 967 /* remove a unix job if it isn't in the system queue any more */ 932 933 968 for (i=0;i<ts->qcount;i++) { 934 uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START); 935 if (jobid == u_jobid) 969 if (ts->queue[i].sysjob == pjob.sysjob) { 936 970 break; 971 } 937 972 } 938 973 if (i == ts->qcount) { … … 965 1000 /* this check only makes sense for jobs submitted from Windows clients */ 966 1001 967 if ( pjob.smbjob) {1002 if (pjob.smbjob) { 968 1003 for (i=0;i<ts->qcount;i++) { 969 uint32 curr_jobid;970 971 1004 if ( pjob.status == LPQ_DELETED ) 972 1005 continue; 973 1006 974 curr_jobid = print_parse_jobid(ts->queue[i].fs_file); 975 976 if (jobid == curr_jobid) { 1007 if (ts->queue[i].sysjob == pjob.sysjob) { 977 1008 978 1009 /* try to clean up any jobs that need to be deleted */ … … 1029 1060 } 1030 1061 1031 /* Save the pjob attributes we will store. 1032 FIXME!!! This is the only place where queue->job 1033 represents the SMB jobid --jerry */ 1034 1035 ts->queue[i].job = jobid; 1062 /* Save the pjob attributes we will store. */ 1063 ts->queue[i].sysjob = pjob.sysjob; 1036 1064 ts->queue[i].size = pjob.size; 1037 1065 ts->queue[i].page_count = pjob.page_count; … … 1184 1212 qcount++; 1185 1213 data.dsize += tdb_pack(NULL, 0, "ddddddff", 1186 (uint32)queue[i]. job,1214 (uint32)queue[i].sysjob, 1187 1215 (uint32)queue[i].size, 1188 1216 (uint32)queue[i].page_count, … … 1204 1232 1205 1233 len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff", 1206 (uint32)queue[i]. job,1234 (uint32)queue[i].sysjob, 1207 1235 (uint32)queue[i].size, 1208 1236 (uint32)queue[i].page_count, … … 1318 1346 ****************************************************************************/ 1319 1347 1320 static void print_queue_update_internal( 1321 1322 1323 1324 char *lpq_command, char *lprm_command)1348 static void print_queue_update_internal(struct tevent_context *ev, 1349 struct messaging_context *msg_ctx, 1350 const char *sharename, 1351 struct printif *current_printif, 1352 char *lpq_command, char *lprm_command) 1325 1353 { 1326 1354 int i, qcount; … … 1334 1362 fstring keystr, cachestr; 1335 1363 struct tdb_print_db *pdb = get_print_db_byname(sharename); 1336 1337 if (!pdb) { 1364 TALLOC_CTX *tmp_ctx = talloc_new(ev); 1365 1366 if ((pdb == NULL) || (tmp_ctx == NULL)) { 1338 1367 return; 1339 1368 } … … 1376 1405 fill in any system job numbers as we go 1377 1406 */ 1378 1379 1407 jcdata = get_jobs_added_data(pdb); 1380 1408 1381 1409 for (i=0; i<qcount; i++) { 1382 uint32 jobid = print_parse_jobid(queue[i].fs_file); 1383 1410 uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob); 1384 1411 if (jobid == (uint32)-1) { 1385 1412 /* assume its a unix print job */ … … 1390 1417 1391 1418 /* we have an active SMB print job - update its status */ 1392 pjob = print_job_find( sharename, jobid);1419 pjob = print_job_find(tmp_ctx, sharename, jobid); 1393 1420 if (!pjob) { 1394 1421 /* err, somethings wrong. Probably smbd was restarted 1395 1422 with jobs in the queue. All we can do is treat them 1396 1423 like unix jobs. Pity. */ 1424 DEBUG(1, ("queued print job %d not found in jobs list, " 1425 "assuming unix job\n", jobid)); 1397 1426 print_unix_job(ev, msg_ctx, 1398 1427 sharename, &queue[i], jobid); 1399 1428 continue; 1400 1429 } 1401 1402 pjob->sysjob = queue[i].job;1403 1430 1404 1431 /* don't reset the status on jobs to be deleted */ … … 1426 1453 tstruct.ev = ev; 1427 1454 tstruct.msg_ctx = msg_ctx; 1455 tstruct.mem_ctx = tmp_ctx; 1428 1456 1429 1457 tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct); … … 1433 1461 1434 1462 SAFE_FREE(tstruct.queue); 1463 talloc_free(tmp_ctx); 1435 1464 1436 1465 DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n", … … 1628 1657 } 1629 1658 1659 static bool printer_housekeeping_fn(const struct timeval *now, 1660 void *private_data) 1661 { 1662 static time_t last_pcap_reload_time = 0; 1663 time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); 1664 time_t t = time_mono(NULL); 1665 1666 DEBUG(5, ("printer housekeeping\n")); 1667 1668 /* if periodic printcap rescan is enabled, see if it's time to reload */ 1669 if ((printcap_cache_time != 0) 1670 && (t >= (last_pcap_reload_time + printcap_cache_time))) { 1671 DEBUG( 3,( "Printcap cache time expired.\n")); 1672 pcap_cache_reload(server_event_context(), 1673 smbd_messaging_context(), 1674 &reload_pcap_change_notify); 1675 last_pcap_reload_time = t; 1676 } 1677 1678 return true; 1679 } 1680 1630 1681 static pid_t background_lpq_updater_pid = -1; 1631 1682 … … 1699 1750 DEBUG(0,("tevent_add_fd() failed for pause_pipe\n")); 1700 1751 smb_panic("tevent_add_fd() failed for pause_pipe"); 1752 } 1753 1754 if (!(event_add_idle(ev, NULL, 1755 timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0), 1756 "printer_housekeeping", 1757 printer_housekeeping_fn, 1758 NULL))) { 1759 DEBUG(0, ("Could not add printing housekeeping event\n")); 1760 exit(1); 1701 1761 } 1702 1762 … … 2045 2105 2046 2106 /**************************************************************************** 2047 Give the filename used for a jobid.2107 Return the device mode asigned to a specific print job. 2048 2108 Only valid for the process doing the spooling and when the job 2049 2109 has not been spooled. 2050 2110 ****************************************************************************/ 2051 2111 2052 char *print_job_fname(const char* sharename, uint32 jobid) 2053 { 2054 struct printjob *pjob = print_job_find(sharename, jobid); 2055 if (!pjob || pjob->spooled || pjob->pid != sys_getpid()) 2112 struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx, 2113 const char *sharename, 2114 uint32 jobid) 2115 { 2116 struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid); 2117 if (pjob == NULL) { 2056 2118 return NULL; 2057 return pjob->filename; 2058 } 2059 2060 2061 /**************************************************************************** 2062 Give the filename used for a jobid. 2063 Only valid for the process doing the spooling and when the job 2064 has not been spooled. 2065 ****************************************************************************/ 2066 2067 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid) 2068 { 2069 struct printjob *pjob = print_job_find(sharename, jobid); 2070 2071 if ( !pjob ) 2072 return NULL; 2119 } 2073 2120 2074 2121 return pjob->devmode; … … 2084 2131 { 2085 2132 struct printjob *pjob; 2086 2087 pjob = print_job_find(sharename, jobid); 2088 if (!pjob || pjob->pid != sys_getpid()) 2089 return False; 2133 bool ret; 2134 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2135 if (tmp_ctx == NULL) { 2136 return false; 2137 } 2138 2139 pjob = print_job_find(tmp_ctx, sharename, jobid); 2140 if (!pjob || pjob->pid != sys_getpid()) { 2141 ret = false; 2142 goto err_out; 2143 } 2090 2144 2091 2145 fstrcpy(pjob->jobname, name); 2092 return pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2146 ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2147 err_out: 2148 talloc_free(tmp_ctx); 2149 return ret; 2093 2150 } 2094 2151 … … 2101 2158 struct printjob *pjob; 2102 2159 2103 pjob = print_job_find( sharename, jobid);2160 pjob = print_job_find(mem_ctx, sharename, jobid); 2104 2161 if (!pjob || pjob->pid != sys_getpid()) { 2105 2162 return false; 2106 2163 } 2107 2164 2108 *name = talloc_strdup(mem_ctx, pjob->jobname); 2109 if (!*name) { 2110 return false; 2111 } 2112 2165 *name = pjob->jobname; 2113 2166 return true; 2114 2167 } … … 2183 2236 { 2184 2237 const char* sharename = lp_const_servicename(snum); 2185 struct printjob *pjob = print_job_find(sharename, jobid);2238 struct printjob *pjob; 2186 2239 int result = 0; 2187 2240 struct printif *current_printif = get_printer_fns( snum ); 2188 2189 if (!pjob) 2190 return False; 2241 bool ret; 2242 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2243 if (tmp_ctx == NULL) { 2244 return false; 2245 } 2246 2247 pjob = print_job_find(tmp_ctx, sharename, jobid); 2248 if (!pjob) { 2249 ret = false; 2250 goto err_out; 2251 } 2191 2252 2192 2253 /* … … 2194 2255 */ 2195 2256 2196 if (pjob->status == LPQ_DELETING) 2197 return True; 2257 if (pjob->status == LPQ_DELETING) { 2258 ret = true; 2259 goto err_out; 2260 } 2198 2261 2199 2262 /* Hrm - we need to be able to cope with deleting a job before it … … 2225 2288 int njobs = 1; 2226 2289 2227 if (!pdb) 2228 return False; 2290 if (!pdb) { 2291 ret = false; 2292 goto err_out; 2293 } 2229 2294 pjob_delete(ev, msg_ctx, sharename, jobid); 2230 2295 /* Ensure we keep a rough count of the number of total jobs... */ … … 2236 2301 remove_from_jobs_added( sharename, jobid ); 2237 2302 2238 return (result == 0); 2303 ret = (result == 0); 2304 err_out: 2305 talloc_free(tmp_ctx); 2306 return ret; 2239 2307 } 2240 2308 … … 2247 2315 uint32 jobid) 2248 2316 { 2249 struct printjob *pjob = print_job_find(servicename, jobid); 2250 2251 if (!pjob || !server_info) 2252 return False; 2253 2254 return strequal(pjob->user, server_info->sanitized_username); 2317 struct printjob *pjob; 2318 bool ret; 2319 TALLOC_CTX *tmp_ctx = talloc_new(server_info); 2320 if (tmp_ctx == NULL) { 2321 return false; 2322 } 2323 2324 pjob = print_job_find(tmp_ctx, servicename, jobid); 2325 if (!pjob || !server_info) { 2326 ret = false; 2327 goto err_out; 2328 } 2329 2330 ret = strequal(pjob->user, server_info->sanitized_username); 2331 err_out: 2332 talloc_free(tmp_ctx); 2333 return ret; 2255 2334 } 2256 2335 … … 2266 2345 struct printjob *pjob; 2267 2346 bool owner; 2268 char *fname; 2347 WERROR werr; 2348 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2349 if (tmp_ctx == NULL) { 2350 return WERR_NOT_ENOUGH_MEMORY; 2351 } 2269 2352 2270 2353 owner = is_owner(server_info, lp_const_servicename(snum), jobid); … … 2286 2369 /* END_ADMIN_LOG */ 2287 2370 2288 return WERR_ACCESS_DENIED; 2371 werr = WERR_ACCESS_DENIED; 2372 goto err_out; 2289 2373 } 2290 2374 … … 2296 2380 */ 2297 2381 2298 fname = print_job_fname(sharename, jobid); 2299 if (fname != NULL) { 2300 /* remove the spool file */ 2301 DEBUG(10, ("print_job_delete: " 2302 "Removing spool file [%s]\n", fname)); 2303 if (unlink(fname) == -1) { 2304 return map_werror_from_unix(errno); 2382 pjob = print_job_find(tmp_ctx, sharename, jobid); 2383 if (!pjob || pjob->spooled || pjob->pid != getpid()) { 2384 DEBUG(10, ("Skipping spool file removal for job %u\n", jobid)); 2385 } else { 2386 DEBUG(10, ("Removing spool file [%s]\n", pjob->filename)); 2387 if (unlink(pjob->filename) == -1) { 2388 werr = map_werror_from_unix(errno); 2389 goto err_out; 2305 2390 } 2306 2391 } 2307 2392 2308 2393 if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) { 2309 return WERR_ACCESS_DENIED; 2394 werr = WERR_ACCESS_DENIED; 2395 goto err_out; 2310 2396 } 2311 2397 … … 2315 2401 print_queue_update(msg_ctx, snum, True); 2316 2402 2317 pjob = print_job_find( sharename, jobid);2403 pjob = print_job_find(tmp_ctx, sharename, jobid); 2318 2404 if (pjob && (pjob->status != LPQ_DELETING)) { 2319 return WERR_ACCESS_DENIED; 2320 } 2321 2322 return WERR_PRINTER_HAS_JOBS_QUEUED; 2405 werr = WERR_ACCESS_DENIED; 2406 goto err_out; 2407 } 2408 werr = WERR_PRINTER_HAS_JOBS_QUEUED; 2409 2410 err_out: 2411 talloc_free(tmp_ctx); 2412 return werr; 2323 2413 } 2324 2414 … … 2327 2417 ****************************************************************************/ 2328 2418 2329 boolprint_job_pause(const struct auth_serversupplied_info *server_info,2419 WERROR print_job_pause(const struct auth_serversupplied_info *server_info, 2330 2420 struct messaging_context *msg_ctx, 2331 int snum, uint32 jobid , WERROR *errcode)2421 int snum, uint32 jobid) 2332 2422 { 2333 2423 const char* sharename = lp_const_servicename(snum); … … 2335 2425 int ret = -1; 2336 2426 struct printif *current_printif = get_printer_fns( snum ); 2337 2338 pjob = print_job_find(sharename, jobid); 2339 2427 WERROR werr; 2428 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2429 if (tmp_ctx == NULL) { 2430 return WERR_NOT_ENOUGH_MEMORY; 2431 } 2432 2433 pjob = print_job_find(tmp_ctx, sharename, jobid); 2340 2434 if (!pjob || !server_info) { 2341 2435 DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n", 2342 2436 (unsigned int)jobid )); 2343 return False; 2437 werr = WERR_INVALID_PARAM; 2438 goto err_out; 2344 2439 } 2345 2440 … … 2347 2442 DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n", 2348 2443 (int)pjob->sysjob, (unsigned int)jobid )); 2349 return False; 2444 werr = WERR_INVALID_PARAM; 2445 goto err_out; 2350 2446 } 2351 2447 … … 2363 2459 /* END_ADMIN_LOG */ 2364 2460 2365 *errcode= WERR_ACCESS_DENIED;2366 return False;2461 werr = WERR_ACCESS_DENIED; 2462 goto err_out; 2367 2463 } 2368 2464 … … 2371 2467 2372 2468 if (ret != 0) { 2373 *errcode= WERR_INVALID_PARAM;2374 return False;2469 werr = WERR_INVALID_PARAM; 2470 goto err_out; 2375 2471 } 2376 2472 … … 2384 2480 2385 2481 /* how do we tell if this succeeded? */ 2386 2387 return True; 2482 werr = WERR_OK; 2483 err_out: 2484 talloc_free(tmp_ctx); 2485 return werr; 2388 2486 } 2389 2487 … … 2392 2490 ****************************************************************************/ 2393 2491 2394 boolprint_job_resume(const struct auth_serversupplied_info *server_info,2492 WERROR print_job_resume(const struct auth_serversupplied_info *server_info, 2395 2493 struct messaging_context *msg_ctx, 2396 int snum, uint32 jobid , WERROR *errcode)2494 int snum, uint32 jobid) 2397 2495 { 2398 2496 const char *sharename = lp_const_servicename(snum); … … 2400 2498 int ret; 2401 2499 struct printif *current_printif = get_printer_fns( snum ); 2402 2403 pjob = print_job_find(sharename, jobid); 2404 2500 WERROR werr; 2501 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2502 if (tmp_ctx == NULL) 2503 return WERR_NOT_ENOUGH_MEMORY; 2504 2505 pjob = print_job_find(tmp_ctx, sharename, jobid); 2405 2506 if (!pjob || !server_info) { 2406 2507 DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n", 2407 2508 (unsigned int)jobid )); 2408 return False; 2509 werr = WERR_INVALID_PARAM; 2510 goto err_out; 2409 2511 } 2410 2512 … … 2412 2514 DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n", 2413 2515 (int)pjob->sysjob, (unsigned int)jobid )); 2414 return False; 2516 werr = WERR_INVALID_PARAM; 2517 goto err_out; 2415 2518 } 2416 2519 … … 2419 2522 JOB_ACCESS_ADMINISTER)) { 2420 2523 DEBUG(3, ("resume denied by security descriptor\n")); 2421 *errcode = WERR_ACCESS_DENIED;2422 2524 2423 2525 /* BEGIN_ADMIN_LOG */ … … 2428 2530 lp_printername(snum) ); 2429 2531 /* END_ADMIN_LOG */ 2430 return False; 2532 werr = WERR_ACCESS_DENIED; 2533 goto err_out; 2431 2534 } 2432 2535 … … 2434 2537 2435 2538 if (ret != 0) { 2436 *errcode= WERR_INVALID_PARAM;2437 return False;2539 werr = WERR_INVALID_PARAM; 2540 goto err_out; 2438 2541 } 2439 2542 … … 2446 2549 JOB_STATUS_QUEUED); 2447 2550 2448 return True; 2551 werr = WERR_OK; 2552 err_out: 2553 talloc_free(tmp_ctx); 2554 return werr; 2449 2555 } 2450 2556 … … 2460 2566 ssize_t return_code; 2461 2567 struct printjob *pjob; 2462 2463 pjob = print_job_find(sharename, jobid); 2464 2465 if (!pjob) 2568 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2569 if (tmp_ctx == NULL) { 2466 2570 return -1; 2571 } 2572 2573 pjob = print_job_find(tmp_ctx, sharename, jobid); 2574 if (!pjob) { 2575 return_code = -1; 2576 goto err_out; 2577 } 2578 2467 2579 /* don't allow another process to get this info - it is meaningless */ 2468 if (pjob->pid != sys_getpid()) 2469 return -1; 2580 if (pjob->pid != sys_getpid()) { 2581 return_code = -1; 2582 goto err_out; 2583 } 2470 2584 2471 2585 /* if SMBD is spooling this can't be allowed */ 2472 2586 if (pjob->status == PJOB_SMBD_SPOOLING) { 2473 return -1; 2587 return_code = -1; 2588 goto err_out; 2474 2589 } 2475 2590 2476 2591 return_code = write_data(pjob->fd, buf, size); 2477 2478 if (return_code>0) { 2592 if (return_code > 0) { 2479 2593 pjob->size += size; 2480 2594 pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2481 2595 } 2596 err_out: 2597 talloc_free(tmp_ctx); 2482 2598 return return_code; 2483 2599 } … … 2759 2875 2760 2876 slprintf(pjob->filename, sizeof(pjob->filename)-1, 2761 "%s/%s%.8u.XXXXXX", lp_pathname(snum), 2762 PRINT_SPOOL_PREFIX, (unsigned int)jobid); 2877 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX); 2763 2878 pjob->fd = mkstemp(pjob->filename); 2764 2879 … … 2826 2941 2827 2942 pjob.pid = sys_getpid(); 2943 pjob.jobid = jobid; 2828 2944 pjob.sysjob = -1; 2829 2945 pjob.fd = -1; … … 2890 3006 const char* sharename = lp_const_servicename(snum); 2891 3007 struct printjob *pjob; 2892 2893 pjob = print_job_find(sharename, jobid); 2894 if (!pjob) 3008 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3009 if (tmp_ctx == NULL) { 2895 3010 return; 3011 } 3012 3013 pjob = print_job_find(tmp_ctx, sharename, jobid); 3014 if (!pjob) { 3015 goto err_out; 3016 } 2896 3017 /* don't allow another process to get this info - it is meaningless */ 2897 if (pjob->pid != sys_getpid()) 2898 return; 3018 if (pjob->pid != sys_getpid()) { 3019 goto err_out; 3020 } 2899 3021 2900 3022 pjob->page_count++; 2901 3023 pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob); 3024 err_out: 3025 talloc_free(tmp_ctx); 2902 3026 } 2903 3027 … … 2915 3039 int ret; 2916 3040 SMB_STRUCT_STAT sbuf; 2917 struct printif *current_printif = get_printer_fns( snum);3041 struct printif *current_printif = get_printer_fns(snum); 2918 3042 NTSTATUS status = NT_STATUS_UNSUCCESSFUL; 2919 2920 pjob = print_job_find(sharename, jobid); 2921 3043 char *lpq_cmd; 3044 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3045 if (tmp_ctx == NULL) { 3046 return NT_STATUS_NO_MEMORY; 3047 } 3048 3049 pjob = print_job_find(tmp_ctx, sharename, jobid); 2922 3050 if (!pjob) { 2923 return NT_STATUS_PRINT_CANCELLED; 3051 status = NT_STATUS_PRINT_CANCELLED; 3052 goto err_out; 2924 3053 } 2925 3054 2926 3055 if (pjob->spooled || pjob->pid != sys_getpid()) { 2927 return NT_STATUS_ACCESS_DENIED; 3056 status = NT_STATUS_ACCESS_DENIED; 3057 goto err_out; 2928 3058 } 2929 3059 … … 2979 3109 } 2980 3110 2981 ret = (*(current_printif->job_submit))(snum, pjob); 2982 3111 /* don't strip out characters like '$' from the printername */ 3112 lpq_cmd = talloc_string_sub2(tmp_ctx, 3113 lp_lpqcommand(snum), 3114 "%p", 3115 lp_printername(snum), 3116 false, false, false); 3117 if (lpq_cmd == NULL) { 3118 status = NT_STATUS_PRINT_CANCELLED; 3119 goto fail; 3120 } 3121 lpq_cmd = talloc_sub_advanced(tmp_ctx, 3122 lp_servicename(snum), 3123 current_user_info.unix_name, 3124 "", 3125 current_user.ut.gid, 3126 get_current_username(), 3127 current_user_info.domain, 3128 lpq_cmd); 3129 if (lpq_cmd == NULL) { 3130 status = NT_STATUS_PRINT_CANCELLED; 3131 goto fail; 3132 } 3133 3134 ret = (*(current_printif->job_submit))(snum, pjob, 3135 current_printif->type, lpq_cmd); 2983 3136 if (ret) { 2984 3137 status = NT_STATUS_PRINT_CANCELLED; … … 3005 3158 unlink(pjob->filename); 3006 3159 pjob_delete(server_event_context(), msg_ctx, sharename, jobid); 3160 err_out: 3161 talloc_free(tmp_ctx); 3007 3162 return status; 3008 3163 } … … 3027 3182 bool ret = False; 3028 3183 const char* sharename = lp_servicename(snum); 3184 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3185 if (tmp_ctx == NULL) { 3186 return false; 3187 } 3029 3188 3030 3189 /* make sure the database is up to date */ … … 3076 3235 queue[i].fs_user, 3077 3236 queue[i].fs_file); 3078 queue[i]. job = qjob;3237 queue[i].sysjob = qjob; 3079 3238 queue[i].size = qsize; 3080 3239 queue[i].page_count = qpage_count; … … 3093 3252 jobid = IVAL(cgdata.dptr, i*4); 3094 3253 DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid)); 3095 pjob = print_job_find( lp_const_servicename(snum), jobid);3254 pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid); 3096 3255 if (!pjob) { 3097 3256 DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid)); … … 3100 3259 } 3101 3260 3102 queue[total_count]. job = jobid;3261 queue[total_count].sysjob = jobid; 3103 3262 queue[total_count].size = pjob->size; 3104 3263 queue[total_count].page_count = pjob->page_count; … … 3109 3268 fstrcpy(queue[total_count].fs_file, pjob->jobname); 3110 3269 total_count++; 3270 talloc_free(pjob); 3111 3271 } 3112 3272 … … 3118 3278 3119 3279 for (j = 0; j < total_count; j++) { 3120 if (queue[j]. job == jobid) {3280 if (queue[j].sysjob == jobid) { 3121 3281 found = true; 3122 3282 break; … … 3130 3290 (unsigned int) jobid)); 3131 3291 3132 pjob = print_job_find( sharename, jobid);3292 pjob = print_job_find(tmp_ctx, sharename, jobid); 3133 3293 if (pjob == NULL) { 3134 3294 DEBUG(5,("get_stored_queue_info: failed to find " … … 3139 3299 } 3140 3300 3141 queue[j]. job = jobid;3301 queue[j].sysjob = jobid; 3142 3302 queue[j].size = pjob->size; 3143 3303 queue[j].page_count = pjob->page_count; … … 3147 3307 fstrcpy(queue[j].fs_user, pjob->user); 3148 3308 fstrcpy(queue[j].fs_file, pjob->jobname); 3309 talloc_free(pjob); 3149 3310 3150 3311 DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n", … … 3174 3335 SAFE_FREE(data.dptr); 3175 3336 SAFE_FREE(cgdata.dptr); 3337 talloc_free(tmp_ctx); 3176 3338 return ret; 3177 3339 } … … 3341 3503 for (i=0;i<njobs;i++) { 3342 3504 bool owner = is_owner(server_info, lp_const_servicename(snum), 3343 queue[i]. job);3505 queue[i].sysjob); 3344 3506 3345 3507 if (owner || can_job_admin) { 3346 3508 print_job_delete1(server_event_context(), msg_ctx, 3347 snum, queue[i]. job);3509 snum, queue[i].sysjob); 3348 3510 } 3349 3511 }
Note:
See TracChangeset
for help on using the changeset viewer.