| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifdef HAVE_CONFIG_H |
|---|
| 20 |
# include <config.h> |
|---|
| 21 |
#endif |
|---|
| 22 |
|
|---|
| 23 |
#include "vserver.h" |
|---|
| 24 |
#include "internal.h" |
|---|
| 25 |
#include "pathconfig.h" |
|---|
| 26 |
|
|---|
| 27 |
#include <string.h> |
|---|
| 28 |
#include <unistd.h> |
|---|
| 29 |
#include <sys/param.h> |
|---|
| 30 |
#include <fcntl.h> |
|---|
| 31 |
|
|---|
| 32 |
static char * |
|---|
| 33 |
getDir(char *dir, bool physical) |
|---|
| 34 |
{ |
|---|
| 35 |
int fd; |
|---|
| 36 |
char tmp[PATH_MAX]; |
|---|
| 37 |
|
|---|
| 38 |
if (!physical) return strdup(dir); |
|---|
| 39 |
|
|---|
| 40 |
fd = open(".", O_RDONLY); |
|---|
| 41 |
if (fd==-1) return 0; |
|---|
| 42 |
|
|---|
| 43 |
if (chdir(dir)!=-1 && |
|---|
| 44 |
getcwd(tmp, sizeof tmp)!=0) |
|---|
| 45 |
dir = strdup(tmp); |
|---|
| 46 |
else |
|---|
| 47 |
dir = 0; |
|---|
| 48 |
|
|---|
| 49 |
if (fchdir(fd)==-1) { |
|---|
| 50 |
if (write(2, "FATAL error: failed to restore directory\n", 41)!=41) { } |
|---|
| 51 |
abort(); |
|---|
| 52 |
} |
|---|
| 53 |
close(fd); |
|---|
| 54 |
return dir; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
char * |
|---|
| 58 |
vc_getVserverVdir(char const *id, vcCfgStyle style, bool physical) |
|---|
| 59 |
{ |
|---|
| 60 |
size_t l1 = strlen(id); |
|---|
| 61 |
char *res = 0; |
|---|
| 62 |
|
|---|
| 63 |
if (style==vcCFG_NONE || style==vcCFG_AUTO) |
|---|
| 64 |
style = vc_getVserverCfgStyle(id); |
|---|
| 65 |
|
|---|
| 66 |
switch (style) { |
|---|
| 67 |
case vcCFG_NONE : return 0; |
|---|
| 68 |
case vcCFG_LEGACY : |
|---|
| 69 |
{ |
|---|
| 70 |
char buf[sizeof(DEFAULT_VSERVERDIR "/") + l1]; |
|---|
| 71 |
|
|---|
| 72 |
strcpy(buf, DEFAULT_VSERVERDIR "/"); |
|---|
| 73 |
strcpy(buf+sizeof(DEFAULT_VSERVERDIR "/") - 1, id); |
|---|
| 74 |
|
|---|
| 75 |
res = getDir(buf, physical); |
|---|
| 76 |
break; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
case vcCFG_RECENT_SHORT : |
|---|
| 80 |
{ |
|---|
| 81 |
char buf[sizeof(CONFDIR) + l1 + sizeof("//vdir") - 1]; |
|---|
| 82 |
|
|---|
| 83 |
strcpy(buf, CONFDIR "/"); |
|---|
| 84 |
strcpy(buf+sizeof(CONFDIR "/") - 1, id); |
|---|
| 85 |
strcpy(buf+sizeof(CONFDIR "/")+l1 - 1, "/vdir"); |
|---|
| 86 |
|
|---|
| 87 |
res = getDir(buf, physical); |
|---|
| 88 |
break; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
case vcCFG_RECENT_FULL : |
|---|
| 92 |
{ |
|---|
| 93 |
char buf[l1 + sizeof("/vdir")]; |
|---|
| 94 |
|
|---|
| 95 |
strcpy(buf, id); |
|---|
| 96 |
strcpy(buf+l1, "/vdir"); |
|---|
| 97 |
|
|---|
| 98 |
res = getDir(buf, physical); |
|---|
| 99 |
break; |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
default : return 0; |
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
if (!physical && !utilvserver_isDirectory(res, true)) { |
|---|
| 108 |
free(res); |
|---|
| 109 |
res = 0; |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
return res; |
|---|
| 113 |
} |
|---|