Exemple #1
0
void DoExtDiskSpace(tBuffer *bIn, tBuffer *bOut, u_int32_t id)
{
	struct STATFS stfs;
	tFSPath	*realPath;
	char *path;

	path = convertFromUtf8(BufferGetString(bIn), 1);
	realPath = FSCheckPath(path);
	DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH]Path: %s", path));
	if (realPath != NULL && !HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_STATSFS))
	{
		DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH]Realpath: %s", realPath->realPath));
		if (STATFS(realPath->realPath, &stfs) == 0)
		{
			tBuffer *b;

			b = BufferNew();
			BufferPutInt8(b, SSH2_FXP_EXTENDED_REPLY);
			BufferPutInt32(b, id);
			BufferPutInt64(b, (u_int64_t) stfs.f_blocks * (u_int64_t) stfs.f_bsize);
			BufferPutInt64(b, (u_int64_t) stfs.f_bfree * (u_int64_t) stfs.f_bsize);
			BufferPutInt64(b, 0);
			BufferPutInt64(b, (u_int64_t) stfs.f_bavail * (u_int64_t) stfs.f_bsize);
			BufferPutInt32(b, stfs.f_bsize);
			BufferPutPacket(bOut, b);
		}
		else
			SendStatus(bOut, id, errnoToPortable(errno));
	}
	else
		SendStatus(bOut, id, SSH2_FX_PERMISSION_DENIED);
	FSDestroyPath(realPath);
	free(path);
}
static void DoExtDiskSpaceOpenSSH_Path(tBuffer *bOut, u_int32_t id, const char *path)
{
	struct STATFS stfs;
	tFSPath	*realPath;

	DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]Path: %s", path));
	realPath = FSCheckPath(path);
	if (realPath != NULL && !HAS_BIT(gl_var->flagsDisable, SFTP_DISABLE_STATSFS))
	{
		DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]Realpath: %s", realPath->realPath));
		if (STATFS(realPath->realPath, &stfs) == 0)
		{
			tBuffer *b;

			b = BufferNew();
			BufferPutInt8(b, SSH2_FXP_EXTENDED_REPLY);
			BufferPutInt32(b, id);
			BufferPutInt64(b, stfs.f_bsize); /* file system block size */
			BufferPutInt64(b, stfs.f_frsize); /* fundamental fs block size */
			BufferPutInt64(b, stfs.f_blocks); /* number of blocks (unit f_frsize) */
			BufferPutInt64(b, stfs.f_bfree); /* free blocks in file system */
			BufferPutInt64(b, stfs.f_bavail); /* free blocks for non-root */
			BufferPutInt64(b, stfs.f_files); /* total file inodes */
			BufferPutInt64(b, stfs.f_ffree); /* free file inodes */
			BufferPutInt64(b, stfs.f_favail); /* free file inodes for to non-root */
			BufferPutInt64(b, stfs.f_fsid); /* file system id */
			BufferPutInt64(b, stfs.f_flag); /* bit mask of f_flag values */
			BufferPutInt64(b, stfs.f_namemax); /* maximum filename length */
			BufferPutPacket(bOut, b);
			BufferDelete(b);
		}
		else
		{
			DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]error: %s", strerror(errno)));
			SendStatus(bOut, id, errnoToPortable(errno));
		}
	}
	else
	{
		DEBUG((MYLOG_DEBUG, "[DoExtDiskSpaceOpenSSH_Path]FSCheckPath failed"));
		SendStatus(bOut, id, SSH2_FX_PERMISSION_DENIED);
	}
	FSDestroyPath(realPath);
}