|
|
|
|
@ -8,7 +8,7 @@ |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* IDENTIFICATION |
|
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.112 2003/08/04 02:40:06 momjian Exp $ |
|
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.113 2003/08/04 04:03:10 tgl Exp $ |
|
|
|
|
* |
|
|
|
|
*------------------------------------------------------------------------- |
|
|
|
|
*/ |
|
|
|
|
@ -48,13 +48,6 @@ ProcessingMode Mode = InitProcessing; |
|
|
|
|
static char directoryLockFile[MAXPGPATH]; |
|
|
|
|
static char socketLockFile[MAXPGPATH]; |
|
|
|
|
|
|
|
|
|
#ifdef CYR_RECODE |
|
|
|
|
static unsigned char RecodeForwTable[128]; |
|
|
|
|
static unsigned char RecodeBackTable[128]; |
|
|
|
|
|
|
|
|
|
static void GetCharSetByHost(char *TableName, int host, const char *DataDir); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* ignoring system indexes support stuff |
|
|
|
|
@ -181,295 +174,6 @@ SetDataDir(const char *dir) |
|
|
|
|
DataDir = new; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* CYR_RECODE support |
|
|
|
|
* ---------------------------------------------------------------- |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifdef CYR_RECODE |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
SetCharSet(void) |
|
|
|
|
{ |
|
|
|
|
FILE *file; |
|
|
|
|
char *filename; |
|
|
|
|
char *map_file; |
|
|
|
|
char buf[MAX_TOKEN]; |
|
|
|
|
int i; |
|
|
|
|
unsigned char FromChar, |
|
|
|
|
ToChar; |
|
|
|
|
char ChTable[MAX_TOKEN]; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < 128; i++) |
|
|
|
|
{ |
|
|
|
|
RecodeForwTable[i] = i + 128; |
|
|
|
|
RecodeBackTable[i] = i + 128; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (IsUnderPostmaster) |
|
|
|
|
{ |
|
|
|
|
GetCharSetByHost(ChTable, MyProcPort->raddr.in.sin_addr.s_addr, DataDir); |
|
|
|
|
filename = ChTable; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
filename = getenv("PG_RECODETABLE"); |
|
|
|
|
|
|
|
|
|
if (filename && *filename != '\0') |
|
|
|
|
{ |
|
|
|
|
map_file = palloc(strlen(DataDir) + strlen(filename) + 2); |
|
|
|
|
sprintf(map_file, "%s/%s", DataDir, filename); |
|
|
|
|
file = AllocateFile(map_file, "r"); |
|
|
|
|
pfree(map_file); |
|
|
|
|
if (file == NULL) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
while (!feof(file)) |
|
|
|
|
{ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
FromChar = strtoul(buf, 0, 0); |
|
|
|
|
/* Read the ToChar */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
ToChar = strtoul(buf, 0, 0); |
|
|
|
|
RecodeForwTable[FromChar - 128] = ToChar; |
|
|
|
|
RecodeBackTable[ToChar - 128] = FromChar; |
|
|
|
|
|
|
|
|
|
/* read to EOL */ |
|
|
|
|
while (!feof(file) && buf[0]) |
|
|
|
|
{ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
elog(LOG, "unexpected token %s in file %s", |
|
|
|
|
buf, filename); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FreeFile(file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char * |
|
|
|
|
convertstr(unsigned char *buff, int len, int dest) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
char *ch = buff; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++, buff++) |
|
|
|
|
{ |
|
|
|
|
if (*buff > 127) |
|
|
|
|
{ |
|
|
|
|
if (dest) |
|
|
|
|
*buff = RecodeForwTable[*buff - 128]; |
|
|
|
|
else |
|
|
|
|
*buff = RecodeBackTable[*buff - 128]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ch; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define CHARSET_FILE "charset.conf" |
|
|
|
|
#define MAX_CHARSETS 10 |
|
|
|
|
#define KEY_HOST 1 |
|
|
|
|
#define KEY_BASE 2 |
|
|
|
|
#define KEY_TABLE 3 |
|
|
|
|
|
|
|
|
|
struct CharsetItem |
|
|
|
|
{ |
|
|
|
|
char Orig[MAX_TOKEN]; |
|
|
|
|
char Dest[MAX_TOKEN]; |
|
|
|
|
char Table[MAX_TOKEN]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static bool |
|
|
|
|
CharSetInRange(char *buf, int host) |
|
|
|
|
{ |
|
|
|
|
int valid, |
|
|
|
|
i, |
|
|
|
|
FromAddr, |
|
|
|
|
ToAddr, |
|
|
|
|
tmp; |
|
|
|
|
struct in_addr file_ip_addr; |
|
|
|
|
char *p; |
|
|
|
|
unsigned int one = 0x80000000, |
|
|
|
|
NetMask = 0; |
|
|
|
|
unsigned char mask; |
|
|
|
|
|
|
|
|
|
p = strchr(buf, '/'); |
|
|
|
|
if (p) |
|
|
|
|
{ |
|
|
|
|
*p++ = '\0'; |
|
|
|
|
valid = inet_aton(buf, &file_ip_addr); |
|
|
|
|
if (valid) |
|
|
|
|
{ |
|
|
|
|
mask = strtoul(p, 0, 0); |
|
|
|
|
FromAddr = ntohl(file_ip_addr.s_addr); |
|
|
|
|
ToAddr = ntohl(file_ip_addr.s_addr); |
|
|
|
|
for (i = 0; i < mask; i++) |
|
|
|
|
{ |
|
|
|
|
NetMask |= one; |
|
|
|
|
one >>= 1; |
|
|
|
|
} |
|
|
|
|
FromAddr &= NetMask; |
|
|
|
|
ToAddr = ToAddr | ~NetMask; |
|
|
|
|
tmp = ntohl(host); |
|
|
|
|
return ((unsigned) tmp >= (unsigned) FromAddr && |
|
|
|
|
(unsigned) tmp <= (unsigned) ToAddr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
p = strchr(buf, '-'); |
|
|
|
|
if (p) |
|
|
|
|
{ |
|
|
|
|
*p++ = '\0'; |
|
|
|
|
valid = inet_aton(buf, &file_ip_addr); |
|
|
|
|
if (valid) |
|
|
|
|
{ |
|
|
|
|
FromAddr = ntohl(file_ip_addr.s_addr); |
|
|
|
|
valid = inet_aton(p, &file_ip_addr); |
|
|
|
|
if (valid) |
|
|
|
|
{ |
|
|
|
|
ToAddr = ntohl(file_ip_addr.s_addr); |
|
|
|
|
tmp = ntohl(host); |
|
|
|
|
return ((unsigned) tmp >= (unsigned) FromAddr && |
|
|
|
|
(unsigned) tmp <= (unsigned) ToAddr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
valid = inet_aton(buf, &file_ip_addr); |
|
|
|
|
if (valid) |
|
|
|
|
{ |
|
|
|
|
FromAddr = file_ip_addr.s_addr; |
|
|
|
|
return (unsigned) FromAddr == (unsigned) host; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
GetCharSetByHost(char *TableName, int host, const char *DataDir) |
|
|
|
|
{ |
|
|
|
|
FILE *file; |
|
|
|
|
char buf[MAX_TOKEN], |
|
|
|
|
BaseCharset[MAX_TOKEN], |
|
|
|
|
OrigCharset[MAX_TOKEN], |
|
|
|
|
DestCharset[MAX_TOKEN], |
|
|
|
|
HostCharset[MAX_TOKEN], |
|
|
|
|
*map_file; |
|
|
|
|
int key, |
|
|
|
|
ChIndex = 0, |
|
|
|
|
i, |
|
|
|
|
bufsize; |
|
|
|
|
struct CharsetItem *ChArray[MAX_CHARSETS]; |
|
|
|
|
|
|
|
|
|
*TableName = '\0'; |
|
|
|
|
bufsize = (strlen(DataDir) + strlen(CHARSET_FILE) + 2) * sizeof(char); |
|
|
|
|
map_file = (char *) palloc(bufsize); |
|
|
|
|
snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE); |
|
|
|
|
file = AllocateFile(map_file, "r"); |
|
|
|
|
pfree(map_file); |
|
|
|
|
if (file == NULL) |
|
|
|
|
{ |
|
|
|
|
/* XXX should we log a complaint? */ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (!feof(file)) |
|
|
|
|
{ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
key = 0; |
|
|
|
|
if (strcasecmp(buf, "HostCharset") == 0) |
|
|
|
|
key = KEY_HOST; |
|
|
|
|
else if (strcasecmp(buf, "BaseCharset") == 0) |
|
|
|
|
key = KEY_BASE; |
|
|
|
|
else if (strcasecmp(buf, "RecodeTable") == 0) |
|
|
|
|
key = KEY_TABLE; |
|
|
|
|
else |
|
|
|
|
elog(LOG, "unrecognized tag %s in file %s", |
|
|
|
|
buf, CHARSET_FILE); |
|
|
|
|
|
|
|
|
|
switch (key) |
|
|
|
|
{ |
|
|
|
|
case KEY_HOST: |
|
|
|
|
/* Read the host */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
if (CharSetInRange(buf, host)) |
|
|
|
|
{ |
|
|
|
|
/* Read the charset */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
strcpy(HostCharset, buf); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case KEY_BASE: |
|
|
|
|
/* Read the base charset */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
strcpy(BaseCharset, buf); |
|
|
|
|
break; |
|
|
|
|
case KEY_TABLE: |
|
|
|
|
/* Read the original charset */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
strcpy(OrigCharset, buf); |
|
|
|
|
/* Read the destination charset */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
strcpy(DestCharset, buf); |
|
|
|
|
/* Read the table filename */ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
if (buf[0] != '\0') |
|
|
|
|
{ |
|
|
|
|
ChArray[ChIndex] = |
|
|
|
|
(struct CharsetItem *) palloc(sizeof(struct CharsetItem)); |
|
|
|
|
strcpy(ChArray[ChIndex]->Orig, OrigCharset); |
|
|
|
|
strcpy(ChArray[ChIndex]->Dest, DestCharset); |
|
|
|
|
strcpy(ChArray[ChIndex]->Table, buf); |
|
|
|
|
ChIndex++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* read to EOL */ |
|
|
|
|
while (!feof(file) && buf[0]) |
|
|
|
|
{ |
|
|
|
|
next_token(file, buf, sizeof(buf)); |
|
|
|
|
elog(LOG, "unrecognized tag %s in file %s", |
|
|
|
|
buf, CHARSET_FILE); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
FreeFile(file); |
|
|
|
|
|
|
|
|
|
for (i = 0; i < ChIndex; i++) |
|
|
|
|
{ |
|
|
|
|
if (strcasecmp(BaseCharset, ChArray[i]->Orig) == 0 && |
|
|
|
|
strcasecmp(HostCharset, ChArray[i]->Dest) == 0) |
|
|
|
|
strncpy(TableName, ChArray[i]->Table, 79); |
|
|
|
|
pfree(ChArray[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif /* CYR_RECODE */ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
|
* User ID things |
|
|
|
|
|