Changeset 751 for trunk/server/source3/printing/printing.c
- Timestamp:
- Nov 29, 2012, 1:59:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/printing/printing.c
r745 r751 378 378 ***********************************************************************/ 379 379 380 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob ) 380 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen, 381 struct printjob *pjob) 381 382 { 382 383 int len = 0; 383 384 int used; 384 uint32 pjpid, pj sysjob, pjfd, pjstarttime, pjstatus;385 uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus; 385 386 uint32 pjsize, pjpage_count, pjspooled, pjsmbjob; 386 387 387 if ( !buf || !pjob )388 if (!buf || !pjob) { 388 389 return -1; 389 390 len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff", 390 } 391 392 len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff", 391 393 &pjpid, 394 &pjjobid, 392 395 &pjsysjob, 393 396 &pjfd, … … 404 407 pjob->queuename); 405 408 406 if ( len == -1 )409 if (len == -1) { 407 410 return -1; 408 409 used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode); 411 } 412 413 used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode); 410 414 if (used == -1) { 411 415 return -1; … … 415 419 416 420 pjob->pid = pjpid; 421 pjob->jobid = pjjobid; 417 422 pjob->sysjob = pjsysjob; 418 423 pjob->fd = pjfd; … … 432 437 ****************************************************************************/ 433 438 434 static struct printjob *print_job_find(const char *sharename, uint32 jobid) 435 { 436 static struct printjob pjob; 439 static struct printjob *print_job_find(TALLOC_CTX *mem_ctx, 440 const char *sharename, 441 uint32 jobid) 442 { 443 struct printjob *pjob; 437 444 uint32_t tmp; 438 445 TDB_DATA ret; … … 450 457 451 458 if (!ret.dptr) { 452 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid )); 459 DEBUG(10, ("print_job_find: failed to find jobid %u.\n", 460 jobid)); 453 461 return NULL; 454 462 } 455 463 456 talloc_free(pjob.devmode); 457 458 ZERO_STRUCT( pjob ); 459 460 if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) { 461 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid )); 462 SAFE_FREE(ret.dptr); 463 return NULL; 464 } 465 464 pjob = talloc_zero(mem_ctx, struct printjob); 465 if (pjob == NULL) { 466 goto err_out; 467 } 468 469 if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) { 470 DEBUG(10, ("failed to unpack jobid %u.\n", jobid)); 471 talloc_free(pjob); 472 pjob = NULL; 473 goto err_out; 474 } 475 476 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n", 477 pjob->sysjob, jobid)); 478 SMB_ASSERT(pjob->jobid == jobid); 479 480 err_out: 466 481 SAFE_FREE(ret.dptr); 467 468 DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n", 469 (int)pjob.sysjob, (unsigned int)jobid )); 470 471 return &pjob; 482 return pjob; 472 483 } 473 484 … … 494 505 495 506 if (state->sysjob == pjob->sysjob) { 496 uint32 jobid = IVAL(key.dptr,0); 497 498 state->sysjob_to_jobid_value = jobid; 507 state->sysjob_to_jobid_value = pjob->jobid; 499 508 return 1; 500 509 } 501 510 502 511 return 0; 512 } 513 514 static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob) 515 { 516 struct unixjob_traverse_state state; 517 518 state.sysjob = sysjob; 519 state.sysjob_to_jobid_value = (uint32)-1; 520 521 tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state); 522 523 return state.sysjob_to_jobid_value; 503 524 } 504 525 … … 742 763 len = 0; 743 764 buflen = newlen; 744 len += tdb_pack(buf+len, buflen-len, "ddddddddd fffff",765 len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff", 745 766 (uint32)pjob->pid, 767 (uint32)pjob->jobid, 746 768 (uint32)pjob->sysjob, 747 769 (uint32)pjob->fd, … … 780 802 /* Send notify updates for what has changed */ 781 803 782 if ( ret) {804 if (ret) { 783 805 bool changed = false; 784 806 struct printjob old_pjob; 785 807 786 if ( old_data.dsize ) 787 { 788 if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 ) 789 { 790 pjob_store_notify(server_event_context(), 808 if (old_data.dsize) { 809 TALLOC_CTX *tmp_ctx = talloc_new(ev); 810 if (tmp_ctx == NULL) 811 goto done; 812 813 len = unpack_pjob(tmp_ctx, old_data.dptr, 814 old_data.dsize, &old_pjob); 815 if (len != -1 ) { 816 pjob_store_notify(ev, 791 817 msg_ctx, 792 818 sharename, jobid, &old_pjob, 793 819 pjob, 794 820 &changed); 795 talloc_free(old_pjob.devmode);796 797 821 if (changed) { 798 822 add_to_jobs_changed(pdb, jobid); 799 823 } 800 824 } 801 802 } 803 else {825 talloc_free(tmp_ctx); 826 827 } else { 804 828 /* new job */ 805 pjob_store_notify( server_event_context(), msg_ctx,829 pjob_store_notify(ev, msg_ctx, 806 830 sharename, jobid, NULL, pjob, 807 831 &changed); … … 809 833 } 810 834 835 done: 811 836 release_print_db(pdb); 812 done:813 837 SAFE_FREE( old_data.dptr ); 814 838 SAFE_FREE( buf ); … … 829 853 uint32 job_status = 0; 830 854 struct tdb_print_db *pdb; 831 832 pdb = get_print_db_byname( sharename ); 833 834 if (!pdb) 855 TALLOC_CTX *tmp_ctx = talloc_new(ev); 856 if (tmp_ctx == NULL) { 835 857 return; 836 837 pjob = print_job_find( sharename, jobid ); 838 858 } 859 860 pdb = get_print_db_byname(sharename); 861 if (!pdb) { 862 goto err_out; 863 } 864 865 pjob = print_job_find(tmp_ctx, sharename, jobid); 839 866 if (!pjob) { 840 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n", 841 (unsigned int)jobid)); 842 release_print_db(pdb); 843 return; 867 DEBUG(5, ("we were asked to delete nonexistent job %u\n", 868 jobid)); 869 goto err_release; 844 870 } 845 871 … … 855 881 tdb_delete(pdb->tdb, print_key(jobid, &tmp)); 856 882 remove_from_jobs_added(sharename, jobid); 857 release_print_db( pdb );858 883 rap_jobid_delete(sharename, jobid); 884 err_release: 885 release_print_db(pdb); 886 err_out: 887 talloc_free(tmp_ctx); 859 888 } 860 889 … … 869 898 { 870 899 struct printjob pj, *old_pj; 871 872 if (jobid == (uint32)-1) 873 jobid = q->job + UNIX_JOB_START; 900 TALLOC_CTX *tmp_ctx = talloc_new(ev); 901 if (tmp_ctx == NULL) { 902 return; 903 } 904 905 if (jobid == (uint32)-1) { 906 jobid = q->sysjob + UNIX_JOB_START; 907 } 874 908 875 909 /* Preserve the timestamp on an existing unix print job */ 876 910 877 old_pj = print_job_find( sharename, jobid);911 old_pj = print_job_find(tmp_ctx, sharename, jobid); 878 912 879 913 ZERO_STRUCT(pj); 880 914 881 915 pj.pid = (pid_t)-1; 882 pj.sysjob = q->job; 916 pj.jobid = jobid; 917 pj.sysjob = q->sysjob; 883 918 pj.fd = -1; 884 919 pj.starttime = old_pj ? old_pj->starttime : q->time; … … 898 933 899 934 pjob_store(ev, msg_ctx, sharename, jobid, &pj); 935 talloc_free(tmp_ctx); 900 936 } 901 937 … … 910 946 struct tevent_context *ev; 911 947 struct messaging_context *msg_ctx; 948 TALLOC_CTX *mem_ctx; 912 949 }; 913 950 … … 926 963 return 0; 927 964 928 jobid = IVAL(key.dptr, 0); 929 if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 ) 965 if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1) 930 966 return 0; 931 967 talloc_free(pjob.devmode); 932 968 jobid = pjob.jobid; 933 969 934 970 if (!pjob.smbjob) { 935 971 /* remove a unix job if it isn't in the system queue any more */ 936 937 972 for (i=0;i<ts->qcount;i++) { 938 uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START); 939 if (jobid == u_jobid) 973 if (ts->queue[i].sysjob == pjob.sysjob) { 940 974 break; 975 } 941 976 } 942 977 if (i == ts->qcount) { … … 969 1004 /* this check only makes sense for jobs submitted from Windows clients */ 970 1005 971 if ( pjob.smbjob) {1006 if (pjob.smbjob) { 972 1007 for (i=0;i<ts->qcount;i++) { 973 uint32 curr_jobid;974 975 1008 if ( pjob.status == LPQ_DELETED ) 976 1009 continue; 977 1010 978 curr_jobid = print_parse_jobid(ts->queue[i].fs_file); 979 980 if (jobid == curr_jobid) { 1011 if (ts->queue[i].sysjob == pjob.sysjob) { 981 1012 982 1013 /* try to clean up any jobs that need to be deleted */ … … 1033 1064 } 1034 1065 1035 /* Save the pjob attributes we will store. 1036 FIXME!!! This is the only place where queue->job 1037 represents the SMB jobid --jerry */ 1038 1039 ts->queue[i].job = jobid; 1066 /* Save the pjob attributes we will store. */ 1067 ts->queue[i].sysjob = pjob.sysjob; 1040 1068 ts->queue[i].size = pjob.size; 1041 1069 ts->queue[i].page_count = pjob.page_count; … … 1188 1216 qcount++; 1189 1217 data.dsize += tdb_pack(NULL, 0, "ddddddff", 1190 (uint32)queue[i]. job,1218 (uint32)queue[i].sysjob, 1191 1219 (uint32)queue[i].size, 1192 1220 (uint32)queue[i].page_count, … … 1208 1236 1209 1237 len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff", 1210 (uint32)queue[i]. job,1238 (uint32)queue[i].sysjob, 1211 1239 (uint32)queue[i].size, 1212 1240 (uint32)queue[i].page_count, … … 1322 1350 ****************************************************************************/ 1323 1351 1324 static void print_queue_update_internal( 1325 1326 1327 1328 char *lpq_command, char *lprm_command)1352 static void print_queue_update_internal(struct tevent_context *ev, 1353 struct messaging_context *msg_ctx, 1354 const char *sharename, 1355 struct printif *current_printif, 1356 char *lpq_command, char *lprm_command) 1329 1357 { 1330 1358 int i, qcount; … … 1338 1366 fstring keystr, cachestr; 1339 1367 struct tdb_print_db *pdb = get_print_db_byname(sharename); 1340 1341 if (!pdb) { 1368 TALLOC_CTX *tmp_ctx = talloc_new(ev); 1369 1370 if ((pdb == NULL) || (tmp_ctx == NULL)) { 1342 1371 return; 1343 1372 } … … 1380 1409 fill in any system job numbers as we go 1381 1410 */ 1382 1383 1411 jcdata = get_jobs_added_data(pdb); 1384 1412 1385 1413 for (i=0; i<qcount; i++) { 1386 uint32 jobid = print_parse_jobid(queue[i].fs_file); 1387 1414 uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob); 1388 1415 if (jobid == (uint32)-1) { 1389 1416 /* assume its a unix print job */ … … 1394 1421 1395 1422 /* we have an active SMB print job - update its status */ 1396 pjob = print_job_find( sharename, jobid);1423 pjob = print_job_find(tmp_ctx, sharename, jobid); 1397 1424 if (!pjob) { 1398 1425 /* err, somethings wrong. Probably smbd was restarted 1399 1426 with jobs in the queue. All we can do is treat them 1400 1427 like unix jobs. Pity. */ 1428 DEBUG(1, ("queued print job %d not found in jobs list, " 1429 "assuming unix job\n", jobid)); 1401 1430 print_unix_job(ev, msg_ctx, 1402 1431 sharename, &queue[i], jobid); 1403 1432 continue; 1404 1433 } 1405 1406 pjob->sysjob = queue[i].job;1407 1434 1408 1435 /* don't reset the status on jobs to be deleted */ … … 1430 1457 tstruct.ev = ev; 1431 1458 tstruct.msg_ctx = msg_ctx; 1459 tstruct.mem_ctx = tmp_ctx; 1432 1460 1433 1461 tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct); … … 1437 1465 1438 1466 SAFE_FREE(tstruct.queue); 1467 talloc_free(tmp_ctx); 1439 1468 1440 1469 DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n", … … 1632 1661 } 1633 1662 1663 static bool printer_housekeeping_fn(const struct timeval *now, 1664 void *private_data) 1665 { 1666 static time_t last_pcap_reload_time = 0; 1667 time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); 1668 time_t t = time_mono(NULL); 1669 1670 DEBUG(5, ("printer housekeeping\n")); 1671 1672 /* if periodic printcap rescan is enabled, see if it's time to reload */ 1673 if ((printcap_cache_time != 0) 1674 && (t >= (last_pcap_reload_time + printcap_cache_time))) { 1675 DEBUG( 3,( "Printcap cache time expired.\n")); 1676 pcap_cache_reload(server_event_context(), 1677 smbd_messaging_context(), 1678 &reload_pcap_change_notify); 1679 last_pcap_reload_time = t; 1680 } 1681 1682 return true; 1683 } 1684 1634 1685 static pid_t background_lpq_updater_pid = -1; 1635 1686 … … 1703 1754 DEBUG(0,("tevent_add_fd() failed for pause_pipe\n")); 1704 1755 smb_panic("tevent_add_fd() failed for pause_pipe"); 1756 } 1757 1758 if (!(event_add_idle(ev, NULL, 1759 timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0), 1760 "printer_housekeeping", 1761 printer_housekeeping_fn, 1762 NULL))) { 1763 DEBUG(0, ("Could not add printing housekeeping event\n")); 1764 exit(1); 1705 1765 } 1706 1766 … … 2049 2109 2050 2110 /**************************************************************************** 2051 Give the filename used for a jobid.2111 Return the device mode asigned to a specific print job. 2052 2112 Only valid for the process doing the spooling and when the job 2053 2113 has not been spooled. 2054 2114 ****************************************************************************/ 2055 2115 2056 char *print_job_fname(const char* sharename, uint32 jobid) 2057 { 2058 struct printjob *pjob = print_job_find(sharename, jobid); 2059 if (!pjob || pjob->spooled || pjob->pid != sys_getpid()) 2116 struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx, 2117 const char *sharename, 2118 uint32 jobid) 2119 { 2120 struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid); 2121 if (pjob == NULL) { 2060 2122 return NULL; 2061 return pjob->filename; 2062 } 2063 2064 2065 /**************************************************************************** 2066 Give the filename used for a jobid. 2067 Only valid for the process doing the spooling and when the job 2068 has not been spooled. 2069 ****************************************************************************/ 2070 2071 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid) 2072 { 2073 struct printjob *pjob = print_job_find(sharename, jobid); 2074 2075 if ( !pjob ) 2076 return NULL; 2123 } 2077 2124 2078 2125 return pjob->devmode; … … 2088 2135 { 2089 2136 struct printjob *pjob; 2090 2091 pjob = print_job_find(sharename, jobid); 2092 if (!pjob || pjob->pid != sys_getpid()) 2093 return False; 2137 bool ret; 2138 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2139 if (tmp_ctx == NULL) { 2140 return false; 2141 } 2142 2143 pjob = print_job_find(tmp_ctx, sharename, jobid); 2144 if (!pjob || pjob->pid != sys_getpid()) { 2145 ret = false; 2146 goto err_out; 2147 } 2094 2148 2095 2149 fstrcpy(pjob->jobname, name); 2096 return pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2150 ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2151 err_out: 2152 talloc_free(tmp_ctx); 2153 return ret; 2097 2154 } 2098 2155 … … 2105 2162 struct printjob *pjob; 2106 2163 2107 pjob = print_job_find( sharename, jobid);2164 pjob = print_job_find(mem_ctx, sharename, jobid); 2108 2165 if (!pjob || pjob->pid != sys_getpid()) { 2109 2166 return false; 2110 2167 } 2111 2168 2112 *name = talloc_strdup(mem_ctx, pjob->jobname); 2113 if (!*name) { 2114 return false; 2115 } 2116 2169 *name = pjob->jobname; 2117 2170 return true; 2118 2171 } … … 2187 2240 { 2188 2241 const char* sharename = lp_const_servicename(snum); 2189 struct printjob *pjob = print_job_find(sharename, jobid);2242 struct printjob *pjob; 2190 2243 int result = 0; 2191 2244 struct printif *current_printif = get_printer_fns( snum ); 2192 2193 if (!pjob) 2194 return False; 2245 bool ret; 2246 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2247 if (tmp_ctx == NULL) { 2248 return false; 2249 } 2250 2251 pjob = print_job_find(tmp_ctx, sharename, jobid); 2252 if (!pjob) { 2253 ret = false; 2254 goto err_out; 2255 } 2195 2256 2196 2257 /* … … 2198 2259 */ 2199 2260 2200 if (pjob->status == LPQ_DELETING) 2201 return True; 2261 if (pjob->status == LPQ_DELETING) { 2262 ret = true; 2263 goto err_out; 2264 } 2202 2265 2203 2266 /* Hrm - we need to be able to cope with deleting a job before it … … 2229 2292 int njobs = 1; 2230 2293 2231 if (!pdb) 2232 return False; 2294 if (!pdb) { 2295 ret = false; 2296 goto err_out; 2297 } 2233 2298 pjob_delete(ev, msg_ctx, sharename, jobid); 2234 2299 /* Ensure we keep a rough count of the number of total jobs... */ … … 2240 2305 remove_from_jobs_added( sharename, jobid ); 2241 2306 2242 return (result == 0); 2307 ret = (result == 0); 2308 err_out: 2309 talloc_free(tmp_ctx); 2310 return ret; 2243 2311 } 2244 2312 … … 2251 2319 uint32 jobid) 2252 2320 { 2253 struct printjob *pjob = print_job_find(servicename, jobid); 2254 2255 if (!pjob || !server_info) 2256 return False; 2257 2258 return strequal(pjob->user, server_info->sanitized_username); 2321 struct printjob *pjob; 2322 bool ret; 2323 TALLOC_CTX *tmp_ctx = talloc_new(server_info); 2324 if (tmp_ctx == NULL) { 2325 return false; 2326 } 2327 2328 pjob = print_job_find(tmp_ctx, servicename, jobid); 2329 if (!pjob || !server_info) { 2330 ret = false; 2331 goto err_out; 2332 } 2333 2334 ret = strequal(pjob->user, server_info->sanitized_username); 2335 err_out: 2336 talloc_free(tmp_ctx); 2337 return ret; 2259 2338 } 2260 2339 … … 2270 2349 struct printjob *pjob; 2271 2350 bool owner; 2272 char *fname; 2351 WERROR werr; 2352 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2353 if (tmp_ctx == NULL) { 2354 return WERR_NOT_ENOUGH_MEMORY; 2355 } 2273 2356 2274 2357 owner = is_owner(server_info, lp_const_servicename(snum), jobid); … … 2290 2373 /* END_ADMIN_LOG */ 2291 2374 2292 return WERR_ACCESS_DENIED; 2375 werr = WERR_ACCESS_DENIED; 2376 goto err_out; 2293 2377 } 2294 2378 … … 2300 2384 */ 2301 2385 2302 fname = print_job_fname(sharename, jobid); 2303 if (fname != NULL) { 2304 /* remove the spool file */ 2305 DEBUG(10, ("print_job_delete: " 2306 "Removing spool file [%s]\n", fname)); 2307 if (unlink(fname) == -1) { 2308 return map_werror_from_unix(errno); 2386 pjob = print_job_find(tmp_ctx, sharename, jobid); 2387 if (!pjob || pjob->spooled || pjob->pid != getpid()) { 2388 DEBUG(10, ("Skipping spool file removal for job %u\n", jobid)); 2389 } else { 2390 DEBUG(10, ("Removing spool file [%s]\n", pjob->filename)); 2391 if (unlink(pjob->filename) == -1) { 2392 werr = map_werror_from_unix(errno); 2393 goto err_out; 2309 2394 } 2310 2395 } 2311 2396 2312 2397 if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) { 2313 return WERR_ACCESS_DENIED; 2398 werr = WERR_ACCESS_DENIED; 2399 goto err_out; 2314 2400 } 2315 2401 … … 2319 2405 print_queue_update(msg_ctx, snum, True); 2320 2406 2321 pjob = print_job_find( sharename, jobid);2407 pjob = print_job_find(tmp_ctx, sharename, jobid); 2322 2408 if (pjob && (pjob->status != LPQ_DELETING)) { 2323 return WERR_ACCESS_DENIED; 2324 } 2325 2326 return WERR_PRINTER_HAS_JOBS_QUEUED; 2409 werr = WERR_ACCESS_DENIED; 2410 goto err_out; 2411 } 2412 werr = WERR_PRINTER_HAS_JOBS_QUEUED; 2413 2414 err_out: 2415 talloc_free(tmp_ctx); 2416 return werr; 2327 2417 } 2328 2418 … … 2331 2421 ****************************************************************************/ 2332 2422 2333 boolprint_job_pause(const struct auth_serversupplied_info *server_info,2423 WERROR print_job_pause(const struct auth_serversupplied_info *server_info, 2334 2424 struct messaging_context *msg_ctx, 2335 int snum, uint32 jobid , WERROR *errcode)2425 int snum, uint32 jobid) 2336 2426 { 2337 2427 const char* sharename = lp_const_servicename(snum); … … 2339 2429 int ret = -1; 2340 2430 struct printif *current_printif = get_printer_fns( snum ); 2341 2342 pjob = print_job_find(sharename, jobid); 2343 2431 WERROR werr; 2432 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2433 if (tmp_ctx == NULL) { 2434 return WERR_NOT_ENOUGH_MEMORY; 2435 } 2436 2437 pjob = print_job_find(tmp_ctx, sharename, jobid); 2344 2438 if (!pjob || !server_info) { 2345 2439 DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n", 2346 2440 (unsigned int)jobid )); 2347 return False; 2441 werr = WERR_INVALID_PARAM; 2442 goto err_out; 2348 2443 } 2349 2444 … … 2351 2446 DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n", 2352 2447 (int)pjob->sysjob, (unsigned int)jobid )); 2353 return False; 2448 werr = WERR_INVALID_PARAM; 2449 goto err_out; 2354 2450 } 2355 2451 … … 2367 2463 /* END_ADMIN_LOG */ 2368 2464 2369 *errcode= WERR_ACCESS_DENIED;2370 return False;2465 werr = WERR_ACCESS_DENIED; 2466 goto err_out; 2371 2467 } 2372 2468 … … 2375 2471 2376 2472 if (ret != 0) { 2377 *errcode= WERR_INVALID_PARAM;2378 return False;2473 werr = WERR_INVALID_PARAM; 2474 goto err_out; 2379 2475 } 2380 2476 … … 2388 2484 2389 2485 /* how do we tell if this succeeded? */ 2390 2391 return True; 2486 werr = WERR_OK; 2487 err_out: 2488 talloc_free(tmp_ctx); 2489 return werr; 2392 2490 } 2393 2491 … … 2396 2494 ****************************************************************************/ 2397 2495 2398 boolprint_job_resume(const struct auth_serversupplied_info *server_info,2496 WERROR print_job_resume(const struct auth_serversupplied_info *server_info, 2399 2497 struct messaging_context *msg_ctx, 2400 int snum, uint32 jobid , WERROR *errcode)2498 int snum, uint32 jobid) 2401 2499 { 2402 2500 const char *sharename = lp_const_servicename(snum); … … 2404 2502 int ret; 2405 2503 struct printif *current_printif = get_printer_fns( snum ); 2406 2407 pjob = print_job_find(sharename, jobid); 2408 2504 WERROR werr; 2505 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 2506 if (tmp_ctx == NULL) 2507 return WERR_NOT_ENOUGH_MEMORY; 2508 2509 pjob = print_job_find(tmp_ctx, sharename, jobid); 2409 2510 if (!pjob || !server_info) { 2410 2511 DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n", 2411 2512 (unsigned int)jobid )); 2412 return False; 2513 werr = WERR_INVALID_PARAM; 2514 goto err_out; 2413 2515 } 2414 2516 … … 2416 2518 DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n", 2417 2519 (int)pjob->sysjob, (unsigned int)jobid )); 2418 return False; 2520 werr = WERR_INVALID_PARAM; 2521 goto err_out; 2419 2522 } 2420 2523 … … 2423 2526 JOB_ACCESS_ADMINISTER)) { 2424 2527 DEBUG(3, ("resume denied by security descriptor\n")); 2425 *errcode = WERR_ACCESS_DENIED;2426 2528 2427 2529 /* BEGIN_ADMIN_LOG */ … … 2432 2534 lp_printername(snum) ); 2433 2535 /* END_ADMIN_LOG */ 2434 return False; 2536 werr = WERR_ACCESS_DENIED; 2537 goto err_out; 2435 2538 } 2436 2539 … … 2438 2541 2439 2542 if (ret != 0) { 2440 *errcode= WERR_INVALID_PARAM;2441 return False;2543 werr = WERR_INVALID_PARAM; 2544 goto err_out; 2442 2545 } 2443 2546 … … 2450 2553 JOB_STATUS_QUEUED); 2451 2554 2452 return True; 2555 werr = WERR_OK; 2556 err_out: 2557 talloc_free(tmp_ctx); 2558 return werr; 2453 2559 } 2454 2560 … … 2464 2570 ssize_t return_code; 2465 2571 struct printjob *pjob; 2466 2467 pjob = print_job_find(sharename, jobid); 2468 2469 if (!pjob) 2572 TALLOC_CTX *tmp_ctx = talloc_new(ev); 2573 if (tmp_ctx == NULL) { 2470 2574 return -1; 2575 } 2576 2577 pjob = print_job_find(tmp_ctx, sharename, jobid); 2578 if (!pjob) { 2579 return_code = -1; 2580 goto err_out; 2581 } 2582 2471 2583 /* don't allow another process to get this info - it is meaningless */ 2472 if (pjob->pid != sys_getpid()) 2473 return -1; 2584 if (pjob->pid != sys_getpid()) { 2585 return_code = -1; 2586 goto err_out; 2587 } 2474 2588 2475 2589 /* if SMBD is spooling this can't be allowed */ 2476 2590 if (pjob->status == PJOB_SMBD_SPOOLING) { 2477 return -1; 2591 return_code = -1; 2592 goto err_out; 2478 2593 } 2479 2594 2480 2595 return_code = write_data(pjob->fd, buf, size); 2481 2482 if (return_code>0) { 2596 if (return_code > 0) { 2483 2597 pjob->size += size; 2484 2598 pjob_store(ev, msg_ctx, sharename, jobid, pjob); 2485 2599 } 2600 err_out: 2601 talloc_free(tmp_ctx); 2486 2602 return return_code; 2487 2603 } … … 2763 2879 2764 2880 slprintf(pjob->filename, sizeof(pjob->filename)-1, 2765 "%s/%s%.8u.XXXXXX", lp_pathname(snum), 2766 PRINT_SPOOL_PREFIX, (unsigned int)jobid); 2881 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX); 2767 2882 pjob->fd = mkstemp(pjob->filename); 2768 2883 … … 2830 2945 2831 2946 pjob.pid = sys_getpid(); 2947 pjob.jobid = jobid; 2832 2948 pjob.sysjob = -1; 2833 2949 pjob.fd = -1; … … 2894 3010 const char* sharename = lp_const_servicename(snum); 2895 3011 struct printjob *pjob; 2896 2897 pjob = print_job_find(sharename, jobid); 2898 if (!pjob) 3012 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3013 if (tmp_ctx == NULL) { 2899 3014 return; 3015 } 3016 3017 pjob = print_job_find(tmp_ctx, sharename, jobid); 3018 if (!pjob) { 3019 goto err_out; 3020 } 2900 3021 /* don't allow another process to get this info - it is meaningless */ 2901 if (pjob->pid != sys_getpid()) 2902 return; 3022 if (pjob->pid != sys_getpid()) { 3023 goto err_out; 3024 } 2903 3025 2904 3026 pjob->page_count++; 2905 3027 pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob); 3028 err_out: 3029 talloc_free(tmp_ctx); 2906 3030 } 2907 3031 … … 2919 3043 int ret; 2920 3044 SMB_STRUCT_STAT sbuf; 2921 struct printif *current_printif = get_printer_fns( snum);3045 struct printif *current_printif = get_printer_fns(snum); 2922 3046 NTSTATUS status = NT_STATUS_UNSUCCESSFUL; 2923 2924 pjob = print_job_find(sharename, jobid); 2925 3047 char *lpq_cmd; 3048 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3049 if (tmp_ctx == NULL) { 3050 return NT_STATUS_NO_MEMORY; 3051 } 3052 3053 pjob = print_job_find(tmp_ctx, sharename, jobid); 2926 3054 if (!pjob) { 2927 return NT_STATUS_PRINT_CANCELLED; 3055 status = NT_STATUS_PRINT_CANCELLED; 3056 goto err_out; 2928 3057 } 2929 3058 2930 3059 if (pjob->spooled || pjob->pid != sys_getpid()) { 2931 return NT_STATUS_ACCESS_DENIED; 3060 status = NT_STATUS_ACCESS_DENIED; 3061 goto err_out; 2932 3062 } 2933 3063 … … 2983 3113 } 2984 3114 2985 ret = (*(current_printif->job_submit))(snum, pjob); 2986 3115 /* don't strip out characters like '$' from the printername */ 3116 lpq_cmd = talloc_string_sub2(tmp_ctx, 3117 lp_lpqcommand(snum), 3118 "%p", 3119 lp_printername(snum), 3120 false, false, false); 3121 if (lpq_cmd == NULL) { 3122 status = NT_STATUS_PRINT_CANCELLED; 3123 goto fail; 3124 } 3125 lpq_cmd = talloc_sub_advanced(tmp_ctx, 3126 lp_servicename(snum), 3127 current_user_info.unix_name, 3128 "", 3129 current_user.ut.gid, 3130 get_current_username(), 3131 current_user_info.domain, 3132 lpq_cmd); 3133 if (lpq_cmd == NULL) { 3134 status = NT_STATUS_PRINT_CANCELLED; 3135 goto fail; 3136 } 3137 3138 ret = (*(current_printif->job_submit))(snum, pjob, 3139 current_printif->type, lpq_cmd); 2987 3140 if (ret) { 2988 3141 status = NT_STATUS_PRINT_CANCELLED; … … 3009 3162 unlink(pjob->filename); 3010 3163 pjob_delete(server_event_context(), msg_ctx, sharename, jobid); 3164 err_out: 3165 talloc_free(tmp_ctx); 3011 3166 return status; 3012 3167 } … … 3031 3186 bool ret = False; 3032 3187 const char* sharename = lp_servicename(snum); 3188 TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx); 3189 if (tmp_ctx == NULL) { 3190 return false; 3191 } 3033 3192 3034 3193 /* make sure the database is up to date */ … … 3080 3239 queue[i].fs_user, 3081 3240 queue[i].fs_file); 3082 queue[i]. job = qjob;3241 queue[i].sysjob = qjob; 3083 3242 queue[i].size = qsize; 3084 3243 queue[i].page_count = qpage_count; … … 3097 3256 jobid = IVAL(cgdata.dptr, i*4); 3098 3257 DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid)); 3099 pjob = print_job_find( lp_const_servicename(snum), jobid);3258 pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid); 3100 3259 if (!pjob) { 3101 3260 DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid)); … … 3104 3263 } 3105 3264 3106 queue[total_count]. job = jobid;3265 queue[total_count].sysjob = jobid; 3107 3266 queue[total_count].size = pjob->size; 3108 3267 queue[total_count].page_count = pjob->page_count; … … 3113 3272 fstrcpy(queue[total_count].fs_file, pjob->jobname); 3114 3273 total_count++; 3274 talloc_free(pjob); 3115 3275 } 3116 3276 … … 3122 3282 3123 3283 for (j = 0; j < total_count; j++) { 3124 if (queue[j]. job == jobid) {3284 if (queue[j].sysjob == jobid) { 3125 3285 found = true; 3126 3286 break; … … 3134 3294 (unsigned int) jobid)); 3135 3295 3136 pjob = print_job_find( sharename, jobid);3296 pjob = print_job_find(tmp_ctx, sharename, jobid); 3137 3297 if (pjob == NULL) { 3138 3298 DEBUG(5,("get_stored_queue_info: failed to find " … … 3143 3303 } 3144 3304 3145 queue[j]. job = jobid;3305 queue[j].sysjob = jobid; 3146 3306 queue[j].size = pjob->size; 3147 3307 queue[j].page_count = pjob->page_count; … … 3151 3311 fstrcpy(queue[j].fs_user, pjob->user); 3152 3312 fstrcpy(queue[j].fs_file, pjob->jobname); 3313 talloc_free(pjob); 3153 3314 3154 3315 DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n", … … 3178 3339 SAFE_FREE(data.dptr); 3179 3340 SAFE_FREE(cgdata.dptr); 3341 talloc_free(tmp_ctx); 3180 3342 return ret; 3181 3343 } … … 3345 3507 for (i=0;i<njobs;i++) { 3346 3508 bool owner = is_owner(server_info, lp_const_servicename(snum), 3347 queue[i]. job);3509 queue[i].sysjob); 3348 3510 3349 3511 if (owner || can_job_admin) { 3350 3512 print_job_delete1(server_event_context(), msg_ctx, 3351 snum, queue[i]. job);3513 snum, queue[i].sysjob); 3352 3514 } 3353 3515 }
Note:
See TracChangeset
for help on using the changeset viewer.