source: branches/samba-3.2.x/source/printing/printfsp.c

Last change on this file was 232, checked in by Herwig Bauernfeind, 16 years ago

Update 3.2 branch to 3.2.8

File size: 3.4 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 printing backend routines for smbd - using files_struct rather
4 than only snum
5 Copyright (C) Andrew Tridgell 1992-2000
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include "includes.h"
22
23extern struct current_user current_user;
24
25/***************************************************************************
26open a print file and setup a fsp for it. This is a wrapper around
27print_job_start().
28***************************************************************************/
29
30NTSTATUS print_fsp_open(connection_struct *conn, const char *fname,
31 files_struct *fsp, SMB_STRUCT_STAT *psbuf)
32{
33 int jobid;
34 fstring name;
35 NTSTATUS status;
36
37 fstrcpy( name, "Remote Downlevel Document");
38 if (fname) {
39 const char *p = strrchr(fname, '/');
40 fstrcat(name, " ");
41 if (!p) {
42 p = fname;
43 }
44 fstrcat(name, p);
45 }
46
47 jobid = print_job_start(&current_user, SNUM(conn), name, NULL);
48 if (jobid == -1) {
49 status = map_nt_error_from_unix(errno);
50 return status;
51 }
52
53 /* Convert to RAP id. */
54 fsp->rap_print_jobid = pjobid_to_rap(lp_const_servicename(SNUM(conn)), jobid);
55 if (fsp->rap_print_jobid == 0) {
56 /* We need to delete the entry in the tdb. */
57 pjob_delete(lp_const_servicename(SNUM(conn)), jobid);
58 return NT_STATUS_ACCESS_DENIED; /* No errno around here */
59 }
60
61 /* setup a full fsp */
62 fsp->fh->fd = print_job_fd(lp_const_servicename(SNUM(conn)),jobid);
63 GetTimeOfDay(&fsp->open_time);
64 fsp->vuid = current_user.vuid;
65 fsp->fh->pos = -1;
66 fsp->can_lock = True;
67 fsp->can_read = False;
68 fsp->access_mask = FILE_GENERIC_WRITE;
69 fsp->can_write = True;
70 fsp->print_file = True;
71 fsp->modified = False;
72 fsp->oplock_type = NO_OPLOCK;
73 fsp->sent_oplock_break = NO_BREAK_SENT;
74 fsp->is_directory = False;
75 string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
76 fsp->wcp = NULL;
77 SMB_VFS_FSTAT(fsp, psbuf);
78 fsp->mode = psbuf->st_mode;
79 fsp->file_id = vfs_file_id_from_sbuf(conn, psbuf);
80
81 return NT_STATUS_OK;
82}
83
84/****************************************************************************
85 Print a file - called on closing the file.
86****************************************************************************/
87
88void print_fsp_end(files_struct *fsp, enum file_close_type close_type)
89{
90 uint32 jobid;
91 fstring sharename;
92
93 if (fsp->fh->private_options & FILE_DELETE_ON_CLOSE) {
94 /*
95 * Truncate the job. print_job_end will take
96 * care of deleting it for us. JRA.
97 */
98 sys_ftruncate(fsp->fh->fd, 0);
99 }
100
101 if (fsp->fsp_name) {
102 string_free(&fsp->fsp_name);
103 }
104
105 if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
106 DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n",
107 (unsigned int)fsp->rap_print_jobid ));
108 return;
109 }
110
111 print_job_end(SNUM(fsp->conn),jobid, close_type);
112}
Note: See TracBrowser for help on using the repository browser.