r15543: New implementation of 'net ads join' to be more like Windows XP.
[Samba/nascimento.git] / source3 / printing / printfsp.c
blobc248851822b8242d83ce98446b79da0f69e85009
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 extern struct current_user current_user;
26 /***************************************************************************
27 open a print file and setup a fsp for it. This is a wrapper around
28 print_job_start().
29 ***************************************************************************/
31 files_struct *print_fsp_open(connection_struct *conn, const char *fname)
33 int jobid;
34 SMB_STRUCT_STAT sbuf;
35 files_struct *fsp = file_new(conn);
36 fstring name;
38 if(!fsp)
39 return NULL;
41 fstrcpy( name, "Remote Downlevel Document");
42 if (fname) {
43 const char *p = strrchr(fname, '/');
44 fstrcat(name, " ");
45 if (!p) {
46 p = fname;
48 fstrcat(name, p);
51 jobid = print_job_start(&current_user, SNUM(conn), name, NULL);
52 if (jobid == -1) {
53 file_free(fsp);
54 return NULL;
57 /* Convert to RAP id. */
58 fsp->rap_print_jobid = pjobid_to_rap(lp_const_servicename(SNUM(conn)), jobid);
59 if (fsp->rap_print_jobid == 0) {
60 /* We need to delete the entry in the tdb. */
61 pjob_delete(lp_const_servicename(SNUM(conn)), jobid);
62 file_free(fsp);
63 return NULL;
66 /* setup a full fsp */
67 fsp->fh->fd = print_job_fd(lp_const_servicename(SNUM(conn)),jobid);
68 GetTimeOfDay(&fsp->open_time);
69 fsp->vuid = current_user.vuid;
70 fsp->fh->pos = -1;
71 fsp->can_lock = True;
72 fsp->can_read = False;
73 fsp->access_mask = FILE_GENERIC_WRITE;
74 fsp->can_write = True;
75 fsp->print_file = True;
76 fsp->modified = False;
77 fsp->oplock_type = NO_OPLOCK;
78 fsp->sent_oplock_break = NO_BREAK_SENT;
79 fsp->is_directory = False;
80 string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
81 fsp->wbmpx_ptr = NULL;
82 fsp->wcp = NULL;
83 SMB_VFS_FSTAT(fsp,fsp->fh->fd, &sbuf);
84 fsp->mode = sbuf.st_mode;
85 fsp->inode = sbuf.st_ino;
86 fsp->dev = sbuf.st_dev;
88 conn->num_files_open++;
90 return fsp;
93 /****************************************************************************
94 Print a file - called on closing the file.
95 ****************************************************************************/
97 void print_fsp_end(files_struct *fsp, enum file_close_type close_type)
99 uint32 jobid;
100 fstring sharename;
102 if (fsp->fh->private_options & FILE_DELETE_ON_CLOSE) {
104 * Truncate the job. print_job_end will take
105 * care of deleting it for us. JRA.
107 sys_ftruncate(fsp->fh->fd, 0);
110 if (fsp->fsp_name) {
111 string_free(&fsp->fsp_name);
114 if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
115 DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n",
116 (unsigned int)fsp->rap_print_jobid ));
117 return;
120 print_job_end(SNUM(fsp->conn),jobid, close_type);