/[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 948 by astrand, Tue Aug 2 09:45:11 2005 UTC revision 1365 by jsorg71, Thu Jan 4 05:39:39 2007 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Copyright (C) Matthew Chapman 1999-2005     Copyright (C) Matthew Chapman 1999-2007
4    
5     This program is free software; you can redistribute it and/or modify     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     it under the terms of the GNU General Public License as published by
# Line 60  extern DEVICE_FNS serial_fns; Line 60  extern DEVICE_FNS serial_fns;
60  extern DEVICE_FNS printer_fns;  extern DEVICE_FNS printer_fns;
61  extern DEVICE_FNS parallel_fns;  extern DEVICE_FNS parallel_fns;
62  extern DEVICE_FNS disk_fns;  extern DEVICE_FNS disk_fns;
63    #ifdef WITH_SCARD
64    extern DEVICE_FNS scard_fns;
65    #endif
66  extern FILEINFO g_fileinfo[];  extern FILEINFO g_fileinfo[];
67  extern BOOL g_notify_stamp;  extern BOOL g_notify_stamp;
68    
69  static VCHANNEL *rdpdr_channel;  static VCHANNEL *rdpdr_channel;
70    
71  /* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */  /* If select() times out, the request for the device with handle g_min_timeout_fd is aborted */
72  NTHANDLE g_min_timeout_fd;  RD_NTHANDLE g_min_timeout_fd;
73  uint32 g_num_devices;  uint32 g_num_devices;
74    
75  /* Table with information about rdpdr devices */  /* Table with information about rdpdr devices */
# Line 91  struct async_iorequest *g_iorequest; Line 94  struct async_iorequest *g_iorequest;
94    
95  /* Return device_id for a given handle */  /* Return device_id for a given handle */
96  int  int
97  get_device_index(NTHANDLE handle)  get_device_index(RD_NTHANDLE handle)
98  {  {
99          int i;          int i;
100          for (i = 0; i < RDPDR_MAX_DEVICES; i++)          for (i = 0; i < RDPDR_MAX_DEVICES; i++)
# Line 309  rdpdr_send_available(void) Line 312  rdpdr_send_available(void)
312          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
313  }  }
314    
315  static void  void
316  rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer,  rdpdr_send_completion(uint32 device, uint32 id, uint32 status, uint32 result, uint8 * buffer,
317                        uint32 length)                        uint32 length)
318  {  {
319          uint8 magic[4] = "rDCI";          uint8 magic[4] = "rDCI";
320          STREAM s;          STREAM s;
321    
322    #ifdef WITH_SCARD
323            scard_lock(SCARD_LOCK_RDPDR);
324    #endif
325          s = channel_init(rdpdr_channel, 20 + length);          s = channel_init(rdpdr_channel, 20 + length);
326          out_uint8a(s, magic, 4);          out_uint8a(s, magic, 4);
327          out_uint32_le(s, device);          out_uint32_le(s, device);
# Line 330  rdpdr_send_completion(uint32 device, uin Line 336  rdpdr_send_completion(uint32 device, uin
336          /* hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */          /* hexdump(s->channel_hdr + 8, s->end - s->channel_hdr - 8); */
337  #endif  #endif
338          channel_send(s, rdpdr_channel);          channel_send(s, rdpdr_channel);
339    #ifdef WITH_SCARD
340            scard_unlock(SCARD_LOCK_RDPDR);
341    #endif
342  }  }
343    
344  static void  static void
# Line 352  rdpdr_process_irp(STREAM s) Line 361  rdpdr_process_irp(STREAM s)
361                  error_mode,                  error_mode,
362                  share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0;                  share_mode, disposition, total_timeout, interval_timeout, flags_and_attributes = 0;
363    
364          char filename[256];          char filename[PATH_MAX];
365          uint8 *buffer, *pst_buf;          uint8 *buffer, *pst_buf;
366          struct stream out;          struct stream out;
367          DEVICE_FNS *fns;          DEVICE_FNS *fns;
368          BOOL rw_blocking = True;          BOOL rw_blocking = True;
369          NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST;          RD_NTSTATUS status = RD_STATUS_INVALID_DEVICE_REQUEST;
370    
371          in_uint32_le(s, device);          in_uint32_le(s, device);
372          in_uint32_le(s, file);          in_uint32_le(s, file);
# Line 395  rdpdr_process_irp(STREAM s) Line 404  rdpdr_process_irp(STREAM s)
404                          break;                          break;
405    
406                  case DEVICE_TYPE_SCARD:                  case DEVICE_TYPE_SCARD:
407    #ifdef WITH_SCARD
408                            fns = &scard_fns;
409                            rw_blocking = False;
410                            break;
411    #endif
412                  default:                  default:
413    
414                          error("IRP for bad device %ld\n", device);                          error("IRP for bad device %ld\n", device);
# Line 425  rdpdr_process_irp(STREAM s) Line 439  rdpdr_process_irp(STREAM s)
439    
440                          if (!fns->create)                          if (!fns->create)
441                          {                          {
442                                  status = STATUS_NOT_SUPPORTED;                                  status = RD_STATUS_NOT_SUPPORTED;
443                                  break;                                  break;
444                          }                          }
445    
# Line 437  rdpdr_process_irp(STREAM s) Line 451  rdpdr_process_irp(STREAM s)
451                  case IRP_MJ_CLOSE:                  case IRP_MJ_CLOSE:
452                          if (!fns->close)                          if (!fns->close)
453                          {                          {
454                                  status = STATUS_NOT_SUPPORTED;                                  status = RD_STATUS_NOT_SUPPORTED;
455                                  break;                                  break;
456                          }                          }
457    
# Line 448  rdpdr_process_irp(STREAM s) Line 462  rdpdr_process_irp(STREAM s)
462    
463                          if (!fns->read)                          if (!fns->read)
464                          {                          {
465                                  status = STATUS_NOT_SUPPORTED;                                  status = RD_STATUS_NOT_SUPPORTED;
466                                  break;                                  break;
467                          }                          }
468    
# Line 459  rdpdr_process_irp(STREAM s) Line 473  rdpdr_process_irp(STREAM s)
473  #endif  #endif
474                          if (!rdpdr_handle_ok(device, file))                          if (!rdpdr_handle_ok(device, file))
475                          {                          {
476                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
477                                  break;                                  break;
478                          }                          }
479    
# Line 468  rdpdr_process_irp(STREAM s) Line 482  rdpdr_process_irp(STREAM s)
482                                  buffer = (uint8 *) xrealloc((void *) buffer, length);                                  buffer = (uint8 *) xrealloc((void *) buffer, length);
483                                  if (!buffer)                                  if (!buffer)
484                                  {                                  {
485                                          status = STATUS_CANCELLED;                                          status = RD_STATUS_CANCELLED;
486                                          break;                                          break;
487                                  }                                  }
488                                  status = fns->read(file, buffer, length, offset, &result);                                  status = fns->read(file, buffer, length, offset, &result);
# Line 480  rdpdr_process_irp(STREAM s) Line 494  rdpdr_process_irp(STREAM s)
494                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
495                          if (!pst_buf)                          if (!pst_buf)
496                          {                          {
497                                  status = STATUS_CANCELLED;                                  status = RD_STATUS_CANCELLED;
498                                  break;                                  break;
499                          }                          }
500                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);                          serial_get_timeout(file, length, &total_timeout, &interval_timeout);
# Line 488  rdpdr_process_irp(STREAM s) Line 502  rdpdr_process_irp(STREAM s)
502                              (device, file, id, major, length, fns, total_timeout, interval_timeout,                              (device, file, id, major, length, fns, total_timeout, interval_timeout,
503                               pst_buf, offset))                               pst_buf, offset))
504                          {                          {
505                                  status = STATUS_PENDING;                                  status = RD_STATUS_PENDING;
506                                  break;                                  break;
507                          }                          }
508    
509                          status = STATUS_CANCELLED;                          status = RD_STATUS_CANCELLED;
510                          break;                          break;
511                  case IRP_MJ_WRITE:                  case IRP_MJ_WRITE:
512    
# Line 500  rdpdr_process_irp(STREAM s) Line 514  rdpdr_process_irp(STREAM s)
514    
515                          if (!fns->write)                          if (!fns->write)
516                          {                          {
517                                  status = STATUS_NOT_SUPPORTED;                                  status = RD_STATUS_NOT_SUPPORTED;
518                                  break;                                  break;
519                          }                          }
520    
# Line 512  rdpdr_process_irp(STREAM s) Line 526  rdpdr_process_irp(STREAM s)
526  #endif  #endif
527                          if (!rdpdr_handle_ok(device, file))                          if (!rdpdr_handle_ok(device, file))
528                          {                          {
529                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
530                                  break;                                  break;
531                          }                          }
532    
# Line 526  rdpdr_process_irp(STREAM s) Line 540  rdpdr_process_irp(STREAM s)
540                          pst_buf = (uint8 *) xmalloc(length);                          pst_buf = (uint8 *) xmalloc(length);
541                          if (!pst_buf)                          if (!pst_buf)
542                          {                          {
543                                  status = STATUS_CANCELLED;                                  status = RD_STATUS_CANCELLED;
544                                  break;                                  break;
545                          }                          }
546    
# Line 535  rdpdr_process_irp(STREAM s) Line 549  rdpdr_process_irp(STREAM s)
549                          if (add_async_iorequest                          if (add_async_iorequest
550                              (device, file, id, major, length, fns, 0, 0, pst_buf, offset))                              (device, file, id, major, length, fns, 0, 0, pst_buf, offset))
551                          {                          {
552                                  status = STATUS_PENDING;                                  status = RD_STATUS_PENDING;
553                                  break;                                  break;
554                          }                          }
555    
556                          status = STATUS_CANCELLED;                          status = RD_STATUS_CANCELLED;
557                          break;                          break;
558    
559                  case IRP_MJ_QUERY_INFORMATION:                  case IRP_MJ_QUERY_INFORMATION:
560    
561                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
562                          {                          {
563                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
564                                  break;                                  break;
565                          }                          }
566                          in_uint32_le(s, info_level);                          in_uint32_le(s, info_level);
# Line 562  rdpdr_process_irp(STREAM s) Line 576  rdpdr_process_irp(STREAM s)
576    
577                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
578                          {                          {
579                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
580                                  break;                                  break;
581                          }                          }
582    
# Line 578  rdpdr_process_irp(STREAM s) Line 592  rdpdr_process_irp(STREAM s)
592    
593                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
594                          {                          {
595                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
596                                  break;                                  break;
597                          }                          }
598    
# Line 594  rdpdr_process_irp(STREAM s) Line 608  rdpdr_process_irp(STREAM s)
608    
609                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
610                          {                          {
611                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
612                                  break;                                  break;
613                          }                          }
614    
# Line 636  rdpdr_process_irp(STREAM s) Line 650  rdpdr_process_irp(STREAM s)
650                                          status = disk_create_notify(file, info_level);                                          status = disk_create_notify(file, info_level);
651                                          result = 0;                                          result = 0;
652    
653                                          if (status == STATUS_PENDING)                                          if (status == RD_STATUS_PENDING)
654                                                  add_async_iorequest(device, file, id, major, length,                                                  add_async_iorequest(device, file, id, major, length,
655                                                                      fns, 0, 0, NULL, 0);                                                                      fns, 0, 0, NULL, 0);
656                                          break;                                          break;
657    
658                                  default:                                  default:
659    
660                                          status = STATUS_INVALID_PARAMETER;                                          status = RD_STATUS_INVALID_PARAMETER;
661                                          /* JIF */                                          /* JIF */
662                                          unimpl("IRP major=0x%x minor=0x%x\n", major, minor);                                          unimpl("IRP major=0x%x minor=0x%x\n", major, minor);
663                          }                          }
# Line 653  rdpdr_process_irp(STREAM s) Line 667  rdpdr_process_irp(STREAM s)
667    
668                          if (!fns->device_control)                          if (!fns->device_control)
669                          {                          {
670                                  status = STATUS_NOT_SUPPORTED;                                  status = RD_STATUS_NOT_SUPPORTED;
671                                  break;                                  break;
672                          }                          }
673    
# Line 665  rdpdr_process_irp(STREAM s) Line 679  rdpdr_process_irp(STREAM s)
679                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);                          buffer = (uint8 *) xrealloc((void *) buffer, bytes_out + 0x14);
680                          if (!buffer)                          if (!buffer)
681                          {                          {
682                                  status = STATUS_CANCELLED;                                  status = RD_STATUS_CANCELLED;
683                                  break;                                  break;
684                          }                          }
685    
686                          out.data = out.p = buffer;                          out.data = out.p = buffer;
687                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
688    
689                            DEBUG_SCARD(("[SMART-CARD TRACE]\n"));
690                            DEBUG_SCARD(("device 0x%.8x\n", device));
691                            DEBUG_SCARD(("file   0x%.8x\n", file));
692                            DEBUG_SCARD(("id     0x%.8x\n", id));
693    #ifdef WITH_SCARD
694                            scardSetInfo(device, id, bytes_out + 0x14);
695    #endif
696                          status = fns->device_control(file, request, s, &out);                          status = fns->device_control(file, request, s, &out);
697                          result = buffer_len = out.p - out.data;                          result = buffer_len = out.p - out.data;
698    
699                            DEBUG_SCARD(("[SMART-CARD TRACE] OUT 0x%.8x\n", status));
700    
701                          /* Serial SERIAL_WAIT_ON_MASK */                          /* Serial SERIAL_WAIT_ON_MASK */
702                          if (status == STATUS_PENDING)                          if (status == RD_STATUS_PENDING)
703                          {                          {
704                                  if (add_async_iorequest                                  if (add_async_iorequest
705                                      (device, file, id, major, length, fns, 0, 0, NULL, 0))                                      (device, file, id, major, length, fns, 0, 0, NULL, 0))
706                                  {                                  {
707                                          status = STATUS_PENDING;                                          status = RD_STATUS_PENDING;
708                                          break;                                          break;
709                                  }                                  }
710                          }                          }
711    #ifdef WITH_SCARD
712                            else if (status == (RD_STATUS_PENDING | 0xC0000000))
713                                    status = RD_STATUS_PENDING;
714    #endif
715                          break;                          break;
716    
717    
# Line 691  rdpdr_process_irp(STREAM s) Line 719  rdpdr_process_irp(STREAM s)
719    
720                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)                          if (g_rdpdr_device[device].device_type != DEVICE_TYPE_DISK)
721                          {                          {
722                                  status = STATUS_INVALID_HANDLE;                                  status = RD_STATUS_INVALID_HANDLE;
723                                  break;                                  break;
724                          }                          }
725    
# Line 701  rdpdr_process_irp(STREAM s) Line 729  rdpdr_process_irp(STREAM s)
729                          out.size = sizeof(buffer);                          out.size = sizeof(buffer);
730                          /* FIXME: Perhaps consider actually *do*                          /* FIXME: Perhaps consider actually *do*
731                             something here :-) */                             something here :-) */
732                          status = STATUS_SUCCESS;                          status = RD_STATUS_SUCCESS;
733                          result = buffer_len = out.p - out.data;                          result = buffer_len = out.p - out.data;
734                          break;                          break;
735    
# Line 710  rdpdr_process_irp(STREAM s) Line 738  rdpdr_process_irp(STREAM s)
738                          break;                          break;
739          }          }
740    
741          if (status != STATUS_PENDING)          if (status != RD_STATUS_PENDING)
742          {          {
743                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);                  rdpdr_send_completion(device, id, status, result, buffer, buffer_len);
744          }          }
# Line 932  rdpdr_remove_iorequest(struct async_iore Line 960  rdpdr_remove_iorequest(struct async_iore
960  static void  static void
961  _rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)  _rdpdr_check_fds(fd_set * rfds, fd_set * wfds, BOOL timed_out)
962  {  {
963          NTSTATUS status;          RD_NTSTATUS status;
964          uint32 result = 0;          uint32 result = 0;
965          DEVICE_FNS *fns;          DEVICE_FNS *fns;
966          struct async_iorequest *iorq;          struct async_iorequest *iorq;
# Line 961  _rdpdr_check_fds(fd_set * rfds, fd_set * Line 989  _rdpdr_check_fds(fd_set * rfds, fd_set *
989                                          /* iv_timeout between 2 chars, send partial_len */                                          /* iv_timeout between 2 chars, send partial_len */
990                                          /*printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length); */                                          /*printf("RDPDR: IVT total %u bytes read of %u\n", iorq->partial_len, iorq->length); */
991                                          rdpdr_send_completion(iorq->device,                                          rdpdr_send_completion(iorq->device,
992                                                                iorq->id, STATUS_SUCCESS,                                                                iorq->id, RD_STATUS_SUCCESS,
993                                                                iorq->partial_len,                                                                iorq->partial_len,
994                                                                iorq->buffer, iorq->partial_len);                                                                iorq->buffer, iorq->partial_len);
995                                          iorq = rdpdr_remove_iorequest(prev, iorq);                                          iorq = rdpdr_remove_iorequest(prev, iorq);
# Line 985  _rdpdr_check_fds(fd_set * rfds, fd_set * Line 1013  _rdpdr_check_fds(fd_set * rfds, fd_set *
1013    
1014                  }                  }
1015    
1016                  rdpdr_abort_io(g_min_timeout_fd, 0, STATUS_TIMEOUT);                  rdpdr_abort_io(g_min_timeout_fd, 0, RD_STATUS_TIMEOUT);
1017                  return;                  return;
1018          }          }
1019    
# Line 1089  _rdpdr_check_fds(fd_set * rfds, fd_set * Line 1117  _rdpdr_check_fds(fd_set * rfds, fd_set *
1117                                                  out.size = sizeof(buffer);                                                  out.size = sizeof(buffer);
1118                                                  out_uint32_le(&out, result);                                                  out_uint32_le(&out, result);
1119                                                  result = buffer_len = out.p - out.data;                                                  result = buffer_len = out.p - out.data;
1120                                                  status = STATUS_SUCCESS;                                                  status = RD_STATUS_SUCCESS;
1121                                                  rdpdr_send_completion(iorq->device, iorq->id,                                                  rdpdr_send_completion(iorq->device, iorq->id,
1122                                                                        status, result, buffer,                                                                        status, result, buffer,
1123                                                                        buffer_len);                                                                        buffer_len);
# Line 1125  _rdpdr_check_fds(fd_set * rfds, fd_set * Line 1153  _rdpdr_check_fds(fd_set * rfds, fd_set *
1153                                                  {                                                  {
1154                                                          g_notify_stamp = False;                                                          g_notify_stamp = False;
1155                                                          status = disk_check_notify(iorq->fd);                                                          status = disk_check_notify(iorq->fd);
1156                                                          if (status != STATUS_PENDING)                                                          if (status != RD_STATUS_PENDING)
1157                                                          {                                                          {
1158                                                                  rdpdr_send_completion(iorq->device,                                                                  rdpdr_send_completion(iorq->device,
1159                                                                                        iorq->id,                                                                                        iorq->id,
# Line 1170  rdpdr_check_fds(fd_set * rfds, fd_set * Line 1198  rdpdr_check_fds(fd_set * rfds, fd_set *
1198    
1199  /* Abort a pending io request for a given handle and major */  /* Abort a pending io request for a given handle and major */
1200  BOOL  BOOL
1201  rdpdr_abort_io(uint32 fd, uint32 major, NTSTATUS status)  rdpdr_abort_io(uint32 fd, uint32 major, RD_NTSTATUS status)
1202  {  {
1203          uint32 result;          uint32 result;
1204          struct async_iorequest *iorq;          struct async_iorequest *iorq;

Legend:
Removed from v.948  
changed lines
  Added in v.1365

  ViewVC Help
Powered by ViewVC 1.1.26