Example #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);
}
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);
}
Example #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);
}
Example #5
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);
}
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);
}
Example #8
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);
}
Example #9
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);
}