2000-04-23 11:51:15 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2000-04-23 11:51:15 +04: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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2005-04-06 20:28:04 +04:00
extern struct current_user current_user ;
2000-04-23 11:51:15 +04:00
/***************************************************************************
open a print file and setup a fsp for it . This is a wrapper around
print_job_start ( ) .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2006-07-11 22:01:26 +04:00
NTSTATUS print_fsp_open ( connection_struct * conn , const char * fname ,
files_struct * * result )
2000-04-23 11:51:15 +04:00
{
int jobid ;
SMB_STRUCT_STAT sbuf ;
2006-07-11 22:01:26 +04:00
files_struct * fsp ;
2002-01-25 23:16:14 +03:00
fstring name ;
2006-07-11 22:01:26 +04:00
NTSTATUS status ;
2000-04-23 11:51:15 +04:00
2006-07-11 22:01:26 +04:00
status = file_new ( conn , & fsp ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2000-04-23 11:51:15 +04:00
2002-01-25 23:16:14 +03:00
fstrcpy ( name , " Remote Downlevel Document " ) ;
if ( fname ) {
2005-07-08 08:51:27 +04:00
const char * p = strrchr ( fname , ' / ' ) ;
2002-01-25 23:16:14 +03:00
fstrcat ( name , " " ) ;
2005-07-08 08:51:27 +04:00
if ( ! p ) {
2002-01-25 23:16:14 +03:00
p = fname ;
2005-07-08 08:51:27 +04:00
}
2002-01-25 23:16:14 +03:00
fstrcat ( name , p ) ;
}
2002-09-25 19:19:00 +04:00
jobid = print_job_start ( & current_user , SNUM ( conn ) , name , NULL ) ;
2000-04-23 11:51:15 +04:00
if ( jobid = = - 1 ) {
2006-07-11 22:01:26 +04:00
status = map_nt_error_from_unix ( errno ) ;
2000-04-23 11:51:15 +04:00
file_free ( fsp ) ;
2006-07-11 22:01:26 +04:00
return status ;
2000-04-23 11:51:15 +04:00
}
2002-12-05 07:00:16 +03:00
/* Convert to RAP id. */
2004-10-19 21:05:01 +04:00
fsp - > rap_print_jobid = pjobid_to_rap ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
2002-12-05 07:00:16 +03:00
if ( fsp - > rap_print_jobid = = 0 ) {
2002-12-06 01:32:15 +03:00
/* We need to delete the entry in the tdb. */
2004-10-19 21:05:01 +04:00
pjob_delete ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
2002-12-05 07:00:16 +03:00
file_free ( fsp ) ;
2006-07-11 22:01:26 +04:00
return NT_STATUS_ACCESS_DENIED ; /* No errno around here */
2002-12-05 07:00:16 +03:00
}
2000-04-23 11:51:15 +04:00
/* setup a full fsp */
2005-07-08 08:51:27 +04:00
fsp - > fh - > fd = print_job_fd ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ;
2000-04-23 11:51:15 +04:00
GetTimeOfDay ( & fsp - > open_time ) ;
fsp - > vuid = current_user . vuid ;
2005-07-08 08:51:27 +04:00
fsp - > fh - > pos = - 1 ;
2000-04-23 11:51:15 +04:00
fsp - > can_lock = True ;
fsp - > can_read = False ;
2005-07-08 08:51:27 +04:00
fsp - > access_mask = FILE_GENERIC_WRITE ;
2000-04-23 11:51:15 +04: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 ;
2004-10-19 21:05:01 +04:00
string_set ( & fsp - > fsp_name , print_job_fname ( lp_const_servicename ( SNUM ( conn ) ) , jobid ) ) ;
2001-11-17 06:19:17 +03:00
fsp - > wbmpx_ptr = NULL ;
2000-04-23 11:51:15 +04:00
fsp - > wcp = NULL ;
2005-07-08 08:51:27 +04:00
SMB_VFS_FSTAT ( fsp , fsp - > fh - > fd , & sbuf ) ;
2000-10-06 07:21:49 +04:00
fsp - > mode = sbuf . st_mode ;
fsp - > inode = sbuf . st_ino ;
fsp - > dev = sbuf . st_dev ;
2000-04-23 11:51:15 +04:00
conn - > num_files_open + + ;
2006-07-11 22:01:26 +04:00
* result = fsp ;
return NT_STATUS_OK ;
2000-04-23 11:51:15 +04:00
}
/****************************************************************************
2005-07-08 08:51:27 +04:00
Print a file - called on closing the file .
2000-04-23 11:51:15 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2005-07-08 08:51:27 +04:00
2006-02-02 23:44:50 +03:00
void print_fsp_end ( files_struct * fsp , enum file_close_type close_type )
2000-04-23 11:51:15 +04:00
{
2002-12-05 07:00:16 +03:00
uint32 jobid ;
2004-10-19 21:05:01 +04:00
fstring sharename ;
2002-12-05 07:00:16 +03:00
2005-07-08 08:51:27 +04:00
if ( fsp - > fh - > private_options & FILE_DELETE_ON_CLOSE ) {
2001-02-22 04:31:55 +03:00
/*
* Truncate the job . print_job_end will take
* care of deleting it for us . JRA .
*/
2005-07-08 08:51:27 +04:00
sys_ftruncate ( fsp - > fh - > fd , 0 ) ;
2001-02-22 04:31:55 +03:00
}
2000-04-23 11:51:15 +04:00
if ( fsp - > fsp_name ) {
string_free ( & fsp - > fsp_name ) ;
}
2002-12-05 07:00:16 +03:00
2004-10-19 21:05:01 +04:00
if ( ! rap_to_pjobid ( fsp - > rap_print_jobid , sharename , & jobid ) ) {
2002-12-05 07:00:16 +03: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 23:44:50 +03:00
print_job_end ( SNUM ( fsp - > conn ) , jobid , close_type ) ;
2000-04-23 11:51:15 +04:00
}