资源简介

AgensGraph 是一个基于 PostgreSQL 的新一代多模型图数据库。它提供图形分析环境,用户可以同时编写、编辑和执行 SQL 和 Cypher 查询。AgensGraph 带有 PostgreSQL 兼容性和 PostgreSQL扩展,能够帮助PostgreSQL用户摆脱数据迁移的痛苦,轻松开发提供高级数据分析的服务。

资源截图

代码片段和文件信息

/*-------------------------------------------------------------------------
 *
 * adminpack.c
 *
 *
 * Copyright (c) 2002-2017 PostgreSQL Global Development Group
 *
 * Author: Andreas Pflug 
 *
 * IDENTIFICATION
 *   contrib/adminpack/adminpack.c
 *
 *-------------------------------------------------------------------------
 */
#include “postgres.h“

#include 
#include 
#include 

#include “catalog/pg_type.h“
#include “funcapi.h“
#include “miscadmin.h“
#include “postmaster/syslogger.h“
#include “storage/fd.h“
#include “utils/builtins.h“
#include “utils/datetime.h“


#ifdef WIN32

#ifdef rename
#undef rename
#endif

#ifdef unlink
#undef unlink
#endif
#endif

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(pg_file_write);
PG_FUNCTION_INFO_V1(pg_file_rename);
PG_FUNCTION_INFO_V1(pg_file_unlink);
PG_FUNCTION_INFO_V1(pg_logdir_ls);

typedef struct
{
char    *location;
DIR    *dirdesc;
} directory_fctx;

/*-----------------------
 * some helper functions
 */

/*
 * Convert a “text“ filename argument to C string and check it‘s allowable.
 *
 * Filename may be absolute or relative to the DataDir but we only allow
 * absolute paths that match DataDir or Log_directory.
 */
static char *
convert_and_check_filename(text *arg bool logAllowed)
{
char    *filename = text_to_cstring(arg);

canonicalize_path(filename); /* filename can change length here */

if (is_absolute_path(filename))
{
/* Disallow ‘/a/b/data/..‘ */
if (path_contains_parent_reference(filename))
ereport(ERROR
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE)
 (errmsg(“reference to parent directory (\“..\“) not allowed“))));

/*
 * Allow absolute paths if within DataDir or Log_directory even
 * though Log_directory might be outside DataDir.
 */
if (!path_is_prefix_of_path(DataDir filename) &&
(!logAllowed || !is_absolute_path(Log_directory) ||
 !path_is_prefix_of_path(Log_directory filename)))
ereport(ERROR
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE)
 (errmsg(“absolute path not allowed“))));
}
else if (!path_is_relative_and_below_cwd(filename))
ereport(ERROR
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE)
 (errmsg(“path must be in or below the current directory“))));

return filename;
}


/*
 * check for superuser bark if not.
 */
static void
requireSuperuser(void)
{
if (!superuser())
ereport(ERROR
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE)
 (errmsg(“only superuser may access generic file functions“))));
}



/* ------------------------------------
 * generic file handling functions
 */

Datum
pg_file_write(PG_FUNCTION_ARGS)
{
FILE    *f;
char    *filename;
text    *data;
int64 count = 0;

requireSuperuser();

filename = convert_and_check_filename(PG_GETARG_TEXT_PP(0) false);
data = PG_GETARG_TEXT_PP(1);

if (!PG_GETARG_BOOL(2))
{
struct stat fst;

if (stat(filename &fst) >= 0)
ereport(ERROR
(ERRCODE_DUPLICATE_FILE
 errmsg(“file \“%s\“ exists

评论

共有 条评论