00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "includes.h"
00023
00024 extern struct current_user current_user;
00025
00026
00027
00028
00029
00030
00031 NTSTATUS print_fsp_open(connection_struct *conn, const char *fname,
00032 files_struct **result)
00033 {
00034 int jobid;
00035 SMB_STRUCT_STAT sbuf;
00036 files_struct *fsp;
00037 fstring name;
00038 NTSTATUS status;
00039
00040 status = file_new(conn, &fsp);
00041 if(!NT_STATUS_IS_OK(status)) {
00042 return status;
00043 }
00044
00045 fstrcpy( name, "Remote Downlevel Document");
00046 if (fname) {
00047 const char *p = strrchr(fname, '/');
00048 fstrcat(name, " ");
00049 if (!p) {
00050 p = fname;
00051 }
00052 fstrcat(name, p);
00053 }
00054
00055 jobid = print_job_start(¤t_user, SNUM(conn), name, NULL);
00056 if (jobid == -1) {
00057 status = map_nt_error_from_unix(errno);
00058 file_free(fsp);
00059 return status;
00060 }
00061
00062
00063 fsp->rap_print_jobid = pjobid_to_rap(lp_const_servicename(SNUM(conn)), jobid);
00064 if (fsp->rap_print_jobid == 0) {
00065
00066 pjob_delete(lp_const_servicename(SNUM(conn)), jobid);
00067 file_free(fsp);
00068 return NT_STATUS_ACCESS_DENIED;
00069 }
00070
00071
00072 fsp->fh->fd = print_job_fd(lp_const_servicename(SNUM(conn)),jobid);
00073 GetTimeOfDay(&fsp->open_time);
00074 fsp->vuid = current_user.vuid;
00075 fsp->fh->pos = -1;
00076 fsp->can_lock = True;
00077 fsp->can_read = False;
00078 fsp->access_mask = FILE_GENERIC_WRITE;
00079 fsp->can_write = True;
00080 fsp->print_file = True;
00081 fsp->modified = False;
00082 fsp->oplock_type = NO_OPLOCK;
00083 fsp->sent_oplock_break = NO_BREAK_SENT;
00084 fsp->is_directory = False;
00085 string_set(&fsp->fsp_name,print_job_fname(lp_const_servicename(SNUM(conn)),jobid));
00086 fsp->wbmpx_ptr = NULL;
00087 fsp->wcp = NULL;
00088 SMB_VFS_FSTAT(fsp,fsp->fh->fd, &sbuf);
00089 fsp->mode = sbuf.st_mode;
00090 fsp->inode = sbuf.st_ino;
00091 fsp->dev = sbuf.st_dev;
00092
00093 conn->num_files_open++;
00094
00095 *result = fsp;
00096 return NT_STATUS_OK;
00097 }
00098
00099
00100
00101
00102
00103 void print_fsp_end(files_struct *fsp, enum file_close_type close_type)
00104 {
00105 uint32 jobid;
00106 fstring sharename;
00107
00108 if (fsp->fh->private_options & FILE_DELETE_ON_CLOSE) {
00109
00110
00111
00112
00113 sys_ftruncate(fsp->fh->fd, 0);
00114 }
00115
00116 if (fsp->fsp_name) {
00117 string_free(&fsp->fsp_name);
00118 }
00119
00120 if (!rap_to_pjobid(fsp->rap_print_jobid, sharename, &jobid)) {
00121 DEBUG(3,("print_fsp_end: Unable to convert RAP jobid %u to print jobid.\n",
00122 (unsigned int)fsp->rap_print_jobid ));
00123 return;
00124 }
00125
00126 print_job_end(SNUM(fsp->conn),jobid, close_type);
00127 }