/[rdesktop]/sourceforge.net/trunk/rdesktop/rdpdr.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/rdpdr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 613 by n-ki, Mon Feb 23 10:34:18 2004 UTC revision 660 by astrand, Fri Apr 16 12:20:56 2004 UTC
# Line 1  Line 1 
1    /* -*- c-basic-offset: 8 -*-
2       rdesktop: A Remote Desktop Protocol client.
3       Copyright (C) Matthew Chapman 1999-2004
4    
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9    
10       This program is distributed in the hope that it will be useful,
11       but WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13       GNU General Public License for more details.
14    
15       You should have received a copy of the GNU General Public License
16       along with this program; if not, write to the Free Software
17       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18    */
19    
20    /*
21      Here are some resources, for your IRP hacking pleasure:
22    
23      http://cvs.sourceforge.net/viewcvs.py/mingw/w32api/include/ddk/winddk.h?view=markup
24    
25      http://win32.mvps.org/ntfs/streams.cpp
26    
27      http://www.acc.umu.se/~bosse/ntifs.h
28    
29      http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/File/
30    
31      http://us1.samba.org/samba/ftp/specs/smb-nt01.txt
32    
33      http://www.osronline.com/
34    */
35    
36  #include <unistd.h>  #include <unistd.h>
37  #include <sys/types.h>  #include <sys/types.h>
38  #include <sys/time.h>  #include <sys/time.h>
39    #include <dirent.h>             /* opendir, closedir, readdir */
40  #include <time.h>  #include <time.h>
41  #include "rdesktop.h"  #include "rdesktop.h"
42    
 #define IRP_MJ_CREATE           0x00  
 #define IRP_MJ_CLOSE            0x02  
 #define IRP_MJ_READ             0x03  
 #define IRP_MJ_WRITE            0x04  
 #define IRP_MJ_DEVICE_CONTROL   0x0e  
   
43  #define IRP_MJ_CREATE                   0x00  #define IRP_MJ_CREATE                   0x00
44  #define IRP_MJ_CLOSE                    0x02  #define IRP_MJ_CLOSE                    0x02
45  #define IRP_MJ_READ                     0x03  #define IRP_MJ_READ                     0x03
# Line 19  Line 49 
49  #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a  #define IRP_MJ_QUERY_VOLUME_INFORMATION 0x0a
50  #define IRP_MJ_DIRECTORY_CONTROL        0x0c  #define IRP_MJ_DIRECTORY_CONTROL        0x0c
51  #define IRP_MJ_DEVICE_CONTROL           0x0e  #define IRP_MJ_DEVICE_CONTROL           0x0e
52    #define IRP_MJ_LOCK_CONTROL             0x11
53    
54  #define IRP_MN_QUERY_DIRECTORY          0x01  #define IRP_MN_QUERY_DIRECTORY          0x01
55  #define IRP_MN_NOTIFY_CHANGE_DIRECTORY  0x02  #define IRP_MN_NOTIFY_CHANGE_DIRECTORY  0x02
# Line 28  extern DEVICE_FNS serial_fns; Line 59  extern DEVICE_FNS serial_fns;
59  extern DEVICE_FNS printer_fns;  extern DEVICE_FNS printer_fns;
60  extern DEVICE_FNS parallel_fns;  extern DEVICE_FNS parallel_fns;
61  extern DEVICE_FNS disk_fns;  extern DEVICE_FNS disk_fns;
62    extern FILEINFO g_fileinfo[];
63    
64  static VCHANNEL *rdpdr_channel;  static VCHANNEL *rdpdr_channel;
65    
# Line 37  uint32 g_num_devices; Line 69  uint32 g_num_devices;
69    
70  /* Table with information about rdpdr devices */  /* Table with information about rdpdr devices */
71  RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];  RDPDR_DEVICE g_rdpdr_device[RDPDR_MAX_DEVICES];
72    char *g_rdpdr_clientname = NULL;
73    
74  /* Used to store incoming io request, until they are ready to be completed */  /* Used to store incoming io request, until they are ready to be completed */
75  /* using a linked list ensures that they are processed in the right order, */  /* using a linked list ensures that they are processed in the right order, */
# Line 79  convert_to_unix_filename(char *filename) Line 112  convert_to_unix_filename(char *filename)
112          }          }
113  }  }
114    
115    BOOL
116    rdpdr_handle_ok(int device, int handle)
117    {
118            switch (g_rdpdr_device[device].device_type)
119            {
120                    case DEVICE_TYPE_PARALLEL:
121                    case DEVICE_TYPE_SERIAL:
122                    case DEVICE_TYPE_PRINTER:
123                    case DEVICE_TYPE_SCARD:
124                            if (g_rdpdr_device[device].handle != handle)
125                                    return False;
126                            break;
127                    case DEVICE_TYPE_DISK:
128                            if (g_fileinfo[handle].device_id != device)
129                                    return False;
130                            break;
131            }
132            return True;
133    }
134    
135  /* Add a new io request to the table containing pending io requests so it won't block rdesktop */  /* Add a new io request to the table containing pending io requests so it won't block rdesktop */
136  BOOL  BOOL
137  add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,  add_async_iorequest(uint32 device, uint32 file, uint32 id, uint32 major, uint32 length,
# Line 146  void Line 199  void
199  rdpdr_send_name(void)  rdpdr_send_name(void)
200  {  {
201          uint8 magic[4] = "rDNC";          uint8 magic[4] = "rDNC";
         uint32 hostlen = (strlen(hostname) + 1) * 2;  
202          STREAM s;          STREAM s;
203            uint32 hostlen;
204    
205            if (NULL == g_rdpdr_clientname)
206            {
207                    g_rdpdr_clientname = hostname;
208            }
209            hostlen = (strlen(g_rdpdr_clientname) + 1) * 2;
210    
211          s = channel_init(rdpdr_channel, 16 + hostlen);          s = channel_init(rdpdr_channel, 16 + hostlen);
212          out_uint8a(s, magic, 4);          out_uint8a(s, magic, 4);
# Line 155  rdpdr_send_name(void) Line 214  rdpdr_send_name(void)
214          out_uint16_le(s, 0x72);          out_uint16_le(s, 0x72);
215          out_uint32(s, 0);          out_uint32(s, 0);
216          out_uint32_le(s, hostlen);          out_uint32_le(s, hostlen);
217          rdp_out_unistr(s, hostname, hostlen - 2);          rdp_out_unistr(s, g_rdpdr_clientname, hostlen - 2);
218          s_mark_end(s);          s_mark_end(s);
219          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
220  }  }
# Line 391  rdpdr_process_irp(STREAM s) Line 450  rdpdr_process_irp(STREAM s)
450  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
451                          DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));                          DEBUG(("RDPDR IRP Read (length: %d, offset: %d)\n", length, offset));
452  #endif  #endif
453                            if (!rdpdr_handle_ok(device, file))
454                            {
455                                    status = STATUS_INVALID_HANDLE;
456                                    break;
457                            }
458    
459                          if (rw_blocking)        // Complete read immediately                          if (rw_blocking)        // Complete read immediately
460                          {                          {
461                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
# Line 438  rdpdr_process_irp(STREAM s) Line 503  rdpdr_process_irp(STREAM s)
503  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
504                          DEBUG(("RDPDR IRP Write (length: %d)\n", result));                          DEBUG(("RDPDR IRP Write (length: %d)\n", result));
505  #endif  #endif
506                            if (!rdpdr_handle_ok(device, file))
507                            {
508                                    status = STATUS_INVALID_HANDLE;
509                                    break;
510                            }
511    
512                          if (rw_blocking)        // Complete immediately                          if (rw_blocking)        // Complete immediately
513                          {                          {
514                                  status = fns->write(file, s->p, length, offset, &result);                                  status = fns->write(file, s->p, length, offset, &result);
# Line 587  rdpdr_process_irp(STREAM s) Line 658  rdpdr_process_irp(STREAM s)
658                          result = buffer_len = out.p - out.data;                          result = buffer_len = out.p - out.data;
659                          break;                          break;
660    
661    
662                    case IRP_MJ_LOCK_CONTROL:
663    
664                            if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
665                            {
666                                    status = STATUS_INVALID_HANDLE;
667                                    break;
668                            }
669    
670                            in_uint32_le(s, info_level);
671    
672                            out.data = out.p = buffer;
673                            out.size = sizeof(buffer);
674                            /* FIXME: Perhaps consider actually *do*
675                               something here :-) */
676                            status = STATUS_SUCCESS;
677                            result = buffer_len = out.p - out.data;
678                            break;
679    
680                  default:                  default:
681                          unimpl("IRP major=0x%x minor=0x%x\n", major, minor);                          unimpl("IRP major=0x%x minor=0x%x\n", major, minor);
682                          break;                          break;
# Line 757  rdpdr_add_fds(int *n, fd_set * rfds, fd_ Line 847  rdpdr_add_fds(int *n, fd_set * rfds, fd_
847          }          }
848  }  }
849    
850    struct async_iorequest *
851    rdpdr_remove_iorequest(struct async_iorequest *prev, struct async_iorequest *iorq)
852    {
853            if (!iorq)
854                    return NULL;
855    
856            if (iorq->buffer)
857                    xfree(iorq->buffer);
858            if (prev)
859            {
860                    prev->next = iorq->next;
861                    xfree(iorq);
862                    iorq = prev->next;
863            }
864            else
865            {
866                    // Even if NULL
867                    g_iorequest = iorq->next;
868                    xfree(iorq);
869                    iorq = NULL;
870            }
871            return iorq;
872    }
873    
874  /* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */  /* Check if select() returned with one of the rdpdr file descriptors, and complete io if it did */
875  void  void
# Line 797  rdpdr_check_fds(fd_set * rfds, fd_set * Line 910  rdpdr_check_fds(fd_set * rfds, fd_set *
910                                                  status = fns->read(iorq->fd,                                                  status = fns->read(iorq->fd,
911                                                                     iorq->buffer + iorq->partial_len,                                                                     iorq->buffer + iorq->partial_len,
912                                                                     req_size, iorq->offset, &result);                                                                     req_size, iorq->offset, &result);
                                                 iorq->partial_len += result;  
                                                 iorq->offset += result;  
913    
914                                                    if (result > 0)
915                                                    {
916                                                            iorq->partial_len += result;
917                                                            iorq->offset += result;
918                                                    }
919  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
920                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));                                                  DEBUG(("RDPDR: %d bytes of data read\n", result));
921  #endif  #endif
# Line 811  rdpdr_check_fds(fd_set * rfds, fd_set * Line 927  rdpdr_check_fds(fd_set * rfds, fd_set *
927  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
928                                                          DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));                                                          DEBUG(("RDPDR: AIO total %u bytes read of %u\n", iorq->partial_len, iorq->length));
929  #endif  #endif
                                                         /* send the data */  
                                                         status = STATUS_SUCCESS;  
930                                                          rdpdr_send_completion(iorq->device,                                                          rdpdr_send_completion(iorq->device,
931                                                                                iorq->id, status,                                                                                iorq->id, status,
932                                                                                iorq->partial_len,                                                                                iorq->partial_len,
933                                                                                iorq->buffer,                                                                                iorq->buffer,
934                                                                                iorq->partial_len);                                                                                iorq->partial_len);
935                                                          xfree(iorq->buffer);                                                          iorq = rdpdr_remove_iorequest(prev, iorq);
                                                         iorq->fd = 0;  
                                                         if (prev != NULL)  
                                                         {  
                                                                 prev->next = iorq->next;  
                                                                 xfree(iorq);  
                                                         }  
                                                         else  
                                                         {  
                                                                 // Even if NULL  
                                                                 g_iorequest = iorq->next;  
                                                                 xfree(iorq);  
                                                         }  
936                                                  }                                                  }
937                                          }                                          }
938                                          break;                                          break;
# Line 850  rdpdr_check_fds(fd_set * rfds, fd_set * Line 952  rdpdr_check_fds(fd_set * rfds, fd_set *
952                                                                      iorq->buffer +                                                                      iorq->buffer +
953                                                                      iorq->partial_len, req_size,                                                                      iorq->partial_len, req_size,
954                                                                      iorq->offset, &result);                                                                      iorq->offset, &result);
955                                                  iorq->partial_len += result;  
956                                                  iorq->offset += result;                                                  if (result > 0)
957                                                    {
958                                                            iorq->partial_len += result;
959                                                            iorq->offset += result;
960                                                    }
961    
962  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
963                                                  DEBUG(("RDPDR: %d bytes of data written\n",                                                  DEBUG(("RDPDR: %d bytes of data written\n",
964                                                         result));                                                         result));
# Line 864  rdpdr_check_fds(fd_set * rfds, fd_set * Line 971  rdpdr_check_fds(fd_set * rfds, fd_set *
971  #if WITH_DEBUG_RDP5  #if WITH_DEBUG_RDP5
972                                                          DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length));                                                          DEBUG(("RDPDR: AIO total %u bytes written of %u\n", iorq->partial_len, iorq->length));
973  #endif  #endif
                                                         /* send a status success */  
                                                         status = STATUS_SUCCESS;  
974                                                          rdpdr_send_completion(iorq->device,                                                          rdpdr_send_completion(iorq->device,
975                                                                                iorq->id, status,                                                                                iorq->id, status,
976                                                                                iorq->partial_len,                                                                                iorq->partial_len,
977                                                                                (uint8 *) "", 1);                                                                                (uint8 *) "", 1);
978    
979                                                          xfree(iorq->buffer);                                                          iorq = rdpdr_remove_iorequest(prev, iorq);
                                                         iorq->fd = 0;  
                                                         if (prev != NULL)  
                                                         {  
                                                                 prev->next = iorq->next;  
                                                                 xfree(iorq);  
                                                         }  
                                                         else  
                                                         {  
                                                                 // Even if NULL  
                                                                 g_iorequest = iorq->next;  
                                                                 xfree(iorq);  
                                                         }  
980                                                  }                                                  }
981                                          }                                          }
982                                          break;                                          break;
# Line 891  rdpdr_check_fds(fd_set * rfds, fd_set * Line 984  rdpdr_check_fds(fd_set * rfds, fd_set *
984    
985                  }                  }
986                  prev = iorq;                  prev = iorq;
987                  iorq = iorq->next;                  if (iorq)
988                            iorq = iorq->next;
989          }          }
990    
991  }  }
# Line 915  rdpdr_abort_io(uint32 fd, uint32 major, Line 1009  rdpdr_abort_io(uint32 fd, uint32 major,
1009                          result = 0;                          result = 0;
1010                          rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "",                          rdpdr_send_completion(iorq->device, iorq->id, status, result, (uint8 *) "",
1011                                                1);                                                1);
1012                          xfree(iorq->buffer);  
1013                          iorq->fd = 0;                          iorq = rdpdr_remove_iorequest(prev, iorq);
                         if (prev != NULL)  
                         {  
                                 prev->next = iorq->next;  
                                 xfree(iorq);  
                         }  
                         else  
                         {  
                                 // Even if NULL  
                                 g_iorequest = iorq->next;  
                                 xfree(iorq);  
                         }  
1014                          return True;                          return True;
1015                  }                  }
1016    

Legend:
Removed from v.613  
changed lines
  Added in v.660

  ViewVC Help
Powered by ViewVC 1.1.26