2000-04-23 07:51:15 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
2000-04-23 07:51:15 +00:00
printing backend routines for smbd - using files_struct rather
than only snum
Copyright ( C ) Andrew Tridgell 1992 - 2000
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
2000-04-23 07:51:15 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2000-04-23 07:51:15 +00:00
*/
# include "includes.h"
/***************************************************************************
open a print file and setup a fsp for it . This is a wrapper around
print_job_start ( ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2008-10-09 15:38:53 +02:00
NTSTATUS print_fsp_open ( struct smb_request * req , connection_struct * conn ,
const char * fname ,
2009-11-17 14:55:02 -08:00
uint16_t current_vuid , files_struct * fsp )
2000-04-23 07:51:15 +00:00
{
int jobid ;
2002-01-25 20:16:14 +00:00
fstring name ;
2006-07-11 18:01:26 +00:00
NTSTATUS status ;
2000-04-23 07:51:15 +00:00
2002-01-25 20:16:14 +00:00
fstrcpy ( name , " Remote Downlevel Document " ) ;
if ( fname ) {
2005-07-08 04:51:27 +00:00
const char * p = strrchr ( fname , ' / ' ) ;
2002-01-25 20:16:14 +00:00
fstrcat ( name , " " ) ;
2005-07-08 04:51:27 +00:00
if ( ! p ) {
2002-01-25 20:16:14 +00:00
p = fname ;
2005-07-08 04:51:27 +00:00
}
2002-01-25 20:16:14 +00:00
fstrcat ( name , p ) ;
}
2008-06-24 16:03:28 +02:00
jobid = print_job_start ( conn - > server_info , SNUM ( conn ) , name , NULL ) ;
2000-04-23 07:51:15 +00:00
if ( jobid = = - 1 ) {
2006-07-11 18:01:26 +00:00
status = map_nt_error_from_unix ( errno ) ;
return status ;
2000-04-23 07:51:15 +00:00
}
2002-12-05 04:00:16 +00:00
/* Convert to RAP id. */
2004-10-19 17:05:01 +00:00
fsp - > rap_print_jobid = pjobid_to_rap ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
2002-12-05 04:00:16 +00:00
if ( fsp - > rap_print_jobid = = 0 ) {
2002-12-05 22:32:15 +00:00
/* We need to delete the entry in the tdb. */
2004-10-19 17:05:01 +00:00
pjob_delete ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
2006-07-11 18:01:26 +00:00
return NT_STATUS_ACCESS_DENIED ; /* No errno around here */
2002-12-05 04:00:16 +00:00
}
2009-07-10 18:11:32 -07:00
status = create_synthetic_smb_fname ( fsp ,
print_job_fname ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) , NULL ,
NULL , & fsp - > fsp_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
pjob_delete ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
return status ;
}
2000-04-23 07:51:15 +00:00
/* setup a full fsp */
2005-07-08 04:51:27 +00:00
fsp - > fh - > fd = print_job_fd ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
2000-04-23 07:51:15 +00:00
GetTimeOfDay ( & fsp - > open_time ) ;
2008-06-24 16:58:29 +02:00
fsp - > vuid = current_vuid ;
2005-07-08 04:51:27 +00:00
fsp - > fh - > pos = - 1 ;
2000-04-23 07:51:15 +00:00
fsp - > can_lock = True ;
fsp - > can_read = False ;
2005-07-08 04:51:27 +00:00
fsp - > access_mask = FILE_GENERIC_WRITE ;
2000-04-23 07:51:15 +00:00
fsp - > can_write = True ;
fsp - > print_file = True ;
fsp - > modified = False ;
fsp - > oplock_type = NO_OPLOCK ;
fsp - > sent_oplock_break = NO_BREAK_SENT ;
fsp - > is_directory = False ;
2008-11-21 12:14:53 -08:00
fsp - > wcp = NULL ;
2009-11-17 14:55:02 -08:00
SMB_VFS_FSTAT ( fsp , & fsp - > fsp_name - > st ) ;
fsp - > mode = fsp - > fsp_name - > st . st_ex_mode ;
fsp - > file_id = vfs_file_id_from_sbuf ( conn , & fsp - > fsp_name - > st ) ;
2000-04-23 07:51:15 +00:00
2006-07-11 18:01:26 +00:00
return NT_STATUS_OK ;
2000-04-23 07:51:15 +00:00
}
/****************************************************************************
2005-07-08 04:51:27 +00:00
Print a file - called on closing the file .
2000-04-23 07:51:15 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-07-08 04:51:27 +00:00
2006-02-02 20:44:50 +00:00
void print_fsp_end ( files_struct * fsp , enum file_close_type close_type )
2000-04-23 07:51:15 +00:00
{
2002-12-05 04:00:16 +00:00
uint32 jobid ;
2005-07-08 04:51:27 +00:00
if ( fsp - > fh - > private_options & FILE_DELETE_ON_CLOSE ) {
2001-02-22 01:31:55 +00:00
/*
* Truncate the job . print_job_end will take
* care of deleting it for us . JRA .
*/
2005-07-08 04:51:27 +00:00
sys_ftruncate ( fsp - > fh - > fd , 0 ) ;
2001-02-22 01:31:55 +00:00
}
2000-04-23 07:51:15 +00:00
if ( fsp - > fsp_name ) {
2009-07-10 18:11:32 -07:00
TALLOC_FREE ( fsp - > fsp_name ) ;
2000-04-23 07:51:15 +00:00
}
2002-12-05 04:00:16 +00:00
2009-03-01 11:39:44 +01:00
if ( ! rap_to_pjobid ( fsp - > rap_print_jobid , NULL , & jobid ) ) {
2002-12-05 04:00:16 +00:00
DEBUG ( 3 , ( " print_fsp_end: Unable to convert RAP jobid %u to print jobid. \n " ,
( unsigned int ) fsp - > rap_print_jobid ) ) ;
return ;
}
2006-02-02 20:44:50 +00:00
print_job_end ( SNUM ( fsp - > conn ) , jobid , close_type ) ;
2000-04-23 07:51:15 +00:00
}