s3-winbind: Implemented samr backend function common_enum_local_groups.
[Samba/gebeck_regimport.git] / source3 / printing / printfsp.c
blob5bb662e10f976e02b3b3efb2eff3af246c9f58fd
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 *fsp)
32 const char *svcname = lp_const_servicename(SNUM(conn));
33 int jobid;
34 fstring name;
35 NTSTATUS status;
37 fstrcpy( name, "Remote Downlevel Document");
38 if (fname) {
39 const char *p = strrchr(fname, '/');
40 fstrcat(name, " ");
41 if (!p) {
42 p = fname;
44 fstrcat(name, p);
47 jobid = print_job_start(conn->server_info, SNUM(conn), name, NULL);
48 if (jobid == -1) {
49 status = map_nt_error_from_unix(errno);
50 return status;
53 fsp->print_file = talloc(fsp, struct print_file_data);
54 if (!fsp->print_file) {
55 status = map_nt_error_from_unix(ENOMEM);
56 return status;
59 /* Convert to RAP id. */
60 fsp->print_file->rap_jobid = pjobid_to_rap(svcname, jobid);
61 if (fsp->print_file->rap_jobid == 0) {
62 /* We need to delete the entry in the tdb. */
63 pjob_delete(svcname, jobid);
64 return NT_STATUS_ACCESS_DENIED; /* No errno around here */
67 status = create_synthetic_smb_fname(fsp,
68 print_job_fname(svcname, jobid), NULL,
69 NULL, &fsp->fsp_name);
70 if (!NT_STATUS_IS_OK(status)) {
71 pjob_delete(svcname, jobid);
72 return status;
74 /* setup a full fsp */
75 fsp->fh->fd = print_job_fd(svcname, jobid);
76 GetTimeOfDay(&fsp->open_time);
77 fsp->vuid = current_vuid;
78 fsp->fh->pos = -1;
79 fsp->can_lock = False;
80 fsp->can_read = False;
81 fsp->access_mask = FILE_GENERIC_WRITE;
82 fsp->can_write = True;
83 fsp->modified = False;
84 fsp->oplock_type = NO_OPLOCK;
85 fsp->sent_oplock_break = NO_BREAK_SENT;
86 fsp->is_directory = False;
87 fsp->wcp = NULL;
88 SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
89 fsp->mode = fsp->fsp_name->st.st_ex_mode;
90 fsp->file_id = vfs_file_id_from_sbuf(conn, &fsp->fsp_name->st);
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;
103 if (fsp->fh->private_options & NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE) {
105 * Truncate the job. print_job_end will take
106 * care of deleting it for us. JRA.
108 sys_ftruncate(fsp->fh->fd, 0);
111 if (fsp->fsp_name) {
112 TALLOC_FREE(fsp->fsp_name);
115 if (!rap_to_pjobid(fsp->print_file->rap_jobid, NULL, &jobid)) {
116 DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n",
117 (unsigned int)fsp->print_file->rap_jobid ));
118 return;
121 print_job_end(SNUM(fsp->conn),jobid, close_type);
124 /****************************************************************************
125 Discovered by Sebastian Kloska <oncaphillis@snafu.de>. When print files
126 go beyond 4GB, the 32-bit offset sent in old SMBwrite calls is relative
127 to the current 4GB chunk we're writing to.
128 ****************************************************************************/
130 SMB_OFF_T printfile_offset(files_struct *fsp, SMB_OFF_T offset)
132 SMB_STRUCT_STAT st;
134 if (offset & 0xffffffff00000000LL) {
135 /* offset is > 4G, skip */
136 return offset;
139 if (sys_fstat(fsp->fh->fd, &st, false) == -1) {
140 DEBUG(3,("printfile_offset: sys_fstat failed on %s (%s)\n",
141 fsp_str_dbg(fsp),
142 strerror(errno) ));
143 return offset;
146 return (st.st_ex_size & 0xffffffff00000000LL) + offset;