~ubuntu-branches/ubuntu/trusty/libssh/trusty

« back to all changes in this revision

Viewing changes to libssh/sftpserver.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2009-12-12 14:29:12 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20091212142912-ha5g2iibt6nfnjq8
Tags: 0.4.0-1
* New upstream release.
  - Bump soname
  - Adjust .symbols file
* Readd static library in -dev package
* Let dh_lintian install override file
* debian/README.Debian: Update file
* debian/rules: Add list-missing rule

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * MA 02111-1307, USA.
22
22
 */
23
23
 
24
 
#include <unistd.h>
25
24
#include <stdlib.h>
26
25
#include <string.h>
27
26
#include <stdio.h>
34
33
#include "libssh/sftp.h"
35
34
#include "libssh/ssh2.h"
36
35
#include "libssh/priv.h"
37
 
 
38
 
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp) {
39
 
  SFTP_PACKET *packet;
40
 
  SFTP_CLIENT_MESSAGE *msg;
41
 
  BUFFER *payload;
42
 
  STRING *tmp;
43
 
 
44
 
  msg = malloc(sizeof (SFTP_CLIENT_MESSAGE));
 
36
#include "libssh/buffer.h"
 
37
#include "libssh/misc.h"
 
38
 
 
39
sftp_client_message sftp_get_client_message(sftp_session sftp) {
 
40
  sftp_packet packet;
 
41
  sftp_client_message msg;
 
42
  ssh_buffer payload;
 
43
  ssh_string tmp;
 
44
 
 
45
  msg = malloc(sizeof (struct sftp_client_message_struct));
45
46
  if (msg == NULL) {
46
47
    return NULL;
47
48
  }
212
213
  return msg;
213
214
}
214
215
 
215
 
void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg) {
 
216
void sftp_client_message_free(sftp_client_message msg) {
216
217
  if (msg == NULL) {
217
218
    return;
218
219
  }
226
227
  SAFE_FREE(msg);
227
228
}
228
229
 
229
 
int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name,
230
 
    SFTP_ATTRIBUTES *attr) {
231
 
  BUFFER *out;
232
 
  STRING *file;
 
230
int sftp_reply_name(sftp_client_message msg, const char *name,
 
231
    sftp_attributes attr) {
 
232
  ssh_buffer out;
 
233
  ssh_string file;
233
234
 
234
235
  out = buffer_new();
235
236
  if (out == NULL) {
258
259
  return 0;
259
260
}
260
261
 
261
 
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle){
262
 
  BUFFER *out;
 
262
int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
 
263
  ssh_buffer out;
263
264
 
264
265
  out = buffer_new();
265
266
  if (out == NULL) {
277
278
  return 0;
278
279
}
279
280
 
280
 
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr) {
281
 
  BUFFER *out;
 
281
int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
 
282
  ssh_buffer out;
282
283
 
283
284
  out = buffer_new();
284
285
  if (out == NULL) {
296
297
  return 0;
297
298
}
298
299
 
299
 
int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file,
300
 
    const char *longname, SFTP_ATTRIBUTES *attr) {
301
 
  STRING *name;
 
300
int sftp_reply_names_add(sftp_client_message msg, const char *file,
 
301
    const char *longname, sftp_attributes attr) {
 
302
  ssh_string name;
302
303
 
303
304
  name = string_from_char(file);
304
305
  if (name == NULL) {
334
335
  return 0;
335
336
}
336
337
 
337
 
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg) {
338
 
  BUFFER *out;
 
338
int sftp_reply_names(sftp_client_message msg) {
 
339
  ssh_buffer out;
339
340
 
340
341
  out = buffer_new();
341
342
  if (out == NULL) {
362
363
  return 0;
363
364
}
364
365
 
365
 
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status,
 
366
int sftp_reply_status(sftp_client_message msg, uint32_t status,
366
367
    const char *message) {
367
 
  BUFFER *out;
368
 
  STRING *s;
 
368
  ssh_buffer out;
 
369
  ssh_string s;
369
370
 
370
371
  out = buffer_new();
371
372
  if (out == NULL) {
394
395
  return 0;
395
396
}
396
397
 
397
 
int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len) {
398
 
  BUFFER *out;
 
398
int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
 
399
  ssh_buffer out;
399
400
 
400
401
  out = buffer_new();
401
402
  if (out == NULL) {
420
421
 * the handle. Care is given that a corrupted handle won't give a
421
422
 * valid info (or worse).
422
423
 */
423
 
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info) {
424
 
  STRING *ret;
425
 
  u32 val;
 
424
ssh_string sftp_handle_alloc(sftp_session sftp, void *info) {
 
425
  ssh_string ret;
 
426
  uint32_t val;
426
427
  int i;
427
428
 
428
429
  if (sftp->handles == NULL) {
449
450
    return NULL;
450
451
  }
451
452
 
452
 
  memcpy(ret->string, &val, sizeof(u32));
 
453
  memcpy(string_data(ret), &val, sizeof(uint32_t));
453
454
  sftp->handles[i] = info;
454
455
 
455
456
  return ret;
456
457
}
457
458
 
458
 
void *sftp_handle(SFTP_SESSION *sftp, STRING *handle){
459
 
  u32 val;
 
459
void *sftp_handle(sftp_session sftp, ssh_string handle){
 
460
  uint32_t val;
460
461
 
461
462
  if (sftp->handles == NULL) {
462
463
    return NULL;
463
464
  }
464
465
 
465
 
  if (string_len(handle) != sizeof(u32)) {
 
466
  if (string_len(handle) != sizeof(uint32_t)) {
466
467
    return NULL;
467
468
  }
468
469
 
469
 
  memcpy(&val, handle->string, sizeof(u32));
 
470
  memcpy(&val, string_data(handle), sizeof(uint32_t));
470
471
 
471
472
  if (val > SFTP_HANDLES) {
472
473
    return NULL;
475
476
  return sftp->handles[val];
476
477
}
477
478
 
478
 
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle) {
 
479
void sftp_handle_remove(sftp_session sftp, void *handle) {
479
480
  int i;
480
481
 
481
482
  for (i = 0; i < SFTP_HANDLES; i++) {