Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4e9dd95

Browse files
committed
From: Peter T Mount <patches@maidast.demon.co.uk>
[This is a repost - it supercedes the previous one. It fixes the patch soit doesn't bread aix port, plus there's a file missing out of theoriginal post because difforig doesn't pick up new files. It's nowattached. peter]This patch brings the JDBC driver up to the current protocol spec.Basically, the backend now tells the driver what authentication scheme touse.The patch also fixes a performance problem with large objects. In thebuffer manager, each fastpath call was sending multiple Notifications tothe backend (sometimes more data in the form of notifications were beingsent than blob data!).
1 parent67c92f4 commit4e9dd95

File tree

7 files changed

+214
-76
lines changed

7 files changed

+214
-76
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.32 1998/01/25 05:13:53 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.33 1998/02/0213:16:31 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1532,6 +1532,7 @@ PrintBufferDescs()
15321532
if (IsUnderPostmaster)
15331533
{
15341534
SpinAcquire(BufMgrLock);
1535+
#if0
15351536
for (i=0;i<NBuffers;++i,++buf)
15361537
{
15371538
elog(NOTICE,"[%02d] (freeNext=%d, freePrev=%d, relname=%s, \
@@ -1540,6 +1541,7 @@ blockNum=%d, flags=0x%x, refcount=%d %d)",
15401541
buf->sb_relname,buf->tag.blockNum,buf->flags,
15411542
buf->refcount,PrivateRefCount[i]);
15421543
}
1544+
#endif
15431545
SpinRelease(BufMgrLock);
15441546
}
15451547
else

‎src/interfaces/jdbc/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for Java JDBC interface
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.4 1998/01/13 02:19:10 scrappy Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.5 1998/02/02 13:16:38 scrappy Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -33,8 +33,9 @@ all: postgresql.jar
3333
@echo
3434
@echo Then either add -Djdbc.drivers=postgresql.Driver to the
3535
@echo commandline when running your application, or edit the
36-
@echo"properties file (~/.hotjava/properties under unix), and"
37-
@echo add a line containing jdbc.drivers=postgresql.Driver
36+
@echo"properties file for your application (~/.hotjava/properties"
37+
@echo"under unix for HotJava), and add a line containing"
38+
@echo jdbc.drivers=postgresql.Driver
3839
@echo
3940
@echo More details arein the README file.
4041
@echo ------------------------------------------------------------
@@ -76,8 +77,12 @@ OBJS=postgresql/CallableStatement.class \
7677
postgresql/util/PGobject.class\
7778
postgresql/util/PGtokenizer.class
7879

80+
# If you have problems with the first line, try the second one.
81+
# This is needed when compiling under Solaris, as the solaris sh doesn't
82+
# recognise $( )
7983
postgresql.jar:$(OBJS)
80-
$(JAR) -c0vf$@$$($(FIND) postgresql -name "*.class" -print)
84+
$(JAR) -c0f$@$$($(FIND) postgresql -name "*.class" -print)
85+
#$(JAR) -c0f $@ `$(FIND) postgresql -name "*.class" -print`
8186

8287
# This rule removes any temporary and compiled files from the source tree.
8388
clean:

‎src/interfaces/jdbc/postgresql/Connection.java

Lines changed: 130 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public class Connection implements java.sql.Connection
4343
publicbooleanCONNECTION_OK =true;
4444
publicbooleanCONNECTION_BAD =false;
4545

46-
privatestaticfinalintSTARTUP_LEN =288;// Length of a startup packet
46+
//private static final int STARTUP_LEN = 288;// Length of a startup packet
4747

4848
// These are defined in src/include/libpq/pqcomm.h
49-
privateintSTARTUP_CODE =STARTUP_USER;
50-
privatestaticfinalintSTARTUP_USER =7;// User auth
51-
privatestaticfinalintSTARTUP_KRB4 =10;// Kerberos 4 (unused)
52-
privatestaticfinalintSTARTUP_KRB5 =11;// Kerberos 5 (unused)
53-
privatestaticfinalintSTARTUP_HBA =12;// Host Based
54-
privatestaticfinalintSTARTUP_NONE =13;// Unauthenticated (unused)
55-
privatestaticfinalintSTARTUP_PASS =14;// Password auth
49+
//private int STARTUP_CODE = STARTUP_USER;
50+
//private static final int STARTUP_USER = 7;// User auth
51+
//private static final int STARTUP_KRB4 = 10;// Kerberos 4 (unused)
52+
//private static final int STARTUP_KRB5 = 11;// Kerberos 5 (unused)
53+
//private static final int STARTUP_HBA = 12;// Host Based
54+
//private static final int STARTUP_NONE = 13;// Unauthenticated (unused)
55+
//private static final int STARTUP_PASS = 14;// Password auth
5656

5757
privatebooleanautoCommit =true;
5858
privatebooleanreadOnly =false;
@@ -61,8 +61,25 @@ public class Connection implements java.sql.Connection
6161
privateStringthis_url;
6262
privateStringcursor =null;// The positioned update cursor name
6363

64-
// This is false for US, true for European date formats
65-
//protected boolean europeanDates = false;
64+
// These are new for v6.3, they determine the current protocol versions
65+
// supported by this version of the driver. They are defined in
66+
// src/include/libpq/pqcomm.h
67+
protectedstaticfinalintPG_PROTOCOL_LATEST_MAJOR =1;
68+
protectedstaticfinalintPG_PROTOCOL_LATEST_MINOR =0;
69+
privatestaticfinalintSM_DATABASE=64;
70+
privatestaticfinalintSM_USER=32;
71+
privatestaticfinalintSM_OPTIONS=64;
72+
privatestaticfinalintSM_UNUSED=64;
73+
privatestaticfinalintSM_TTY=64;
74+
75+
privatestaticfinalintAUTH_REQ_OK =0;
76+
privatestaticfinalintAUTH_REQ_KRB4 =1;
77+
privatestaticfinalintAUTH_REQ_KRB5 =2;
78+
privatestaticfinalintAUTH_REQ_PASSWORD =3;
79+
privatestaticfinalintAUTH_REQ_CRYPT =4;
80+
81+
// New for 6.3, salt value for crypt authorisation
82+
privateStringsalt;
6683

6784
/**
6885
* This is the current date style of the backend
@@ -120,7 +137,7 @@ public class Connection implements java.sql.Connection
120137
*/
121138
publicConnection(Stringhost,intport,Propertiesinfo,Stringdatabase,Stringurl,Driverd)throwsSQLException
122139
{
123-
intlen =STARTUP_LEN;// Length of a startup packet
140+
//int len = STARTUP_LEN;// Length of a startup packet
124141

125142
this_driver =d;
126143
this_url =newString(url);
@@ -131,24 +148,25 @@ public Connection(String host, int port, Properties info, String database, Strin
131148
PG_HOST =newString(host);
132149
PG_STATUS =CONNECTION_BAD;
133150

151+
// Pre 6.3 code
134152
// This handles the auth property. Any value begining with p enables
135153
// password authentication, while anything begining with i enables
136154
// ident (RFC 1413) authentication. Any other values default to trust.
137155
//
138156
// Also, the postgresql.auth system property can be used to change the
139157
// local default, if the auth property is not present.
140158
//
141-
Stringauth =info.getProperty("auth",System.getProperty("postgresql.auth","trust")).toLowerCase();
142-
if(auth.startsWith("p")) {
143-
// Password authentication
144-
STARTUP_CODE=STARTUP_PASS;
145-
}elseif(auth.startsWith("i")) {
146-
// Ident (RFC 1413) authentication
147-
STARTUP_CODE=STARTUP_HBA;
148-
}else {
149-
// Anything else defaults to trust authentication
150-
STARTUP_CODE=STARTUP_USER;
151-
}
159+
//String auth = info.getProperty("auth",System.getProperty("postgresql.auth","trust")).toLowerCase();
160+
//if(auth.startsWith("p")) {
161+
//// Password authentication
162+
//STARTUP_CODE=STARTUP_PASS;
163+
//} else if(auth.startsWith("i")) {
164+
//// Ident (RFC 1413) authentication
165+
//STARTUP_CODE=STARTUP_HBA;
166+
//} else {
167+
//// Anything else defaults to trust authentication
168+
//STARTUP_CODE=STARTUP_USER;
169+
//}
152170

153171
// Now make the initial connection
154172
try
@@ -161,21 +179,94 @@ public Connection(String host, int port, Properties info, String database, Strin
161179
// Now we need to construct and send a startup packet
162180
try
163181
{
164-
pg_stream.SendInteger(len,4);len -=4;
165-
pg_stream.SendInteger(STARTUP_CODE,4);len -=4;
166-
pg_stream.Send(database.getBytes(),64);len -=64;
167-
pg_stream.Send(PG_USER.getBytes(),len);
182+
// Pre 6.3 code
183+
//pg_stream.SendInteger(len, 4);len -= 4;
184+
//pg_stream.SendInteger(STARTUP_CODE, 4);len -= 4;
185+
//pg_stream.Send(database.getBytes(), 64);len -= 64;
186+
//pg_stream.Send(PG_USER.getBytes(), len);
187+
//
188+
//// Send the password packet if required
189+
//if(STARTUP_CODE == STARTUP_PASS) {
190+
//len=STARTUP_LEN;
191+
//pg_stream.SendInteger(len, 4);len -= 4;
192+
//pg_stream.SendInteger(STARTUP_PASS, 4);len -= 4;
193+
//pg_stream.Send(PG_USER.getBytes(), PG_USER.length());
194+
//len-=PG_USER.length();
195+
//pg_stream.SendInteger(0,1);len -= 1;
196+
//pg_stream.Send(PG_PASSWORD.getBytes(), len);
197+
//}
168198

169-
// Send the password packet if required
170-
if(STARTUP_CODE ==STARTUP_PASS) {
171-
len=STARTUP_LEN;
172-
pg_stream.SendInteger(len,4);len -=4;
173-
pg_stream.SendInteger(STARTUP_PASS,4);len -=4;
174-
pg_stream.Send(PG_USER.getBytes(),PG_USER.length());
175-
len-=PG_USER.length();
176-
pg_stream.SendInteger(0,1);len -=1;
177-
pg_stream.Send(PG_PASSWORD.getBytes(),len);
178-
}
199+
// Ver 6.3 code
200+
pg_stream.SendInteger(4+4+SM_DATABASE+SM_USER+SM_OPTIONS+SM_UNUSED+SM_TTY,4);
201+
pg_stream.SendInteger(PG_PROTOCOL_LATEST_MAJOR,2);
202+
pg_stream.SendInteger(PG_PROTOCOL_LATEST_MINOR,2);
203+
pg_stream.Send(database.getBytes(),SM_DATABASE);
204+
pg_stream.Send(PG_USER.getBytes(),SM_USER+SM_OPTIONS+SM_UNUSED+SM_TTY);
205+
// The last send includes the unused fields
206+
207+
// Now get the response from the backend, either an error message
208+
// or an authentication request
209+
intareq = -1;// must have a value here
210+
do {
211+
intberesp =pg_stream.ReceiveChar();
212+
switch(beresp)
213+
{
214+
case'E':
215+
thrownewSQLException(pg_stream.ReceiveString(4096));
216+
217+
case'R':
218+
// Get the type of request
219+
areq =pg_stream.ReceiveIntegerR(4);
220+
221+
// Get the password salt if there is one
222+
if(areq ==AUTH_REQ_CRYPT) {
223+
byte[]rst =newbyte[2];
224+
rst[0] = (byte)pg_stream.ReceiveChar();
225+
rst[1] = (byte)pg_stream.ReceiveChar();
226+
salt =newString(rst,0,2);
227+
DriverManager.println("Salt="+salt);
228+
}
229+
230+
// now send the auth packet
231+
switch(areq)
232+
{
233+
caseAUTH_REQ_OK:
234+
break;
235+
236+
caseAUTH_REQ_KRB4:
237+
DriverManager.println("postgresql: KRB4");
238+
thrownewSQLException("Kerberos 4 not supported");
239+
240+
caseAUTH_REQ_KRB5:
241+
DriverManager.println("postgresql: KRB5");
242+
thrownewSQLException("Kerberos 5 not supported");
243+
244+
caseAUTH_REQ_PASSWORD:
245+
DriverManager.println("postgresql: PASSWORD");
246+
pg_stream.SendInteger(5+PG_PASSWORD.length(),4);
247+
pg_stream.Send(PG_PASSWORD.getBytes());
248+
pg_stream.SendInteger(0,1);
249+
//pg_stream.SendPacket(PG_PASSWORD.getBytes());
250+
break;
251+
252+
caseAUTH_REQ_CRYPT:
253+
DriverManager.println("postgresql: CRYPT");
254+
Stringcrypted =UnixCrypt.crypt(salt,PG_PASSWORD);
255+
pg_stream.SendInteger(5+crypted.length(),4);
256+
pg_stream.Send(crypted.getBytes());
257+
pg_stream.SendInteger(0,1);
258+
//pg_stream.SendPacket(UnixCrypt.crypt(salt,PG_PASSWORD).getBytes());
259+
break;
260+
261+
default:
262+
thrownewSQLException("Authentication type "+areq+" not supported");
263+
}
264+
break;
265+
266+
default:
267+
thrownewSQLException("error getting authentication request");
268+
}
269+
}while(areq !=AUTH_REQ_OK);
179270

180271
}catch (IOExceptione) {
181272
thrownewSQLException("Connection failed: " +e.toString());
@@ -671,14 +762,14 @@ public synchronized ResultSet ExecSQL(String sql) throws SQLException
671762
*/
672763
privateField[]ReceiveFields()throwsSQLException
673764
{
674-
intnf =pg_stream.ReceiveInteger(2),i;
765+
intnf =pg_stream.ReceiveIntegerR(2),i;
675766
Field[]fields =newField[nf];
676767

677768
for (i =0 ;i <nf ; ++i)
678769
{
679770
Stringtypname =pg_stream.ReceiveString(8192);
680-
inttypid =pg_stream.ReceiveInteger(4);
681-
inttyplen =pg_stream.ReceiveInteger(2);
771+
inttypid =pg_stream.ReceiveIntegerR(4);
772+
inttyplen =pg_stream.ReceiveIntegerR(2);
682773
fields[i] =newField(this,typname,typid,typlen);
683774
}
684775
returnfields;

‎src/interfaces/jdbc/postgresql/DatabaseMetaData.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,30 +1925,28 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
19251925
*/
19261926
publicjava.sql.ResultSetgetColumnPrivileges(Stringcatalog,Stringschema,Stringtable,StringcolumnNamePattern)throwsSQLException
19271927
{
1928-
// XXX-Not Implemented as grant is broken
1929-
returnnull;
1930-
//Field f[] = new Field[8];
1931-
//Vector v = new Vector();
1932-
//
1933-
//f[0] = new Field(connection,new String("TABLE_CAT"),iVarcharOid,32);
1934-
//f[1] = new Field(connection,new String("TABLE_SCHEM"),iVarcharOid,32);
1935-
//f[2] = new Field(connection,new String("TABLE_NAME"),iVarcharOid,32);
1936-
//f[3] = new Field(connection,new String("COLUMN_NAME"),iVarcharOid,32);
1937-
//f[4] = new Field(connection,new String("GRANTOR"),iVarcharOid,32);
1938-
//f[5] = new Field(connection,new String("GRANTEE"),iVarcharOid,32);
1939-
//f[6] = new Field(connection,new String("PRIVILEGE"),iVarcharOid,32);
1940-
//f[7] = new Field(connection,new String("IS_GRANTABLE"),iVarcharOid,32);
1941-
//
1942-
//// This is taken direct from the psql source
1943-
//ResultSet r = connection.ExecSQL("SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner ORDER BY relname");
1944-
//while(r.next()) {
1945-
//byte[][] tuple = new byte[8][0];
1946-
//tuple[0] = tuple[1]= "default".getBytes();
1947-
//
1948-
//v.addElement(tuple);
1949-
//}
1950-
//
1951-
//return new ResultSet(connection,f,v,"OK",1);
1928+
Fieldf[] =newField[8];
1929+
Vectorv =newVector();
1930+
1931+
f[0] =newField(connection,newString("TABLE_CAT"),iVarcharOid,32);
1932+
f[1] =newField(connection,newString("TABLE_SCHEM"),iVarcharOid,32);
1933+
f[2] =newField(connection,newString("TABLE_NAME"),iVarcharOid,32);
1934+
f[3] =newField(connection,newString("COLUMN_NAME"),iVarcharOid,32);
1935+
f[4] =newField(connection,newString("GRANTOR"),iVarcharOid,32);
1936+
f[5] =newField(connection,newString("GRANTEE"),iVarcharOid,32);
1937+
f[6] =newField(connection,newString("PRIVILEGE"),iVarcharOid,32);
1938+
f[7] =newField(connection,newString("IS_GRANTABLE"),iVarcharOid,32);
1939+
1940+
// This is taken direct from the psql source
1941+
ResultSetr =connection.ExecSQL("SELECT relname, relacl FROM pg_class, pg_user WHERE ( relkind = 'r' OR relkind = 'i') and relname !~ '^pg_' and relname !~ '^xin[vx][0-9]+' and usesysid = relowner ORDER BY relname");
1942+
while(r.next()) {
1943+
byte[][]tuple =newbyte[8][0];
1944+
tuple[0] =tuple[1]="".getBytes();
1945+
DriverManager.println("relname=\""+r.getString(1)+"\" relacl=\""+r.getString(2)+"\"");
1946+
//v.addElement(tuple);
1947+
}
1948+
1949+
returnnewResultSet(connection,f,v,"OK",1);
19521950
}
19531951

19541952
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp