cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

rdpdr-fs-messages-dir-info.c (8615B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include "channels/rdpdr/rdpdr-fs-messages-dir-info.h"
     21#include "channels/rdpdr/rdpdr.h"
     22#include "fs.h"
     23#include "unicode.h"
     24
     25#include <guacamole/client.h>
     26#include <guacamole/unicode.h>
     27#include <winpr/nt.h>
     28#include <winpr/stream.h>
     29
     30#include <stddef.h>
     31#include <stddef.h>
     32
     33void guac_rdpdr_fs_process_query_directory_info(guac_rdp_common_svc* svc,
     34        guac_rdpdr_device* device, guac_rdpdr_iorequest* iorequest,
     35        const char* entry_name, int entry_file_id) {
     36
     37    guac_rdp_fs_file* file;
     38
     39    wStream* output_stream;
     40    int length = guac_utf8_strlen(entry_name);
     41    int utf16_length = length*2;
     42
     43    unsigned char utf16_entry_name[256];
     44    guac_rdp_utf8_to_utf16((const unsigned char*) entry_name, length,
     45            (char*) utf16_entry_name, sizeof(utf16_entry_name));
     46
     47    /* Get file */
     48    file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, entry_file_id);
     49    if (file == NULL)
     50        return;
     51
     52    guac_client_log(svc->client, GUAC_LOG_DEBUG,
     53            "%s: [file_id=%i (entry_name=\"%s\")]",
     54            __func__, entry_file_id, entry_name);
     55
     56    output_stream = guac_rdpdr_new_io_completion(device,
     57            iorequest->completion_id, STATUS_SUCCESS,
     58            4 + 64 + utf16_length + 2);
     59
     60    Stream_Write_UINT32(output_stream,
     61            64 + utf16_length + 2); /* Length */
     62
     63    Stream_Write_UINT32(output_stream, 0); /* NextEntryOffset */
     64    Stream_Write_UINT32(output_stream, 0); /* FileIndex */
     65    Stream_Write_UINT64(output_stream, file->ctime); /* CreationTime */
     66    Stream_Write_UINT64(output_stream, file->atime); /* LastAccessTime */
     67    Stream_Write_UINT64(output_stream, file->mtime); /* LastWriteTime */
     68    Stream_Write_UINT64(output_stream, file->mtime); /* ChangeTime */
     69    Stream_Write_UINT64(output_stream, file->size);  /* EndOfFile */
     70    Stream_Write_UINT64(output_stream, file->size);  /* AllocationSize */
     71    Stream_Write_UINT32(output_stream, file->attributes);   /* FileAttributes */
     72    Stream_Write_UINT32(output_stream, utf16_length+2); /* FileNameLength*/
     73
     74    Stream_Write(output_stream, utf16_entry_name, utf16_length); /* FileName */
     75    Stream_Write(output_stream, "\0\0", 2);
     76
     77    guac_rdp_common_svc_write(svc, output_stream);
     78
     79}
     80
     81void guac_rdpdr_fs_process_query_full_directory_info(guac_rdp_common_svc* svc,
     82        guac_rdpdr_device* device, guac_rdpdr_iorequest* iorequest,
     83        const char* entry_name, int entry_file_id) {
     84
     85    guac_rdp_fs_file* file;
     86
     87    wStream* output_stream;
     88    int length = guac_utf8_strlen(entry_name);
     89    int utf16_length = length*2;
     90
     91    unsigned char utf16_entry_name[256];
     92    guac_rdp_utf8_to_utf16((const unsigned char*) entry_name, length,
     93            (char*) utf16_entry_name, sizeof(utf16_entry_name));
     94
     95    /* Get file */
     96    file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, entry_file_id);
     97    if (file == NULL)
     98        return;
     99
    100    guac_client_log(svc->client, GUAC_LOG_DEBUG,
    101            "%s: [file_id=%i (entry_name=\"%s\")]",
    102            __func__, entry_file_id, entry_name);
    103
    104    output_stream = guac_rdpdr_new_io_completion(device,
    105            iorequest->completion_id, STATUS_SUCCESS,
    106            4 + 68 + utf16_length + 2);
    107
    108    Stream_Write_UINT32(output_stream,
    109            68 + utf16_length + 2); /* Length */
    110
    111    Stream_Write_UINT32(output_stream, 0); /* NextEntryOffset */
    112    Stream_Write_UINT32(output_stream, 0); /* FileIndex */
    113    Stream_Write_UINT64(output_stream, file->ctime); /* CreationTime */
    114    Stream_Write_UINT64(output_stream, file->atime); /* LastAccessTime */
    115    Stream_Write_UINT64(output_stream, file->mtime); /* LastWriteTime */
    116    Stream_Write_UINT64(output_stream, file->mtime); /* ChangeTime */
    117    Stream_Write_UINT64(output_stream, file->size);  /* EndOfFile */
    118    Stream_Write_UINT64(output_stream, file->size);  /* AllocationSize */
    119    Stream_Write_UINT32(output_stream, file->attributes);   /* FileAttributes */
    120    Stream_Write_UINT32(output_stream, utf16_length+2); /* FileNameLength*/
    121    Stream_Write_UINT32(output_stream, 0); /* EaSize */
    122
    123    Stream_Write(output_stream, utf16_entry_name, utf16_length); /* FileName */
    124    Stream_Write(output_stream, "\0\0", 2);
    125
    126    guac_rdp_common_svc_write(svc, output_stream);
    127
    128}
    129
    130void guac_rdpdr_fs_process_query_both_directory_info(guac_rdp_common_svc* svc,
    131        guac_rdpdr_device* device, guac_rdpdr_iorequest* iorequest,
    132        const char* entry_name, int entry_file_id) {
    133
    134    guac_rdp_fs_file* file;
    135
    136    wStream* output_stream;
    137    int length = guac_utf8_strlen(entry_name);
    138    int utf16_length = length*2;
    139
    140    unsigned char utf16_entry_name[256];
    141    guac_rdp_utf8_to_utf16((const unsigned char*) entry_name, length,
    142            (char*) utf16_entry_name, sizeof(utf16_entry_name));
    143
    144    /* Get file */
    145    file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, entry_file_id);
    146    if (file == NULL)
    147        return;
    148
    149    guac_client_log(svc->client, GUAC_LOG_DEBUG,
    150            "%s: [file_id=%i (entry_name=\"%s\")]",
    151            __func__, entry_file_id, entry_name);
    152
    153    output_stream = guac_rdpdr_new_io_completion(device,
    154            iorequest->completion_id, STATUS_SUCCESS,
    155            4 + 69 + 24 + utf16_length + 2);
    156
    157    Stream_Write_UINT32(output_stream,
    158            69 + 24 + utf16_length + 2); /* Length */
    159
    160    Stream_Write_UINT32(output_stream, 0); /* NextEntryOffset */
    161    Stream_Write_UINT32(output_stream, 0); /* FileIndex */
    162    Stream_Write_UINT64(output_stream, file->ctime); /* CreationTime */
    163    Stream_Write_UINT64(output_stream, file->atime); /* LastAccessTime */
    164    Stream_Write_UINT64(output_stream, file->mtime); /* LastWriteTime */
    165    Stream_Write_UINT64(output_stream, file->mtime); /* ChangeTime */
    166    Stream_Write_UINT64(output_stream, file->size);  /* EndOfFile */
    167    Stream_Write_UINT64(output_stream, file->size);  /* AllocationSize */
    168    Stream_Write_UINT32(output_stream, file->attributes);   /* FileAttributes */
    169    Stream_Write_UINT32(output_stream, utf16_length+2); /* FileNameLength*/
    170    Stream_Write_UINT32(output_stream, 0); /* EaSize */
    171    Stream_Write_UINT8(output_stream,  0); /* ShortNameLength */
    172
    173    /* Apparently, the reserved byte here must be skipped ... */
    174
    175    Stream_Zero(output_stream, 24); /* FileName */
    176    Stream_Write(output_stream, utf16_entry_name, utf16_length); /* FileName */
    177    Stream_Write(output_stream, "\0\0", 2);
    178
    179    guac_rdp_common_svc_write(svc, output_stream);
    180
    181}
    182
    183void guac_rdpdr_fs_process_query_names_info(guac_rdp_common_svc* svc,
    184        guac_rdpdr_device* device, guac_rdpdr_iorequest* iorequest,
    185        const char* entry_name, int entry_file_id) {
    186
    187    guac_rdp_fs_file* file;
    188
    189    wStream* output_stream;
    190    int length = guac_utf8_strlen(entry_name);
    191    int utf16_length = length*2;
    192
    193    unsigned char utf16_entry_name[256];
    194    guac_rdp_utf8_to_utf16((const unsigned char*) entry_name, length,
    195            (char*) utf16_entry_name, sizeof(utf16_entry_name));
    196
    197    /* Get file */
    198    file = guac_rdp_fs_get_file((guac_rdp_fs*) device->data, entry_file_id);
    199    if (file == NULL)
    200        return;
    201
    202    guac_client_log(svc->client, GUAC_LOG_DEBUG,
    203            "%s: [file_id=%i (entry_name=\"%s\")]",
    204            __func__, entry_file_id, entry_name);
    205
    206    output_stream = guac_rdpdr_new_io_completion(device,
    207            iorequest->completion_id, STATUS_SUCCESS,
    208            4 + 12 + utf16_length + 2);
    209
    210    Stream_Write_UINT32(output_stream,
    211            12 + utf16_length + 2); /* Length */
    212
    213    Stream_Write_UINT32(output_stream, 0); /* NextEntryOffset */
    214    Stream_Write_UINT32(output_stream, 0); /* FileIndex */
    215    Stream_Write_UINT32(output_stream, utf16_length+2); /* FileNameLength*/
    216    Stream_Write(output_stream, utf16_entry_name, utf16_length); /* FileName */
    217    Stream_Write(output_stream, "\0\0", 2);
    218
    219    guac_rdp_common_svc_write(svc, output_stream);
    220
    221}
    222