Ejemplo n.º 1
0
static void
process_fstat(u_int32_t id)
{
	Attrib a;
	struct stat st;
	int fd, r, handle, status = SSH2_FX_FAILURE;

	if ((r = get_handle(iqueue, &handle)) != 0)
		fatal("%s: buffer error: %s", __func__, ssh_err(r));
	debug("request %u: fstat \"%s\" (handle %u)",
	    id, handle_to_name(handle), handle);
	fd = handle_to_fd(handle);
	if (fd >= 0) {
		r = fstat(fd, &st);
		if (r < 0) {
			status = errno_to_portable(errno);
		} else {
			stat_to_attrib(&st, &a);
			send_attrib(id, &a);
			status = SSH2_FX_OK;
		}
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
}
Ejemplo n.º 2
0
void SFTP::process_fstat(void)
{
	Attrib a;
	BY_HANDLE_FILE_INFORMATION st;
	u_int32_t id;
	int handle, status = SSH2_FX_FAILURE;

	id = get_int();
	handle = get_handle();
	debug("request %u: fstat \"%s\" (handle %u)",
	    id, toUTF8(handle_to_name(handle)).c_str (), handle);
	const HANDLE fh = handle_to_fh(handle);
  if (fh != INVALID_HANDLE_VALUE) 
  {
		if (!::GetFileInformationByHandle (fh, &st)) 
    {
			status = errno_to_portable(::GetLastError ());
		} 
    else 
    {
			stat_to_attrib(&st, &a);
			send_attrib(id, &a);
			status = SSH2_FX_OK;
		}
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
}
Ejemplo n.º 3
0
static void
process_do_stat(u_int32_t id, int do_lstat)
{
	Attrib a;
	struct stat st;
	char *name;
	int r, status = SSH2_FX_FAILURE;

	if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0)
		fatal("%s: buffer error: %s", __func__, ssh_err(r));

	debug3("request %u: %sstat", id, do_lstat ? "l" : "");
	verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
	r = do_lstat ? lstat(name, &st) : stat(name, &st);
	if (r < 0) {
		status = errno_to_portable(errno);
	} else {
		stat_to_attrib(&st, &a);
		send_attrib(id, &a);
		status = SSH2_FX_OK;
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
	free(name);
}
static void
process_fstat(void)
{
	Attrib a;
	struct stat st;
	u_int32_t id;
	int fd, ret, handle, status = SSH2_FX_FAILURE;

	id = get_int();
	handle = get_handle();
	TRACE("fstat id %u handle %d", id, handle);
	fd = handle_to_fd(handle);
	if (fd  >= 0) {
		ret = fstat(fd, &st);
		if (ret < 0) {
			status = errno_to_portable(errno);
		} else {
			stat_to_attrib(&st, &a);
			send_attrib(id, &a);
			status = SSH2_FX_OK;
		}
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
}
static void
process_do_stat(int do_lstat)
{
	Attrib a;
	struct stat st;
	u_int32_t id;
	char *name;
	int ret, status = SSH2_FX_FAILURE;

	id = get_int();
	name = get_string(NULL);
	debug3("request %u: %sstat", id, do_lstat ? "l" : "");
	verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
	ret = do_lstat ? lstat(name, &st) : stat(name, &st);
	if (ret < 0) {
		status = errno_to_portable(errno);
	} else {
		stat_to_attrib(&st, &a);
		if (fake_permissions)
			a.perm |= (S_IRUSR | S_IWUSR);
		send_attrib(id, &a);
		status = SSH2_FX_OK;
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
	xfree(name);
}
static void
process_fstat(u_int32_t id)
{
	Attrib a;
	struct stat st;
	int fd, ret, handle, status = SSH2_FX_FAILURE;

	handle = get_handle();
	debug("request %u: fstat \"%s\" (handle %u)",
	    id, handle_to_name(handle), handle);
	fd = handle_to_fd(handle);
	if (fd >= 0) {
		ret = fstat(fd, &st);
		if (ret < 0) {
			status = errno_to_portable(errno);
		} else {
			stat_to_attrib(&st, &a);
			send_attrib(id, &a);
			status = SSH2_FX_OK;
		}
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
	s_audit("sftp_process_fstat_3", "count=%i int=%d int=%d", 
		get_client_session_id(), (int)getppid(), handle);
#endif
}
static void
process_do_stat(u_int32_t id, int do_lstat)
{
	Attrib a;
	struct stat st;
	char *name;
	int ret, status = SSH2_FX_FAILURE;

	name = get_string(NULL);
	debug3("request %u: %sstat", id, do_lstat ? "l" : "");
	verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
	ret = do_lstat ? lstat(name, &st) : stat(name, &st);
	if (ret < 0) {
		status = errno_to_portable(errno);
	} else {
		stat_to_attrib(&st, &a);
		send_attrib(id, &a);
		status = SSH2_FX_OK;
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);

#ifdef NERSC_MOD
 	char* t1buf = encode_string(name, strlen(name));
 	s_audit("sftp_process_do_stat_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
 	free(t1buf);
#endif

	free(name);
}
static void
process_readdir(u_int32_t id)
{
	DIR *dirp;
	struct dirent *dp;
	char *path;
	int handle;

	handle = get_handle();
	debug("request %u: readdir \"%s\" (handle %d)", id,
	    handle_to_name(handle), handle);
	dirp = handle_to_dir(handle);
	path = handle_to_name(handle);
	if (dirp == NULL || path == NULL) {
		send_status(id, SSH2_FX_FAILURE);
	} else {
		struct stat st;
		char pathname[MAXPATHLEN];
		Stat *stats;
		int nstats = 10, count = 0, i;

		stats = xcalloc(nstats, sizeof(Stat));
		while ((dp = readdir(dirp)) != NULL) {
			if (count >= nstats) {
				nstats *= 2;
				stats = xrealloc(stats, nstats, sizeof(Stat));
			}
/* XXX OVERFLOW ? */
			snprintf(pathname, sizeof pathname, "%s%s%s", path,
			    strcmp(path, "/") ? "/" : "", dp->d_name);
			if (lstat(pathname, &st) < 0)
				continue;
			stat_to_attrib(&st, &(stats[count].attrib));
			stats[count].name = xstrdup(dp->d_name);
			stats[count].long_name = ls_file(dp->d_name, &st, 0, 0);
			count++;
			/* send up to 100 entries in one message */
			/* XXX check packet size instead */
			if (count == 100)
				break;
		}
		if (count > 0) {
			send_names(id, count, stats);
			for (i = 0; i < count; i++) {
				free(stats[i].name);
				free(stats[i].long_name);
			}
		} else {
			send_status(id, SSH2_FX_EOF);
		}

#ifdef NERSC_MOD
 	char* t1buf = encode_string(path, strlen(path));
 	s_audit("sftp_process_readdir_3", "count=%i int=%d uristring=%s",
 		get_client_session_id(), (int)getppid(), t1buf);
#endif

		free(stats);
	}
}
Ejemplo n.º 9
0
static void
process_readdir(u_int32_t id)
{
	DIR *dirp;
	struct dirent *dp;
	char *path;
	int r, handle;

	if ((r = get_handle(iqueue, &handle)) != 0)
		fatal("%s: buffer error: %s", __func__, ssh_err(r));

	debug("request %u: readdir \"%s\" (handle %d)", id,
	    handle_to_name(handle), handle);
	dirp = handle_to_dir(handle);
	path = handle_to_name(handle);
	if (dirp == NULL || path == NULL) {
		send_status(id, SSH2_FX_FAILURE);
	} else {
		struct stat st;
		char pathname[PATH_MAX];
		Stat *stats;
		int nstats = 10, count = 0, i;

		stats = xcalloc(nstats, sizeof(Stat));
		while ((dp = readdir(dirp)) != NULL) {
			if (count >= nstats) {
				nstats *= 2;
				stats = xreallocarray(stats, nstats, sizeof(Stat));
			}
/* XXX OVERFLOW ? */
			snprintf(pathname, sizeof pathname, "%s%s%s", path,
			    strcmp(path, "/") ? "/" : "", dp->d_name);
			if (lstat(pathname, &st) < 0)
				continue;
			stat_to_attrib(&st, &(stats[count].attrib));
			stats[count].name = xstrdup(dp->d_name);
			stats[count].long_name = ls_file(dp->d_name, &st, 0, 0);
			count++;
			/* send up to 100 entries in one message */
			/* XXX check packet size instead */
			if (count == 100)
				break;
		}
		if (count > 0) {
			send_names(id, count, stats);
			for (i = 0; i < count; i++) {
				free(stats[i].name);
				free(stats[i].long_name);
			}
		} else {
			send_status(id, SSH2_FX_EOF);
		}
		free(stats);
	}
}
static void
process_readdir(void)
{
	DIR *dirp;
	struct dirent *dp;
	char *path;
	int handle;
	u_int32_t id;

	id = get_int();
	handle = get_handle();
	TRACE("readdir id %u handle %d", id, handle);
	dirp = handle_to_dir(handle);
	path = handle_to_name(handle);
	if (dirp == NULL || path == NULL) {
		send_status(id, SSH2_FX_FAILURE);
	} else {
		struct stat st;
		char pathname[1024];
		Stat *stats;
		int nstats = 10, count = 0, i;

		stats = xmalloc(nstats * sizeof(Stat));
		while ((dp = readdir(dirp)) != NULL) {
			if (count >= nstats) {
				nstats *= 2;
				stats = xrealloc(stats, nstats * sizeof(Stat));
			}
/* XXX OVERFLOW ? */
			snprintf(pathname, sizeof pathname, "%s%s%s", path,
			    strcmp(path, "/") ? "/" : "", dp->d_name);
			if (lstat(pathname, &st) < 0)
				continue;
			stat_to_attrib(&st, &(stats[count].attrib));
			stats[count].name = xstrdup(dp->d_name);
			stats[count].long_name = ls_file(dp->d_name, &st);
			count++;
			/* send up to 100 entries in one message */
			/* XXX check packet size instead */
			if (count == 100)
				break;
		}
		if (count > 0) {
			send_names(id, count, stats);
			for (i = 0; i < count; i++) {
				xfree(stats[i].name);
				xfree(stats[i].long_name);
			}
		} else {
			send_status(id, SSH2_FX_EOF);
		}
		xfree(stats);
	}
}
Ejemplo n.º 11
0
void SFTP::process_do_stat(/*int do_lstat*/)
{
	Attrib a;
	WIN32_FILE_ATTRIBUTE_DATA st;
	u_int32_t id;
	char *utf8_name = 0;
	int status = SSH2_FX_FAILURE;

  try
  {
	  id = get_int(); 
	  utf8_name = (char*) get_string(NULL);
	  debug3("request %u: %sstat", id, /*do_lstat*/ 0 ? "l" : "");
	  verbose("%sstat name \"%s\"", /*do_lstat*/ 0 ? "l" : "", utf8_name);
    
    const SFTPFilePath path = pathFact.create_path (utf8_name);
    if (!::GetFileAttributesExW 
      (path.get_for_call ().c_str (),
       GetFileExInfoStandard,
       &st
       )
      ) 
    {
      status = errno_to_portable(::GetLastError ());
	  } 
    else 
    {
		  stat_to_attrib(&st, &a);
		  send_attrib(id, &a);
		  status = SSH2_FX_OK;
	  }
  }
  catch (Path::InvalidPath&)
  {
    //logit 
    status = SSH2_FX_FAILURE; 
    // TODO return the reason
  }
  catch (...)
  {
    status = SSH2_FX_FAILURE; 
    error ("unhandled exception in %s", __FUNCTION__);
  }
	if (status != SSH2_FX_OK)
		send_status(id, status);
	if (utf8_name) xfree(utf8_name);
}
Ejemplo n.º 12
0
static void
process_fstat(u_int32_t id)
{
	Attrib a;
	struct stat st;
	int fd, ret, handle, status = SSH2_FX_FAILURE;

	handle = get_handle();
	debug("request %u: fstat \"%s\" (handle %u)",
	    id, handle_to_name(handle), handle);
	fd = handle_to_fd(handle);
	if (fd >= 0) {
		ret = fstat(fd, &st);
		if (ret < 0) {
			status = errno_to_portable(errno);
		} else {
			stat_to_attrib(&st, &a);
			send_attrib(id, &a);
			status = SSH2_FX_OK;
		}
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
}
static void
process_do_stat(int do_lstat)
{
	Attrib a;
	struct stat st;
	u_int32_t id;
	char *name;
	int ret, status = SSH2_FX_FAILURE;

	id = get_int();
	name = get_string(NULL);
	TRACE("%sstat id %u name %s", do_lstat ? "l" : "", id, name);
	ret = do_lstat ? lstat(name, &st) : stat(name, &st);
	if (ret < 0) {
		status = errno_to_portable(errno);
	} else {
		stat_to_attrib(&st, &a);
		send_attrib(id, &a);
		status = SSH2_FX_OK;
	}
	if (status != SSH2_FX_OK)
		send_status(id, status);
	xfree(name);
}
Ejemplo n.º 14
0
void SFTP::process_readdir(void)
{
  int handle;
	u_int32_t id;

	id = get_int();
	handle = get_handle();
	debug("request %u: readdir \"%s\" (handle %d)", id,
    toUTF8(handle_to_name(handle)).c_str (), handle);
	
  HANDLE dh = handle_to_dir(handle);
  const SFTPFilePath dirPath (handle_to_path (handle));
	if (dh == INVALID_HANDLE_VALUE 
      || dirPath.to_string ().length () == 0
      ) 
  {
		send_status(id, SSH2_FX_FAILURE);
	} 
  else 
  {
		WIN32_FIND_DATA st;
		//char pathname[MAXPATHLEN];
		Stat *stats;
		int nstats = 10, count = 0, i;

    stats = (Stat*) xcalloc(nstats, sizeof(Stat));
    HANDLE& searchHandle = handles[handle].searchHandle;
    bool& searchDone = handles[handle].searchDone;
    if (!searchDone 
        && searchHandle == INVALID_HANDLE_VALUE)
    {
      assert (!searchDone);
      searchHandle = ::FindFirstFile
        (dirPath.get_mask_for_dir_search ().c_str (),
         &st
         );
    }
    if (!searchDone 
        && searchHandle != INVALID_HANDLE_VALUE
) 
    {
      searchDone = true;
      while (::FindNextFileW (searchHandle, &st))
      {
			  if (count >= nstats) {
				  nstats *= 2;
				  stats = (Stat*) xrealloc(stats, nstats, sizeof(Stat));
			  }
			  stat_to_attrib(&st, &(stats[count].attrib));
        stats[count].name = xstrdup
          (toUTF8(st.cFileName).c_str ());
        stats[count].long_name = xstrdup
          (toUTF8 (ls_file(st.cFileName, &st, 0)).c_str ());
			  count++;
			  /* send up to 100 entries in one message */
			  /* XXX check packet size instead */
			  if (count == 100) {
          searchDone = false;
          break;
        }
      }
      /*if (searchDone)
        ::GetLastError (); // read error of FindNextFile*/
		}
    if (searchDone 
        && searchHandle != INVALID_HANDLE_VALUE)
    {
      ::FindClose (searchHandle);
      searchHandle = 0;
    }

		if (count > 0) {
			send_names(id, count, stats);
			for (i = 0; i < count; i++) {
				xfree(stats[i].name);
				xfree(stats[i].long_name);
			}
		} else {
      searchHandle = INVALID_HANDLE_VALUE;
      searchDone = false;
			send_status(id, SSH2_FX_EOF);
		}
		xfree(stats);
	}
}