|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.27 1998/01/27 03:24:56 scrappy Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.28 1998/02/24 15:18:41 scrappy Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -846,6 +846,192 @@ authident(struct sockaddr_in *raddr, struct sockaddr_in *laddr,
|
846 | 846 | }
|
847 | 847 |
|
848 | 848 |
|
| 849 | +#ifdef CYR_RECODE |
| 850 | +#define CHARSET_FILE "charset.conf" |
| 851 | +#define MAX_CHARSETS 10 |
| 852 | +#define KEY_HOST 1 |
| 853 | +#define KEY_BASE 2 |
| 854 | +#define KEY_TABLE 3 |
| 855 | + |
| 856 | +struct CharsetItem |
| 857 | +{ |
| 858 | + char Orig[MAX_TOKEN]; |
| 859 | + char Dest[MAX_TOKEN]; |
| 860 | + char Table[MAX_TOKEN]; |
| 861 | +}; |
| 862 | + |
| 863 | +int InRange(char *buf,int host) |
| 864 | +{ |
| 865 | + int valid,i,FromAddr,ToAddr,tmp; |
| 866 | + struct in_addr file_ip_addr; |
| 867 | + char *p; |
| 868 | + unsigned int one=0x80000000,NetMask=0; |
| 869 | + unsigned char mask; |
| 870 | + p = strchr(buf,'/'); |
| 871 | + if(p) |
| 872 | + { |
| 873 | + *p++ = '\0'; |
| 874 | + valid = inet_aton(buf, &file_ip_addr); |
| 875 | + if(valid) |
| 876 | + { |
| 877 | + mask = strtoul(p,0,0); |
| 878 | + FromAddr = ntohl(file_ip_addr.s_addr); |
| 879 | + ToAddr = ntohl(file_ip_addr.s_addr); |
| 880 | + for(i=0;i<mask;i++) |
| 881 | + { |
| 882 | + NetMask |= one; |
| 883 | + one >>= 1; |
| 884 | + } |
| 885 | + FromAddr &= NetMask; |
| 886 | + ToAddr = ToAddr | ~NetMask; |
| 887 | + tmp = ntohl(host); |
| 888 | + return ((unsigned)tmp>=(unsigned)FromAddr && |
| 889 | + (unsigned)tmp<=(unsigned)ToAddr); |
| 890 | + } |
| 891 | + } |
| 892 | + else |
| 893 | + { |
| 894 | + p = strchr(buf,'-'); |
| 895 | + if(p) |
| 896 | + { |
| 897 | + *p++ = '\0'; |
| 898 | + valid = inet_aton(buf, &file_ip_addr); |
| 899 | + if(valid) |
| 900 | + { |
| 901 | + FromAddr = ntohl(file_ip_addr.s_addr); |
| 902 | + valid = inet_aton(p, &file_ip_addr); |
| 903 | + if(valid) |
| 904 | + { |
| 905 | + ToAddr = ntohl(file_ip_addr.s_addr); |
| 906 | + tmp = ntohl(host); |
| 907 | + return ((unsigned)tmp>=(unsigned)FromAddr && |
| 908 | + (unsigned)tmp<=(unsigned)ToAddr); |
| 909 | + } |
| 910 | + } |
| 911 | + } |
| 912 | + else |
| 913 | + { |
| 914 | + valid = inet_aton(buf, &file_ip_addr); |
| 915 | + if(valid) |
| 916 | + { |
| 917 | + FromAddr = file_ip_addr.s_addr; |
| 918 | + return ((unsigned)FromAddr == (unsigned)host); |
| 919 | + } |
| 920 | + } |
| 921 | + } |
| 922 | + return false; |
| 923 | +} |
| 924 | + |
| 925 | +void GetCharSetByHost(char TableName[],int host, const char DataDir[]) |
| 926 | +{ |
| 927 | + FILE *file; |
| 928 | + char buf[MAX_TOKEN],BaseCharset[MAX_TOKEN], |
| 929 | + OrigCharset[MAX_TOKEN],DestCharset[MAX_TOKEN],HostCharset[MAX_TOKEN]; |
| 930 | + char c,eof=false; |
| 931 | + char *map_file; |
| 932 | + int key=0,i; |
| 933 | + struct CharsetItem* ChArray[MAX_CHARSETS]; |
| 934 | + int ChIndex=0; |
| 935 | + |
| 936 | + *TableName = '\0'; |
| 937 | + map_file = (char *) malloc((strlen(DataDir) + |
| 938 | + strlen(CHARSET_FILE)+2)*sizeof(char)); |
| 939 | + sprintf(map_file, "%s/%s", DataDir, CHARSET_FILE); |
| 940 | + file = fopen(map_file, "r"); |
| 941 | + if (file == NULL) |
| 942 | + return; |
| 943 | + while (!eof) |
| 944 | + { |
| 945 | + c = getc(file); |
| 946 | + ungetc(c, file); |
| 947 | + if (c == EOF) |
| 948 | + eof = true; |
| 949 | + else |
| 950 | + { |
| 951 | + if (c == '#') |
| 952 | + read_through_eol(file); |
| 953 | + else |
| 954 | + { |
| 955 | + /* Read the key */ |
| 956 | + next_token(file, buf, sizeof(buf)); |
| 957 | + if (buf[0] != '\0') |
| 958 | + { |
| 959 | + if (strcasecmp(buf, "HostCharset") == 0) |
| 960 | + key = KEY_HOST; |
| 961 | + if (strcasecmp(buf, "BaseCharset") == 0) |
| 962 | + key = KEY_BASE; |
| 963 | + if (strcasecmp(buf, "RecodeTable") == 0) |
| 964 | + key = KEY_TABLE; |
| 965 | + switch(key) |
| 966 | + { |
| 967 | + case KEY_HOST: |
| 968 | + /* Read the host */ |
| 969 | + next_token(file, buf, sizeof(buf)); |
| 970 | + if (buf[0] != '\0') |
| 971 | + { |
| 972 | + if (InRange(buf,host)) |
| 973 | + { |
| 974 | + /* Read the charset */ |
| 975 | + next_token(file, buf, sizeof(buf)); |
| 976 | + if (buf[0] != '\0') |
| 977 | + { |
| 978 | + strcpy(HostCharset,buf); |
| 979 | + } |
| 980 | + } |
| 981 | + } |
| 982 | + break; |
| 983 | + case KEY_BASE: |
| 984 | + /* Read the base charset */ |
| 985 | + next_token(file, buf, sizeof(buf)); |
| 986 | + if (buf[0] != '\0') |
| 987 | + { |
| 988 | + strcpy(BaseCharset,buf); |
| 989 | + } |
| 990 | + break; |
| 991 | + case KEY_TABLE: |
| 992 | + /* Read the original charset */ |
| 993 | + next_token(file, buf, sizeof(buf)); |
| 994 | + if (buf[0] != '\0') |
| 995 | + { |
| 996 | + strcpy(OrigCharset,buf); |
| 997 | + /* Read the destination charset */ |
| 998 | + next_token(file, buf, sizeof(buf)); |
| 999 | + if (buf[0] != '\0') |
| 1000 | + { |
| 1001 | + strcpy(DestCharset,buf); |
| 1002 | + /* Read the table filename */ |
| 1003 | + next_token(file, buf, sizeof(buf)); |
| 1004 | + if (buf[0] != '\0') |
| 1005 | + { |
| 1006 | + ChArray[ChIndex] = (struct CharsetItem *) malloc(sizeof(struct CharsetItem)); |
| 1007 | + strcpy(ChArray[ChIndex]->Orig,OrigCharset); |
| 1008 | + strcpy(ChArray[ChIndex]->Dest,DestCharset); |
| 1009 | + strcpy(ChArray[ChIndex]->Table,buf); |
| 1010 | + ChIndex++; |
| 1011 | + } |
| 1012 | + } |
| 1013 | + } |
| 1014 | + break; |
| 1015 | + } |
| 1016 | + read_through_eol(file); |
| 1017 | + } |
| 1018 | + } |
| 1019 | + } |
| 1020 | + } |
| 1021 | + fclose(file); |
| 1022 | + free(map_file); |
| 1023 | + |
| 1024 | + for(i=0; i<ChIndex; i++) |
| 1025 | + { |
| 1026 | + if(!strcasecmp(BaseCharset,ChArray[i]->Orig) && |
| 1027 | + !strcasecmp(HostCharset,ChArray[i]->Dest)) |
| 1028 | + { |
| 1029 | + strncpy(TableName,ChArray[i]->Table,79); |
| 1030 | + } |
| 1031 | + free((struct CharsetItem *) ChArray[i]); |
| 1032 | + } |
| 1033 | +} |
| 1034 | +#endif |
849 | 1035 |
|
850 | 1036 | extern int
|
851 | 1037 | hba_getauthmethod(SockAddr *raddr, char *database, char *auth_arg,
|
|
0 commit comments