Removed mktemp from HEAD - same as done in 2.2.
[tprouty/samba.git] / source3 / printing / printfsp.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    printing backend routines for smbd - using files_struct rather
5    than only snum
6    Copyright (C) Andrew Tridgell 1992-2000
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 extern int DEBUGLEVEL;
25
26
27 /***************************************************************************
28 open a print file and setup a fsp for it. This is a wrapper around
29 print_job_start().
30 ***************************************************************************/
31
32 files_struct *print_fsp_open(connection_struct *conn)
33 {
34         int jobid;
35         SMB_STRUCT_STAT sbuf;
36         extern struct current_user current_user;
37         files_struct *fsp = file_new(conn);
38
39         if(!fsp)
40                 return NULL;
41
42         jobid = print_job_start(&current_user, SNUM(conn), "smb.prn");
43         if (jobid == -1) {
44                 file_free(fsp);
45                 return NULL;
46         }
47
48         /* setup a full fsp */
49         fsp->print_jobid = jobid;
50         fsp->fd = print_job_fd(jobid);
51         GetTimeOfDay(&fsp->open_time);
52         fsp->vuid = current_user.vuid;
53         fsp->size = 0;
54         fsp->pos = -1;
55         fsp->can_lock = True;
56         fsp->can_read = False;
57         fsp->can_write = True;
58         fsp->share_mode = 0;
59         fsp->print_file = True;
60         fsp->modified = False;
61         fsp->oplock_type = NO_OPLOCK;
62         fsp->sent_oplock_break = NO_BREAK_SENT;
63         fsp->is_directory = False;
64         fsp->stat_open = False;
65         fsp->directory_delete_on_close = False;
66         fsp->conn = conn;
67         string_set(&fsp->fsp_name,print_job_fname(jobid));
68         fsp->wbmpx_ptr = NULL;      
69         fsp->wcp = NULL; 
70         conn->vfs_ops.fstat(fsp,fsp->fd, &sbuf);
71         fsp->mode = sbuf.st_mode;
72         fsp->inode = sbuf.st_ino;
73         fsp->dev = sbuf.st_dev;
74
75         conn->num_files_open++;
76
77         return fsp;
78 }
79
80 /****************************************************************************
81 print a file - called on closing the file
82 ****************************************************************************/
83 void print_fsp_end(files_struct *fsp, BOOL normal_close)
84 {
85         if (fsp->share_mode == FILE_DELETE_ON_CLOSE) {
86                 /*
87                  * Truncate the job. print_job_end will take
88                  * care of deleting it for us. JRA.
89                  */
90                 sys_ftruncate(fsp->fd, 0);
91         }
92
93         print_job_end(fsp->print_jobid, normal_close);
94
95         if (fsp->fsp_name) {
96                 string_free(&fsp->fsp_name);
97         }
98 }