|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $PostgreSQL: pgsql/src/backend/utils/misc/database.c,v 1.59 2003/11/29 19:52:03 pgsql Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/utils/misc/database.c,v 1.60 2004/01/22 20:57:39 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
|
28 | 28 | staticboolPhonyHeapTupleSatisfiesNow(HeapTupleHeadertuple); |
29 | 29 |
|
30 | 30 |
|
31 | | -/* |
32 | | - * ExpandDatabasePath resolves a proposed database path (obtained from |
33 | | - * pg_database.datpath) to a full absolute path for further consumption. |
34 | | - * NULL means an error, which the caller should process. One reason for |
35 | | - * such an error would be an absolute alternative path when no absolute |
36 | | - * paths are allowed. |
37 | | - */ |
38 | | - |
39 | | -char* |
40 | | -ExpandDatabasePath(constchar*dbpath) |
41 | | -{ |
42 | | -charbuf[MAXPGPATH]; |
43 | | -constchar*cp; |
44 | | -intlen; |
45 | | - |
46 | | -AssertArg(dbpath); |
47 | | -Assert(DataDir); |
48 | | - |
49 | | -if (strlen(dbpath) >=MAXPGPATH) |
50 | | -returnNULL;/* ain't gonna fit nohow */ |
51 | | - |
52 | | -/* leading path delimiter? then already absolute path */ |
53 | | -if (is_absolute_path(dbpath)) |
54 | | -{ |
55 | | -#ifdefALLOW_ABSOLUTE_DBPATHS |
56 | | -cp=last_path_separator(dbpath); |
57 | | -len=cp-dbpath; |
58 | | -strncpy(buf,dbpath,len); |
59 | | -snprintf(&buf[len],MAXPGPATH-len,"/base/%s", (cp+1)); |
60 | | -#else |
61 | | -returnNULL; |
62 | | -#endif |
63 | | -} |
64 | | -/* path delimiter somewhere? then has leading environment variable */ |
65 | | -elseif ((cp=first_path_separator(dbpath))!=NULL) |
66 | | -{ |
67 | | -constchar*envvar; |
68 | | - |
69 | | -len=cp-dbpath; |
70 | | -strncpy(buf,dbpath,len); |
71 | | -buf[len]='\0'; |
72 | | -envvar=getenv(buf); |
73 | | -if (envvar==NULL) |
74 | | -returnNULL; |
75 | | - |
76 | | -snprintf(buf,sizeof(buf),"%s/base/%s",envvar, (cp+1)); |
77 | | -} |
78 | | -else |
79 | | -{ |
80 | | -/* no path delimiter? then add the default path prefix */ |
81 | | -snprintf(buf,sizeof(buf),"%s/base/%s",DataDir,dbpath); |
82 | | -} |
83 | | - |
84 | | -/* |
85 | | - * check for illegal characters in dbpath these should really throw an |
86 | | - * error, shouldn't they? or else all callers need to test for NULL |
87 | | - */ |
88 | | -for (cp=buf;*cp;cp++) |
89 | | -{ |
90 | | -/* |
91 | | - * The following characters will not be allowed anywhere in the |
92 | | - * database path. (Do not include the slash or '.' here.) |
93 | | - */ |
94 | | -charillegal_dbpath_chars[]= |
95 | | -"\001\002\003\004\005\006\007\010" |
96 | | -"\011\012\013\014\015\016\017\020" |
97 | | -"\021\022\023\024\025\026\027\030" |
98 | | -"\031\032\033\034\035\036\037" |
99 | | -"'`"; |
100 | | - |
101 | | -constchar*cx; |
102 | | - |
103 | | -for (cx=illegal_dbpath_chars;*cx;cx++) |
104 | | -if (*cp==*cx) |
105 | | -returnNULL; |
106 | | -/* don't allow access to parent dirs */ |
107 | | -if (strncmp(cp,"/../",4)==0) |
108 | | -returnNULL; |
109 | | -} |
110 | | - |
111 | | -returnpstrdup(buf); |
112 | | -}/* ExpandDatabasePath() */ |
113 | | - |
114 | | - |
115 | | - |
116 | 31 | /* -------------------------------- |
117 | 32 | *GetRawDatabaseInfo() -- Find the OID and path of the database. |
118 | 33 | * |
|