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