Enable optional anonymization of user names,
[Samba/ekacnet.git] / source3 / printing / printfsp.c
bloba247cd84276106e7a819bffdc0b9789b15fd0eb3
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
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.
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.
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/>.
21 #include "includes.h"
23 /***************************************************************************
24 open a print file and setup a fsp for it. This is a wrapper around
25 print_job_start().
26 ***************************************************************************/
28 NTSTATUS print_fsp_open(struct smb_request *req, connection_struct *conn,
29 const char *fname,
30 uint16_t current_vuid, files_struct **result)
32 int jobid;
33 SMB_STRUCT_STAT sbuf;
34 files_struct *fsp;
35 fstring name;
36 NTSTATUS status;
38 status = file_new(req, conn, &fsp);
39 if(!NT_STATUS_IS_OK(status)) {
40 return status;
43 fstrcpy( name, "Remote Downlevel Document");
44 if (fname) {
45 const char *p = strrchr(fname, '/');
46 fstrcat(name, " ");
47 if (!p) {
48 p = fname;
50 fstrcat(name, p);
53 jobid = print_job_start(conn->server_info, SNUM(conn), name, NULL);
54 if (jobid == -1) {
55 status = map_nt_error_from_unix(errno);
56 file_free(req, fsp);
57 return status;
60 /* Convert to RAP id. */
61 fsp->rap_print_jobid = pjobid_to_rap(lp_const_servicename(SNUM(conn)), jobid);
62 if (fsp->rap_print_jobid == 0) {
63 /* We need to delete the entry in the tdb. */
64 pjob_delete(lp_const_servicename(SNUM(conn)), jobid);
65 file_free(req, fsp);
66 return NT_STATUS_ACCESS_DENIED; /* No errno around here */
69 /* setup a full fsp */
70 fsp->fh->fd = print_job_fd(lp_const_servicename(SNUM(conn)),jobid);
71 GetTimeOfDay(&fsp->open_time);
72 fsp->vuid = current_vuid;
73 fsp->fh->pos = -1;
74 fsp->can_lock = True;
75 fsp->can_read = False;
76 fsp->access_mask = FILE_GENERIC_WRITE;
77 fsp->can_write = True;
78 fsp->print_file = True;
79 fsp->modified = False;
80 fsp->oplock_type = NO_OPLOCK;
81 fsp->sent_oplock_break = NO_BREAK_SENT;
82 fsp->is_directory = False;
83 string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
84 fsp->wcp = NULL;
85 SMB_VFS_FSTAT(fsp, &sbuf);
86 fsp->mode = sbuf.st_mode;
87 fsp->file_id = vfs_file_id_from_sbuf(conn, &sbuf);
89 conn->num_files_open++;
91 *result = fsp;
92 return NT_STATUS_OK;
95 /****************************************************************************
96 Print a file - called on closing the file.
97 ****************************************************************************/
99 void print_fsp_end(files_struct *fsp, enum file_close_type close_type)
101 uint32 jobid;
102 fstring sharename;
104 if (fsp->fh->private_options & FILE_DELETE_ON_CLOSE) {
106 * Truncate the job. print_job_end will take
107 * care of deleting it for us. JRA.
109 sys_ftruncate(fsp->fh->fd, 0);
112 if (fsp->fsp_name) {
113 string_free(&fsp->fsp_name);
116 if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
117 DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n",
118 (unsigned int)fsp->rap_print_jobid ));
119 return;
122 print_job_end(SNUM(fsp->conn),jobid, close_type);