s3: piddir creation fix part 2.
[ira/wip.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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20   this implements the print backend, called by the NTVFS subsystem to
21   handle requests on printing shares
22 */
23
24 #include "includes.h"
25 #include "../libcli/smb/smb_constants.h"
26 #include "ntvfs/ntvfs.h"
27 #include "param/param.h"
28
29 NTSTATUS ntvfs_print_init(void);
30
31 /*
32   connect to a share - used when a tree_connect operation comes
33   in. For printing shares this should check that the spool directory
34   is available
35 */
36 static NTSTATUS print_connect(struct ntvfs_module_context *ntvfs,
37                               struct ntvfs_request *req, union smb_tcon* tcon)
38 {
39         ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
40         NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
41
42         ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "LPT1:");
43         NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
44
45         if (tcon->generic.level == RAW_TCON_TCONX) {
46                 tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
47                 tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
48         }
49
50         return NT_STATUS_OK;
51 }
52
53 /*
54   disconnect from a share
55 */
56 static NTSTATUS print_disconnect(struct ntvfs_module_context *ntvfs)
57 {
58         return NT_STATUS_OK;
59 }
60
61 /*
62   lots of operations are not allowed on printing shares - mostly return NT_STATUS_ACCESS_DENIED
63 */
64 static NTSTATUS print_unlink(struct ntvfs_module_context *ntvfs,
65                              struct ntvfs_request *req,
66                              union smb_unlink *unl)
67 {
68         return NT_STATUS_ACCESS_DENIED;
69 }
70
71
72 /*
73   ioctl - used for job query
74 */
75 static NTSTATUS print_ioctl(struct ntvfs_module_context *ntvfs,
76                             struct ntvfs_request *req, union smb_ioctl *io)
77 {
78         char *p;
79
80         if (io->generic.level != RAW_IOCTL_IOCTL) {
81                 return NT_STATUS_NOT_IMPLEMENTED;
82         }
83
84         if (io->ioctl.in.request == IOCTL_QUERY_JOB_INFO) {
85
86                 /* a request for the print job id of an open print job */
87                 io->ioctl.out.blob = data_blob_talloc(req, NULL, 32);
88
89                 data_blob_clear(&io->ioctl.out.blob);
90
91                 p = (char *)io->ioctl.out.blob.data;
92                 SSVAL(p,0, 1 /* REWRITE: fsp->rap_print_jobid */);
93                 push_string(p+2, lpcfg_netbios_name(ntvfs->ctx->lp_ctx), 15, STR_TERMINATE|STR_ASCII);
94                 push_string(p+18, ntvfs->ctx->config->name, 13, STR_TERMINATE|STR_ASCII);
95                 return NT_STATUS_OK;
96         }
97
98         return NT_STATUS_INVALID_PARAMETER;
99 }
100
101
102 /*
103   initialialise the print backend, registering ourselves with the ntvfs subsystem
104  */
105 NTSTATUS ntvfs_print_init(void)
106 {
107         NTSTATUS ret;
108         struct ntvfs_ops ops;
109         NTVFS_CURRENT_CRITICAL_SIZES(vers);
110
111         ZERO_STRUCT(ops);
112
113         /* fill in the name and type */
114         ops.name = "default";
115         ops.type = NTVFS_PRINT;
116         
117         /* fill in all the operations */
118         ops.connect = print_connect;
119         ops.disconnect = print_disconnect;
120         ops.unlink = print_unlink;
121         ops.ioctl = print_ioctl;
122
123         /* register ourselves with the NTVFS subsystem. We register under the name 'default'
124            as we wish to be the default backend */
125         ret = ntvfs_register(&ops, &vers);
126
127         if (!NT_STATUS_IS_OK(ret)) {
128                 DEBUG(0,("Failed to register PRINT backend!\n"));
129         }
130
131         return ret;
132 }