if we are adding a new sambaAccount, make sure that we add a
[Samba.git] / source / printing / printfsp.c
blob4f9b649185d38569b095b9448ed6cfc638bf82ea
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
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.
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.
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.
23 #include "includes.h"
25 /***************************************************************************
26 open a print file and setup a fsp for it. This is a wrapper around
27 print_job_start().
28 ***************************************************************************/
30 files_struct *print_fsp_open(connection_struct *conn, char *fname)
32 int jobid;
33 SMB_STRUCT_STAT sbuf;
34 extern struct current_user current_user;
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 char *p = strrchr(fname, '/');
44 fstrcat(name, " ");
45 if (!p)
46 p = fname;
47 fstrcat(name, p);
50 jobid = print_job_start(&current_user, SNUM(conn), name);
51 if (jobid == -1) {
52 file_free(fsp);
53 return NULL;
56 /* setup a full fsp */
57 fsp->print_jobid = jobid;
58 fsp->fd = print_job_fd(jobid);
59 GetTimeOfDay(&fsp->open_time);
60 fsp->vuid = current_user.vuid;
61 fsp->size = 0;
62 fsp->pos = -1;
63 fsp->can_lock = True;
64 fsp->can_read = False;
65 fsp->can_write = True;
66 fsp->share_mode = 0;
67 fsp->print_file = True;
68 fsp->modified = False;
69 fsp->oplock_type = NO_OPLOCK;
70 fsp->sent_oplock_break = NO_BREAK_SENT;
71 fsp->is_directory = False;
72 fsp->directory_delete_on_close = False;
73 fsp->conn = conn;
74 string_set(&fsp->fsp_name,print_job_fname(jobid));
75 fsp->wbmpx_ptr = NULL;
76 fsp->wcp = NULL;
77 conn->vfs_ops.fstat(fsp,fsp->fd, &sbuf);
78 fsp->mode = sbuf.st_mode;
79 fsp->inode = sbuf.st_ino;
80 fsp->dev = sbuf.st_dev;
82 conn->num_files_open++;
84 return fsp;
87 /****************************************************************************
88 print a file - called on closing the file
89 ****************************************************************************/
90 void print_fsp_end(files_struct *fsp, BOOL normal_close)
92 if (fsp->share_mode == FILE_DELETE_ON_CLOSE) {
94 * Truncate the job. print_job_end will take
95 * care of deleting it for us. JRA.
97 sys_ftruncate(fsp->fd, 0);
100 print_job_end(fsp->print_jobid, normal_close);
102 if (fsp->fsp_name) {
103 string_free(&fsp->fsp_name);