r14456: don't access the smbsrv_tcon inside the ntvfs modules
[metze/samba-autobuild/.git] / source4 / ntvfs / print / vfs_print.c
1 /* 
2    Unix SMB/CIFS implementation.
3    default print NTVFS backend
4    Copyright (C) Andrew Tridgell  2003
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 /*
21   this implements the print backend, called by the NTVFS subsystem to
22   handle requests on printing shares
23 */
24
25 #include "includes.h"
26 #include "libcli/raw/ioctl.h"
27 #include "smb_server/smb_server.h"
28 #include "ntvfs/ntvfs.h"
29
30 /*
31   connect to a share - used when a tree_connect operation comes
32   in. For printing shares this should check that the spool directory
33   is available
34 */
35 static NTSTATUS print_connect(struct ntvfs_module_context *ntvfs,
36                               struct ntvfs_request *req, const char *sharename)
37 {
38         ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
39         NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
40
41         ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "LPT1:");
42         NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
43
44         return NT_STATUS_OK;
45 }
46
47 /*
48   disconnect from a share
49 */
50 static NTSTATUS print_disconnect(struct ntvfs_module_context *ntvfs)
51 {
52         return NT_STATUS_OK;
53 }
54
55 /*
56   lots of operations are not allowed on printing shares - mostly return NT_STATUS_ACCESS_DENIED
57 */
58 static NTSTATUS print_unlink(struct ntvfs_module_context *ntvfs,
59                              struct ntvfs_request *req,
60                              union smb_unlink *unl)
61 {
62         return NT_STATUS_ACCESS_DENIED;
63 }
64
65
66 /*
67   ioctl - used for job query
68 */
69 static NTSTATUS print_ioctl(struct ntvfs_module_context *ntvfs,
70                             struct ntvfs_request *req, union smb_ioctl *io)
71 {
72         char *p;
73
74         if (io->generic.level != RAW_IOCTL_IOCTL) {
75                 return NT_STATUS_NOT_IMPLEMENTED;
76         }
77
78         if (io->ioctl.in.request == IOCTL_QUERY_JOB_INFO) {
79                 int snum = ntvfs->ctx->config.snum;
80
81                 /* a request for the print job id of an open print job */
82                 io->ioctl.out.blob = data_blob_talloc(req, NULL, 32);
83
84                 data_blob_clear(&io->ioctl.out.blob);
85
86                 p = (char *)io->ioctl.out.blob.data;
87                 SSVAL(p,0, 1 /* REWRITE: fsp->rap_print_jobid */);
88                 push_string(p+2, lp_netbios_name(), 15, STR_TERMINATE|STR_ASCII);
89                 push_string(p+18, lp_servicename(snum), 13, STR_TERMINATE|STR_ASCII);
90                 return NT_STATUS_OK;
91         }
92
93         return NT_STATUS_INVALID_PARAMETER;
94 }
95
96
97 /*
98   initialialise the print backend, registering ourselves with the ntvfs subsystem
99  */
100 NTSTATUS ntvfs_print_init(void)
101 {
102         NTSTATUS ret;
103         struct ntvfs_ops ops;
104
105         ZERO_STRUCT(ops);
106
107         /* fill in the name and type */
108         ops.name = "default";
109         ops.type = NTVFS_PRINT;
110         
111         /* fill in all the operations */
112         ops.connect = print_connect;
113         ops.disconnect = print_disconnect;
114         ops.unlink = print_unlink;
115         ops.ioctl = print_ioctl;
116
117         /* register ourselves with the NTVFS subsystem. We register under the name 'default'
118            as we wish to be the default backend */
119         ret = ntvfs_register(&ops);
120
121         if (!NT_STATUS_IS_OK(ret)) {
122                 DEBUG(0,("Failed to register PRINT backend!\n"));
123         }
124
125         return ret;
126 }