[BACK]Return to sftp-server.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Diff for /src/usr.bin/ssh/sftp-server.c between version 1.25.2.2 and 1.26

version 1.25.2.2, 2002/03/09 00:20:45 version 1.26, 2001/05/12 19:53:13
Line 1 
Line 1 
 /*  /*
  * Copyright (c) 2000, 2001, 2002 Markus Friedl.  All rights reserved.   * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions   * modification, are permitted provided that the following conditions
Line 56 
Line 56 
         Attrib attrib;          Attrib attrib;
 };  };
   
 static int  int
 errno_to_portable(int unixerrno)  errno_to_portable(int unixerrno)
 {  {
         int ret = 0;          int ret = 0;
Line 87 
Line 87 
         return ret;          return ret;
 }  }
   
 static int  int
 flags_from_portable(int pflags)  flags_from_portable(int pflags)
 {  {
         int flags = 0;          int flags = 0;
Line 109 
Line 109 
         return flags;          return flags;
 }  }
   
 static Attrib *  Attrib *
 get_attrib(void)  get_attrib(void)
 {  {
         return decode_attrib(&iqueue);          return decode_attrib(&iqueue);
Line 133 
Line 133 
   
 Handle  handles[100];  Handle  handles[100];
   
 static void  void
 handle_init(void)  handle_init(void)
 {  {
         int i;          int i;
   
         for (i = 0; i < sizeof(handles)/sizeof(Handle); i++)          for(i = 0; i < sizeof(handles)/sizeof(Handle); i++)
                 handles[i].use = HANDLE_UNUSED;                  handles[i].use = HANDLE_UNUSED;
 }  }
   
 static int  int
 handle_new(int use, char *name, int fd, DIR *dirp)  handle_new(int use, char *name, int fd, DIR *dirp)
 {  {
         int i;          int i;
   
         for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) {          for(i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
                 if (handles[i].use == HANDLE_UNUSED) {                  if (handles[i].use == HANDLE_UNUSED) {
                         handles[i].use = use;                          handles[i].use = use;
                         handles[i].dirp = dirp;                          handles[i].dirp = dirp;
Line 159 
Line 159 
         return -1;          return -1;
 }  }
   
 static int  int
 handle_is_ok(int i, int type)  handle_is_ok(int i, int type)
 {  {
         return i >= 0 && i < sizeof(handles)/sizeof(Handle) &&          return i >= 0 && i < sizeof(handles)/sizeof(Handle) &&
             handles[i].use == type;              handles[i].use == type;
 }  }
   
 static int  int
 handle_to_string(int handle, char **stringp, int *hlenp)  handle_to_string(int handle, char **stringp, int *hlenp)
 {  {
         if (stringp == NULL || hlenp == NULL)          if (stringp == NULL || hlenp == NULL)
Line 177 
Line 177 
         return 0;          return 0;
 }  }
   
 static int  int
 handle_from_string(char *handle, u_int hlen)  handle_from_string(char *handle, u_int hlen)
 {  {
         int val;          int val;
Line 191 
Line 191 
         return -1;          return -1;
 }  }
   
 static char *  char *
 handle_to_name(int handle)  handle_to_name(int handle)
 {  {
         if (handle_is_ok(handle, HANDLE_DIR)||          if (handle_is_ok(handle, HANDLE_DIR)||
Line 200 
Line 200 
         return NULL;          return NULL;
 }  }
   
 static DIR *  DIR *
 handle_to_dir(int handle)  handle_to_dir(int handle)
 {  {
         if (handle_is_ok(handle, HANDLE_DIR))          if (handle_is_ok(handle, HANDLE_DIR))
Line 208 
Line 208 
         return NULL;          return NULL;
 }  }
   
 static int  int
 handle_to_fd(int handle)  handle_to_fd(int handle)
 {  {
         if (handle_is_ok(handle, HANDLE_FILE))          if (handle_is_ok(handle, HANDLE_FILE))
Line 216 
Line 216 
         return -1;          return -1;
 }  }
   
 static int  int
 handle_close(int handle)  handle_close(int handle)
 {  {
         int ret = -1;          int ret = -1;
Line 233 
Line 233 
         return ret;          return ret;
 }  }
   
 static int  int
 get_handle(void)  get_handle(void)
 {  {
         char *handle;          char *handle;
Line 249 
Line 249 
   
 /* send replies */  /* send replies */
   
 static void  void
 send_msg(Buffer *m)  send_msg(Buffer *m)
 {  {
         int mlen = buffer_len(m);          int mlen = buffer_len(m);
Line 259 
Line 259 
         buffer_consume(m, mlen);          buffer_consume(m, mlen);
 }  }
   
 static void  void
 send_status(u_int32_t id, u_int32_t error)  send_status(u_int32_t id, u_int32_t error)
 {  {
         Buffer msg;          Buffer msg;
Line 289 
Line 289 
         send_msg(&msg);          send_msg(&msg);
         buffer_free(&msg);          buffer_free(&msg);
 }  }
 static void  void
 send_data_or_handle(char type, u_int32_t id, char *data, int dlen)  send_data_or_handle(char type, u_int32_t id, char *data, int dlen)
 {  {
         Buffer msg;          Buffer msg;
Line 302 
Line 302 
         buffer_free(&msg);          buffer_free(&msg);
 }  }
   
 static void  void
 send_data(u_int32_t id, char *data, int dlen)  send_data(u_int32_t id, char *data, int dlen)
 {  {
         TRACE("sent data id %d len %d", id, dlen);          TRACE("sent data id %d len %d", id, dlen);
         send_data_or_handle(SSH2_FXP_DATA, id, data, dlen);          send_data_or_handle(SSH2_FXP_DATA, id, data, dlen);
 }  }
   
 static void  void
 send_handle(u_int32_t id, int handle)  send_handle(u_int32_t id, int handle)
 {  {
         char *string;          char *string;
Line 321 
Line 321 
         xfree(string);          xfree(string);
 }  }
   
 static void  void
 send_names(u_int32_t id, int count, Stat *stats)  send_names(u_int32_t id, int count, Stat *stats)
 {  {
         Buffer msg;          Buffer msg;
Line 341 
Line 341 
         buffer_free(&msg);          buffer_free(&msg);
 }  }
   
 static void  void
 send_attrib(u_int32_t id, Attrib *a)  send_attrib(u_int32_t id, Attrib *a)
 {  {
         Buffer msg;          Buffer msg;
Line 357 
Line 357 
   
 /* parse incoming */  /* parse incoming */
   
 static void  void
 process_init(void)  process_init(void)
 {  {
         Buffer msg;          Buffer msg;
Line 371 
Line 371 
         buffer_free(&msg);          buffer_free(&msg);
 }  }
   
 static void  void
 process_open(void)  process_open(void)
 {  {
         u_int32_t id, pflags;          u_int32_t id, pflags;
Line 403 
Line 403 
         xfree(name);          xfree(name);
 }  }
   
 static void  void
 process_close(void)  process_close(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 417 
Line 417 
         send_status(id, status);          send_status(id, status);
 }  }
   
 static void  void
 process_read(void)  process_read(void)
 {  {
         char buf[64*1024];          char buf[64*1024];
Line 457 
Line 457 
                 send_status(id, status);                  send_status(id, status);
 }  }
   
 static void  void
 process_write(void)  process_write(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 495 
Line 495 
         xfree(data);          xfree(data);
 }  }
   
 static void  void
 process_do_stat(int do_lstat)  process_do_stat(int do_lstat)
 {  {
         Attrib a;          Attrib a;
Line 520 
Line 520 
         xfree(name);          xfree(name);
 }  }
   
 static void  void
 process_stat(void)  process_stat(void)
 {  {
         process_do_stat(0);          process_do_stat(0);
 }  }
   
 static void  void
 process_lstat(void)  process_lstat(void)
 {  {
         process_do_stat(1);          process_do_stat(1);
 }  }
   
 static void  void
 process_fstat(void)  process_fstat(void)
 {  {
         Attrib a;          Attrib a;
Line 558 
Line 558 
                 send_status(id, status);                  send_status(id, status);
 }  }
   
 static struct timeval *  struct timeval *
 attrib_to_tv(Attrib *a)  attrib_to_tv(Attrib *a)
 {  {
         static struct timeval tv[2];          static struct timeval tv[2];
Line 570 
Line 570 
         return tv;          return tv;
 }  }
   
 static void  void
 process_setstat(void)  process_setstat(void)
 {  {
         Attrib *a;          Attrib *a;
Line 583 
Line 583 
         name = get_string(NULL);          name = get_string(NULL);
         a = get_attrib();          a = get_attrib();
         TRACE("setstat id %d name %s", id, name);          TRACE("setstat id %d name %s", id, name);
         if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {  
                 ret = truncate(name, a->size);  
                 if (ret == -1)  
                         status = errno_to_portable(errno);  
         }  
         if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {          if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
                 ret = chmod(name, a->perm & 0777);                  ret = chmod(name, a->perm & 0777);
                 if (ret == -1)                  if (ret == -1)
Line 607 
Line 602 
         xfree(name);          xfree(name);
 }  }
   
 static void  void
 process_fsetstat(void)  process_fsetstat(void)
 {  {
         Attrib *a;          Attrib *a;
Line 623 
Line 618 
         if (fd < 0) {          if (fd < 0) {
                 status = SSH2_FX_FAILURE;                  status = SSH2_FX_FAILURE;
         } else {          } else {
                 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {  
                         ret = ftruncate(fd, a->size);  
                         if (ret == -1)  
                                 status = errno_to_portable(errno);  
                 }  
                 if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {                  if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
                         ret = fchmod(fd, a->perm & 0777);                          ret = fchmod(fd, a->perm & 0777);
                         if (ret == -1)                          if (ret == -1)
Line 647 
Line 637 
         send_status(id, status);          send_status(id, status);
 }  }
   
 static void  void
 process_opendir(void)  process_opendir(void)
 {  {
         DIR *dirp = NULL;          DIR *dirp = NULL;
Line 679 
Line 669 
 /*  /*
  * drwxr-xr-x    5 markus   markus       1024 Jan 13 18:39 .ssh   * drwxr-xr-x    5 markus   markus       1024 Jan 13 18:39 .ssh
  */   */
 static char *  char *
 ls_file(char *name, struct stat *st)  ls_file(char *name, struct stat *st)
 {  {
         int ulen, glen, sz = 0;          int sz = 0;
         struct passwd *pw;          struct passwd *pw;
         struct group *gr;          struct group *gr;
         struct tm *ltime = localtime(&st->st_mtime);          struct tm *ltime = localtime(&st->st_mtime);
Line 710 
Line 700 
         }          }
         if (sz == 0)          if (sz == 0)
                 tbuf[0] = '\0';                  tbuf[0] = '\0';
         ulen = MAX(strlen(user), 8);          snprintf(buf, sizeof buf, "%s %3d %-8.8s %-8.8s %8llu %s %s", mode,
         glen = MAX(strlen(group), 8);              st->st_nlink, user, group, (unsigned long long)st->st_size, tbuf, name);
         snprintf(buf, sizeof buf, "%s %3d %-*s %-*s %8llu %s %s", mode,  
             st->st_nlink, ulen, user, glen, group,  
             (unsigned long long)st->st_size, tbuf, name);  
         return xstrdup(buf);          return xstrdup(buf);
 }  }
   
 static void  void
 process_readdir(void)  process_readdir(void)
 {  {
         DIR *dirp;          DIR *dirp;
Line 746 
Line 733 
                                 stats = xrealloc(stats, nstats * sizeof(Stat));                                  stats = xrealloc(stats, nstats * sizeof(Stat));
                         }                          }
 /* XXX OVERFLOW ? */  /* XXX OVERFLOW ? */
                         snprintf(pathname, sizeof pathname, "%s%s%s", path,                          snprintf(pathname, sizeof pathname,
                             strcmp(path, "/") ? "/" : "", dp->d_name);                              "%s/%s", path, dp->d_name);
                         if (lstat(pathname, &st) < 0)                          if (lstat(pathname, &st) < 0)
                                 continue;                                  continue;
                         stat_to_attrib(&st, &(stats[count].attrib));                          stat_to_attrib(&st, &(stats[count].attrib));
Line 761 
Line 748 
                 }                  }
                 if (count > 0) {                  if (count > 0) {
                         send_names(id, count, stats);                          send_names(id, count, stats);
                         for (i = 0; i < count; i++) {                          for(i = 0; i < count; i++) {
                                 xfree(stats[i].name);                                  xfree(stats[i].name);
                                 xfree(stats[i].long_name);                                  xfree(stats[i].long_name);
                         }                          }
Line 772 
Line 759 
         }          }
 }  }
   
 static void  void
 process_remove(void)  process_remove(void)
 {  {
         char *name;          char *name;
Line 789 
Line 776 
         xfree(name);          xfree(name);
 }  }
   
 static void  void
 process_mkdir(void)  process_mkdir(void)
 {  {
         Attrib *a;          Attrib *a;
Line 809 
Line 796 
         xfree(name);          xfree(name);
 }  }
   
 static void  void
 process_rmdir(void)  process_rmdir(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 825 
Line 812 
         xfree(name);          xfree(name);
 }  }
   
 static void  void
 process_realpath(void)  process_realpath(void)
 {  {
         char resolvedname[MAXPATHLEN];          char resolvedname[MAXPATHLEN];
Line 850 
Line 837 
         xfree(path);          xfree(path);
 }  }
   
 static void  void
 process_rename(void)  process_rename(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 872 
Line 859 
         xfree(newpath);          xfree(newpath);
 }  }
   
 static void  void
 process_readlink(void)  process_readlink(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 887 
Line 874 
                 send_status(id, errno_to_portable(errno));                  send_status(id, errno_to_portable(errno));
         else {          else {
                 Stat s;                  Stat s;
   
                 link[len] = '\0';                  link[len] = '\0';
                 attrib_clear(&s.attrib);                  attrib_clear(&s.attrib);
                 s.name = s.long_name = link;                  s.name = s.long_name = link;
Line 896 
Line 883 
         xfree(path);          xfree(path);
 }  }
   
 static void  void
 process_symlink(void)  process_symlink(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 918 
Line 905 
         xfree(newpath);          xfree(newpath);
 }  }
   
 static void  void
 process_extended(void)  process_extended(void)
 {  {
         u_int32_t id;          u_int32_t id;
Line 932 
Line 919 
   
 /* stolen from ssh-agent */  /* stolen from ssh-agent */
   
 static void  void
 process(void)  process(void)
 {  {
         u_int msg_len;          u_int msg_len;
Line 941 
Line 928 
   
         if (buffer_len(&iqueue) < 5)          if (buffer_len(&iqueue) < 5)
                 return;         /* Incomplete message. */                  return;         /* Incomplete message. */
         cp = buffer_ptr(&iqueue);          cp = (u_char *) buffer_ptr(&iqueue);
         msg_len = GET_32BIT(cp);          msg_len = GET_32BIT(cp);
         if (msg_len > 256 * 1024) {          if (msg_len > 256 * 1024) {
                 error("bad message ");                  error("bad message ");

Legend:
Removed from v.1.25.2.2  
changed lines
  Added in v.1.26