Link the tools and the server against libwine so we can use the
[wine] / server / smb.c
1 /*
2  * Server-side smb network file management
3  *
4  * Copyright (C) 1998 Alexandre Julliard
5  * Copyright (C) 2000, 2001, 2002 Mike McCormack
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  * FIXME: if you can't find something to fix, 
22  *          you're not looking hard enough
23  */
24
25 #include "config.h"
26
27 #include <assert.h>
28 #include <fcntl.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <errno.h>
33 #ifdef HAVE_SYS_ERRNO_H
34 #include <sys/errno.h>
35 #endif
36 #include <sys/time.h>
37 #include <sys/types.h>
38 #include <time.h>
39 #include <unistd.h>
40 #include <utime.h>
41 #include <termios.h>
42 #include <sys/ioctl.h>
43
44 #include "winerror.h"
45 #include "winbase.h"
46
47 #include "handle.h"
48 #include "thread.h"
49 #include "request.h"
50
51 static void smb_dump( struct object *obj, int verbose );
52 static int smb_get_fd( struct object *obj );
53 static int smb_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags );
54 static int smb_get_poll_events( struct object *obj );
55 static void destroy_smb(struct object *obj);
56
57 struct smb
58 {
59     struct object       obj;
60     unsigned int        tree_id;
61     unsigned int        user_id;
62     unsigned int        dialect;
63     unsigned int        file_id;
64     unsigned int        offset;
65 };
66
67 static const struct object_ops smb_ops =
68 {
69     sizeof(struct smb),        /* size */
70     smb_dump,                  /* dump */
71     default_poll_add_queue,    /* add_queue */
72     default_poll_remove_queue, /* remove_queue */
73     default_poll_signaled,     /* signaled */
74     no_satisfied,              /* satisfied */
75     smb_get_poll_events,       /* get_poll_events */
76     default_poll_event,        /* poll_event */
77     smb_get_fd,                /* get_fd */
78     no_flush,                  /* flush */
79     smb_get_info,              /* get_file_info */
80     NULL,                      /* queue_async */
81     destroy_smb                /* destroy */
82 };
83
84 static void destroy_smb( struct object *obj)
85 {
86     /* struct smb *smb = (struct smb *)obj; */
87     assert( obj->ops == &smb_ops );
88 }
89
90 static void smb_dump( struct object *obj, int verbose )
91 {
92     struct smb *smb = (struct smb *)obj;
93     assert( obj->ops == &smb_ops );
94     fprintf( stderr, "smb file with socket fd=%d \n", smb->obj.fd );
95 }
96
97 struct smb *get_smb_obj( struct process *process, handle_t handle, unsigned int access )
98 {
99     return (struct smb *)get_handle_obj( process, handle, access, &smb_ops );
100 }
101
102 static int smb_get_poll_events( struct object *obj )
103 {
104     /* struct smb *smb = (struct smb *)obj; */
105     int events = 0;
106     assert( obj->ops == &smb_ops );
107
108     events |= POLLIN;
109
110     /* fprintf(stderr,"poll events are %04x\n",events); */
111
112     return events;
113 }
114
115 static int smb_get_fd( struct object *obj )
116 {
117     struct smb *smb = (struct smb *)obj;
118     assert( obj->ops == &smb_ops );
119     return smb->obj.fd;
120 }
121
122 static int smb_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags )
123 {
124     /* struct smb *smb = (struct smb *) obj; */
125     assert( obj->ops == &smb_ops );
126
127     if (reply)
128     {
129         reply->type        = FILE_TYPE_CHAR;
130         reply->attr        = 0;
131         reply->access_time = 0;
132         reply->write_time  = 0;
133         reply->size_high   = 0;
134         reply->size_low    = 0;
135         reply->links       = 0;
136         reply->index_high  = 0;
137         reply->index_low   = 0;
138         reply->serial      = 0;
139     }
140
141     *flags = 0;
142
143     return FD_TYPE_SMB;
144 }
145
146 /* create a smb */
147 DECL_HANDLER(create_smb)
148 {
149     struct smb *smb;
150     int fd;
151
152     reply->handle = 0;
153
154     fd = thread_get_inflight_fd( current, req->fd );
155     if (fd == -1)
156     {
157         set_error( STATUS_INVALID_HANDLE );
158         return;
159     }
160
161     smb = alloc_object( &smb_ops, fd );
162     if (smb)
163     {
164         smb->tree_id = req->tree_id;
165         smb->user_id = req->user_id;
166         smb->dialect = req->dialect;
167         smb->file_id = req->file_id;
168         smb->offset = 0;
169         reply->handle = alloc_handle( current->process, smb, GENERIC_READ, 0);
170         release_object( smb );
171     }
172 }
173
174 DECL_HANDLER(get_smb_info)
175 {
176     struct smb *smb;
177
178     if ((smb = get_smb_obj( current->process, req->handle, 0 )))
179     {
180         if(req->flags & SMBINFO_SET_OFFSET)
181             smb->offset = req->offset;
182
183         reply->tree_id = smb->tree_id;
184         reply->user_id = smb->user_id;
185         reply->dialect = smb->dialect;
186         reply->file_id = smb->file_id;
187         reply->offset  = smb->offset;
188
189         release_object( smb );
190     }
191 }
192