Index: src/backend/libpq/ip.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/libpq/ip.c,v retrieving revision 1.2 diff -c -r1.2 ip.c *** src/backend/libpq/ip.c 2003/01/09 14:35:03 1.2 --- src/backend/libpq/ip.c 2003/01/13 11:59:35 *************** *** 20,25 **** --- 20,26 ---- #ifndef FRONTEND #include "postgres.h" #else + #include "libpq-reentrant.h" #include "postgres_fe.h" #endif *************** *** 80,88 **** result->in.sin_addr.s_addr = htonl(INADDR_ANY); else { ! struct hostent *hp; ! hp = gethostbyname(hostname); if ((hp == NULL) || (hp->h_addrtype != AF_INET)) { elog(LOG, "getaddrinfo2: gethostbyname(%s) failed\n", hostname); --- 81,97 ---- result->in.sin_addr.s_addr = htonl(INADDR_ANY); else { ! struct hostent *hp = NULL; ! #ifdef FRONTEND ! struct hostent hpstr; ! char buf[BUFSIZ]; ! int herrno = 0; ! pqGethostbyname(hostname, &hpstr, buf, sizeof(buf), ! &hp, &herrno); ! #else ! hp = gethostbyname(hostname); ! #endif if ((hp == NULL) || (hp->h_addrtype != AF_INET)) { elog(LOG, "getaddrinfo2: gethostbyname(%s) failed\n", hostname); Index: src/interfaces/libpq/Makefile =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/Makefile,v retrieving revision 1.72 diff -c -r1.72 Makefile *** src/interfaces/libpq/Makefile 2003/01/10 10:59:08 1.72 --- src/interfaces/libpq/Makefile 2003/01/13 11:59:35 *************** *** 20,28 **** override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"' ! OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \ ! pqexpbuffer.o dllist.o pqsignal.o fe-secure.o wchar.o encnames.o ip.o \ ! md5.o \ $(filter inet_aton.o snprintf.o strerror.o, $(LIBOBJS)) --- 20,28 ---- override CPPFLAGS := -I$(srcdir) $(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"' ! OBJS= libpq-reentrant.o fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o \ ! fe-lobj.o pqexpbuffer.o dllist.o pqsignal.o fe-secure.o wchar.o encnames.o \ ! ip.o md5.o \ $(filter inet_aton.o snprintf.o strerror.o, $(LIBOBJS)) Index: src/interfaces/libpq/fe-auth.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-auth.c,v retrieving revision 1.72 diff -c -r1.72 fe-auth.c *** src/interfaces/libpq/fe-auth.c 2002/12/03 22:09:20 1.72 --- src/interfaces/libpq/fe-auth.c 2003/01/13 11:59:35 *************** *** 28,33 **** --- 28,34 ---- * */ + #include "libpq-reentrant.h" #include "postgres_fe.h" #ifdef WIN32 *************** *** 391,398 **** flags = fcntl(sock, F_GETFL); if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK))) { snprintf(PQerrormsg, PQERRORMSG_LENGTH, ! libpq_gettext("could not set socket to blocking mode: %s\n"), strerror(errno)); krb5_free_principal(pg_krb5_context, server); return STATUS_ERROR; } --- 392,401 ---- flags = fcntl(sock, F_GETFL); if (flags < 0 || fcntl(sock, F_SETFL, (long) (flags & ~O_NONBLOCK))) { + char sebuf[256]; + snprintf(PQerrormsg, PQERRORMSG_LENGTH, ! libpq_gettext("could not set socket to blocking mode: %s\n"), pqStrerror(errno, sebuf, sizeof(sebuf))); krb5_free_principal(pg_krb5_context, server); return STATUS_ERROR; } *************** *** 436,444 **** if (fcntl(sock, F_SETFL, (long) flags)) { snprintf(PQerrormsg, PQERRORMSG_LENGTH, libpq_gettext("could not restore non-blocking mode on socket: %s\n"), ! strerror(errno)); ret = STATUS_ERROR; } --- 439,449 ---- if (fcntl(sock, F_SETFL, (long) flags)) { + char sebuf[256]; + snprintf(PQerrormsg, PQERRORMSG_LENGTH, libpq_gettext("could not restore non-blocking mode on socket: %s\n"), ! pqStrerror(errno, sebuf, sizeof(sebuf))); ret = STATUS_ERROR; } *************** *** 495,502 **** if (sendmsg(conn->sock, &msg, 0) == -1) { snprintf(PQerrormsg, PQERRORMSG_LENGTH, ! "pg_local_sendauth: sendmsg: %s\n", strerror(errno)); return STATUS_ERROR; } return STATUS_OK; --- 500,510 ---- if (sendmsg(conn->sock, &msg, 0) == -1) { + char sebuf[256]; + snprintf(PQerrormsg, PQERRORMSG_LENGTH, ! "pg_local_sendauth: sendmsg: %s\n", ! pqStrerror(errno, sebuf, sizeof(sebuf))); return STATUS_ERROR; } return STATUS_OK; *************** *** 724,733 **** if (GetUserName(username, &namesize)) name = username; #else ! struct passwd *pw = getpwuid(geteuid()); ! ! if (pw) ! name = pw->pw_name; #endif } --- 732,744 ---- if (GetUserName(username, &namesize)) name = username; #else ! char pwdbuf[BUFSIZ]; ! struct passwd pwdstr; ! struct passwd *pw = NULL; ! ! if( pqGetpwuid(geteuid(), &pwdstr, ! pwdbuf, sizeof(pwdbuf), &pw) == 0 ) ! name = pw->pw_name; #endif } Index: src/interfaces/libpq/fe-connect.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-connect.c,v retrieving revision 1.221 diff -c -r1.221 fe-connect.c *** src/interfaces/libpq/fe-connect.c 2003/01/08 21:33:27 1.221 --- src/interfaces/libpq/fe-connect.c 2003/01/13 11:59:36 *************** *** 13,18 **** --- 13,19 ---- *------------------------------------------------------------------------- */ + #include "libpq-reentrant.h" #include "postgres_fe.h" #include *************** *** 716,724 **** if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) #endif { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not set socket to non-blocking mode: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return 0; } --- 717,727 ---- if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) #endif { + char sebuf[256]; + printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not set socket to non-blocking mode: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return 0; } *************** *** 740,748 **** (char *) &on, sizeof(on)) < 0) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not set socket to TCP no delay mode: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return 0; } --- 743,753 ---- (char *) &on, sizeof(on)) < 0) { + char sebuf[256]; + printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not set socket to TCP no delay mode: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return 0; } *************** *** 758,763 **** --- 763,770 ---- static void connectFailureMessage(PGconn *conn, int errorno) { + char sebuf[256]; + if (conn->raddr.sa.sa_family == AF_UNIX) printfPQExpBuffer(&conn->errorMessage, libpq_gettext( *************** *** 765,771 **** "\tIs the server running locally and accepting\n" "\tconnections on Unix domain socket \"%s\"?\n" ), ! SOCK_STRERROR(errorno), conn->raddr.un.sun_path); else printfPQExpBuffer(&conn->errorMessage, --- 772,778 ---- "\tIs the server running locally and accepting\n" "\tconnections on Unix domain socket \"%s\"?\n" ), ! SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)), conn->raddr.un.sun_path); else printfPQExpBuffer(&conn->errorMessage, *************** *** 774,780 **** "\tIs the server running on host %s and accepting\n" "\tTCP/IP connections on port %s?\n" ), ! SOCK_STRERROR(errorno), conn->pghost ? conn->pghost : (conn->pghostaddr --- 781,787 ---- "\tIs the server running on host %s and accepting\n" "\tTCP/IP connections on port %s?\n" ), ! SOCK_STRERROR(errorno, sebuf, sizeof(sebuf)), conn->pghost ? conn->pghost : (conn->pghostaddr *************** *** 797,802 **** --- 804,810 ---- int portnum; int sockfd; char portstr[64]; + char sebuf[256]; #ifdef USE_SSL StartupPacket np; /* Used to negotiate SSL connection */ char SSLok; *************** *** 1013,1019 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not create socket: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); goto connect_errReturn; } else --- 1021,1027 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not create socket: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); goto connect_errReturn; } else *************** *** 1036,1042 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not send SSL negotiation packet: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); goto connect_errReturn; } retry2: --- 1044,1050 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not send SSL negotiation packet: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); goto connect_errReturn; } retry2: *************** *** 1049,1055 **** printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); goto connect_errReturn; } if (SSLok == 'S') --- 1057,1063 ---- printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not receive server response to SSL negotiation packet: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); goto connect_errReturn; } if (SSLok == 'S') *************** *** 1234,1239 **** --- 1242,1248 ---- PQconnectPoll(PGconn *conn) { PGresult *res; + char sebuf[256]; if (conn == NULL) return PGRES_POLLING_FAILED; *************** *** 1309,1315 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not get socket error status: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); goto error_return; } else if (optval != 0) --- 1318,1324 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not get socket error status: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); goto error_return; } else if (optval != 0) *************** *** 1329,1335 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not get client address from socket: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); goto error_return; } --- 1338,1344 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not get client address from socket: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); goto error_return; } *************** *** 1368,1374 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not send startup packet: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); goto error_return; } --- 1377,1383 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not send startup packet: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); goto error_return; } *************** *** 2186,2191 **** --- 2195,2201 ---- { int save_errno = SOCK_ERRNO; int tmpsock = -1; + char sebuf[256]; struct { uint32 packetlen; *************** *** 2264,2270 **** return TRUE; cancel_errReturn: ! strcat(conn->errorMessage.data, SOCK_STRERROR(SOCK_ERRNO)); strcat(conn->errorMessage.data, "\n"); conn->errorMessage.len = strlen(conn->errorMessage.data); if (tmpsock >= 0) --- 2274,2280 ---- return TRUE; cancel_errReturn: ! strcat(conn->errorMessage.data, SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); strcat(conn->errorMessage.data, "\n"); conn->errorMessage.len = strlen(conn->errorMessage.data); if (tmpsock >= 0) *************** *** 2392,2399 **** *val; int found_keyword; ! key = strtok(line, "="); ! if (key == NULL) { printfPQExpBuffer(errorMessage, "ERROR: syntax error in service file '%s', line %d\n", --- 2402,2410 ---- *val; int found_keyword; ! key = line; ! val = strchr(line, '='); ! if( val == NULL ) { printfPQExpBuffer(errorMessage, "ERROR: syntax error in service file '%s', line %d\n", *************** *** 2402,2407 **** --- 2413,2419 ---- fclose(f); return 3; } + *val++ = '\0'; /* * If not already set, set the database name to the *************** *** 2411,2418 **** if (strcmp(options[i].keyword, "dbname") == 0) if (options[i].val == NULL) options[i].val = strdup(service); - - val = line + strlen(line) + 1; found_keyword = 0; for (i = 0; options[i].keyword; i++) --- 2423,2428 ---- Index: src/interfaces/libpq/fe-exec.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-exec.c,v retrieving revision 1.124 diff -c -r1.124 fe-exec.c *** src/interfaces/libpq/fe-exec.c 2003/01/07 22:23:17 1.124 --- src/interfaces/libpq/fe-exec.c 2003/01/13 11:59:36 *************** *** 12,20 **** * *------------------------------------------------------------------------- */ #include "postgres_fe.h" - #include #include #include --- 12,21 ---- * *------------------------------------------------------------------------- */ + + #include "libpq-reentrant.h" #include "postgres_fe.h" #include #include Index: src/interfaces/libpq/fe-lobj.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-lobj.c,v retrieving revision 1.41 diff -c -r1.41 fe-lobj.c *** src/interfaces/libpq/fe-lobj.c 2002/06/20 20:29:54 1.41 --- src/interfaces/libpq/fe-lobj.c 2003/01/13 11:59:36 *************** *** 12,17 **** --- 12,19 ---- * *------------------------------------------------------------------------- */ + + #include "libpq-reentrant.h" #include "postgres_fe.h" #include *************** *** 396,404 **** fd = open(filename, O_RDONLY | PG_BINARY, 0666); if (fd < 0) { /* error */ printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open file \"%s\": %s\n"), ! filename, strerror(errno)); return InvalidOid; } --- 398,407 ---- fd = open(filename, O_RDONLY | PG_BINARY, 0666); if (fd < 0) { /* error */ + char sebuf[256]; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open file \"%s\": %s\n"), ! filename, pqStrerror(errno, sebuf, sizeof(sebuf))); return InvalidOid; } *************** *** 479,487 **** fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666); if (fd < 0) { /* error */ printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open file \"%s\": %s\n"), ! filename, strerror(errno)); (void) lo_close(conn, lobj); return -1; } --- 482,491 ---- fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666); if (fd < 0) { /* error */ + char sebuf[256]; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open file \"%s\": %s\n"), ! filename, pqStrerror(errno, sebuf, sizeof(sebuf))); (void) lo_close(conn, lobj); return -1; } Index: src/interfaces/libpq/fe-misc.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-misc.c,v retrieving revision 1.86 diff -c -r1.86 fe-misc.c *** src/interfaces/libpq/fe-misc.c 2003/01/07 22:23:17 1.86 --- src/interfaces/libpq/fe-misc.c 2003/01/13 11:59:36 *************** *** 30,35 **** --- 30,36 ---- *------------------------------------------------------------------------- */ + #include "libpq-reentrant.h" #include "postgres_fe.h" #include *************** *** 381,393 **** if (select(conn->sock + 1, &input_mask, (fd_set *) NULL, (fd_set *) NULL, &timeout) < 0) { if (SOCK_ERRNO == EINTR) /* Interrupted system call - we'll just try again */ goto retry1; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("select() failed: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return -1; } --- 382,395 ---- if (select(conn->sock + 1, &input_mask, (fd_set *) NULL, (fd_set *) NULL, &timeout) < 0) { + char sebuf[256]; if (SOCK_ERRNO == EINTR) /* Interrupted system call - we'll just try again */ goto retry1; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("select() failed: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return -1; } *************** *** 415,427 **** if (select(conn->sock + 1, (fd_set *) NULL, &input_mask, (fd_set *) NULL, &timeout) < 0) { if (SOCK_ERRNO == EINTR) /* Interrupted system call - we'll just try again */ goto retry2; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("select() failed: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return -1; } return FD_ISSET(conn->sock, &input_mask) ? 1 : 0; --- 417,430 ---- if (select(conn->sock + 1, (fd_set *) NULL, &input_mask, (fd_set *) NULL, &timeout) < 0) { + char sebuf[256]; if (SOCK_ERRNO == EINTR) /* Interrupted system call - we'll just try again */ goto retry2; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("select() failed: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return -1; } return FD_ISSET(conn->sock, &input_mask) ? 1 : 0; *************** *** 443,448 **** --- 446,452 ---- { int someread = 0; int nread; + char sebuf[256]; if (conn->sock < 0) { *************** *** 513,519 **** #endif printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not receive data from server: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return -1; } if (nread > 0) --- 517,523 ---- #endif printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not receive data from server: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return -1; } if (nread > 0) *************** *** 593,599 **** #endif printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not receive data from server: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return -1; } if (nread > 0) --- 597,603 ---- #endif printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not receive data from server: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return -1; } if (nread > 0) *************** *** 654,659 **** --- 658,664 ---- while (len > 0) { int sent; + char sebuf[256]; sent = pqsecure_write(conn, ptr, len); *************** *** 700,706 **** default: printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not send data to server: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); /* We don't assume it's a fatal error... */ return -1; } --- 705,711 ---- default: printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not send data to server: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); /* We don't assume it's a fatal error... */ return -1; } *************** *** 850,860 **** &except_mask, ptmp_timeout); if (selresult < 0) { if (SOCK_ERRNO == EINTR) goto retry5; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("select() failed: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return EOF; } if (selresult == 0) --- 855,866 ---- &except_mask, ptmp_timeout); if (selresult < 0) { + char sebuf[256]; if (SOCK_ERRNO == EINTR) goto retry5; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("select() failed: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return EOF; } if (selresult == 0) Index: src/interfaces/libpq/fe-print.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-print.c,v retrieving revision 1.47 diff -c -r1.47 fe-print.c *** src/interfaces/libpq/fe-print.c 2002/10/03 17:09:42 1.47 --- src/interfaces/libpq/fe-print.c 2003/01/13 11:59:36 *************** *** 14,19 **** --- 14,21 ---- * *------------------------------------------------------------------------- */ + + #include "libpq-reentrant.h" #include "postgres_fe.h" #include Index: src/interfaces/libpq/fe-secure.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/fe-secure.c,v retrieving revision 1.20 diff -c -r1.20 fe-secure.c *** src/interfaces/libpq/fe-secure.c 2003/01/08 23:18:25 1.20 --- src/interfaces/libpq/fe-secure.c 2003/01/13 11:59:36 *************** *** 79,84 **** --- 79,85 ---- *------------------------------------------------------------------------- */ + #include "libpq-reentrant.h" #include "postgres_fe.h" #include *************** *** 272,280 **** break; case SSL_ERROR_SYSCALL: if (n == -1) ! printfPQExpBuffer(&conn->errorMessage, ! libpq_gettext("SSL SYSCALL error: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); break; case SSL_ERROR_SSL: printfPQExpBuffer(&conn->errorMessage, --- 273,284 ---- break; case SSL_ERROR_SYSCALL: if (n == -1) ! { ! char sebuf[256]; ! printfPQExpBuffer(&conn->errorMessage, ! libpq_gettext("SSL SYSCALL error: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); ! } break; case SSL_ERROR_SSL: printfPQExpBuffer(&conn->errorMessage, *************** *** 319,327 **** break; case SSL_ERROR_SYSCALL: if (n == -1) ! printfPQExpBuffer(&conn->errorMessage, ! libpq_gettext("SSL SYSCALL error: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); break; case SSL_ERROR_SSL: printfPQExpBuffer(&conn->errorMessage, --- 323,334 ---- break; case SSL_ERROR_SYSCALL: if (n == -1) ! { ! char sebuf[256]; ! printfPQExpBuffer(&conn->errorMessage, ! libpq_gettext("SSL SYSCALL error: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); ! } break; case SSL_ERROR_SSL: printfPQExpBuffer(&conn->errorMessage, *************** *** 385,393 **** len = sizeof(addr); if (getpeername(conn->sock, &addr, &len) == -1) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("error querying socket: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO)); return -1; } --- 392,401 ---- len = sizeof(addr); if (getpeername(conn->sock, &addr, &len) == -1) { + char sebuf[256]; printfPQExpBuffer(&conn->errorMessage, libpq_gettext("error querying socket: %s\n"), ! SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf))); return -1; } *************** *** 465,478 **** static DH * load_dh_file(int keylength) { ! struct passwd *pwd; FILE *fp; char fnbuf[2048]; DH *dh = NULL; int codes; ! if ((pwd = getpwuid(getuid())) == NULL) ! return NULL; /* attempt to open file. It's not an error if it doesn't exist. */ snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/dh%d.pem", --- 473,488 ---- static DH * load_dh_file(int keylength) { ! char pwdbuf[BUFSIZ]; ! struct passwd pwdstr; ! struct passwd *pwd = NULL; FILE *fp; char fnbuf[2048]; DH *dh = NULL; int codes; ! if( pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0 ) ! return NULL; /* attempt to open file. It's not an error if it doesn't exist. */ snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/dh%d.pem", *************** *** 605,619 **** static int client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) { ! struct passwd *pwd; struct stat buf, buf2; char fnbuf[2048]; FILE *fp; PGconn *conn = (PGconn *) SSL_get_app_data(ssl); int (*cb) () = NULL; /* how to read user password */ ! if ((pwd = getpwuid(getuid())) == NULL) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not get user information\n")); --- 615,633 ---- static int client_cert_cb(SSL *ssl, X509 **x509, EVP_PKEY **pkey) { ! char pwdbuf[BUFSIZ]; ! struct passwd pwdstr; ! struct passwd *pwd = NULL; struct stat buf, buf2; char fnbuf[2048]; FILE *fp; PGconn *conn = (PGconn *) SSL_get_app_data(ssl); int (*cb) () = NULL; /* how to read user password */ + char sebuf[256]; + ! if( pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0 ) { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not get user information\n")); *************** *** 629,635 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open certificate (%s): %s\n"), ! fnbuf, strerror(errno)); return -1; } if (PEM_read_X509(fp, x509, NULL, NULL) == NULL) --- 643,649 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open certificate (%s): %s\n"), ! fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf))); return -1; } if (PEM_read_X509(fp, x509, NULL, NULL) == NULL) *************** *** 665,671 **** { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open private key file (%s): %s\n"), ! fnbuf, strerror(errno)); X509_free(*x509); return -1; } --- 679,685 ---- { printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not open private key file (%s): %s\n"), ! fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf))); X509_free(*x509); return -1; } *************** *** 709,715 **** initialize_SSL(PGconn *conn) { struct stat buf; ! struct passwd *pwd; char fnbuf[2048]; if (!SSL_context) --- 723,731 ---- initialize_SSL(PGconn *conn) { struct stat buf; ! char pwdbuf[BUFSIZ]; ! struct passwd pwdstr; ! struct passwd *pwd = NULL; char fnbuf[2048]; if (!SSL_context) *************** *** 726,732 **** } } ! if ((pwd = getpwuid(getuid())) != NULL) { snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/root.crt", pwd->pw_dir); --- 742,748 ---- } } ! if( pqGetpwuid(getuid(), &pwdstr, pwdbuf, sizeof(pwdbuf), &pwd) == 0 ) { snprintf(fnbuf, sizeof fnbuf, "%s/.postgresql/root.crt", pwd->pw_dir); *************** *** 734,743 **** { return 0; #ifdef NOT_USED /* CLIENT CERTIFICATES NOT REQUIRED bjm 2002-09-26 */ printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not read root certificate list (%s): %s\n"), ! fnbuf, strerror(errno)); return -1; #endif } --- 750,760 ---- { return 0; #ifdef NOT_USED + char sebuf[256]; /* CLIENT CERTIFICATES NOT REQUIRED bjm 2002-09-26 */ printfPQExpBuffer(&conn->errorMessage, libpq_gettext("could not read root certificate list (%s): %s\n"), ! fnbuf, pqStrerror(errno, sebuf, sizeof(sebuf))); return -1; #endif } Index: src/interfaces/libpq/libpq-int.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/libpq-int.h,v retrieving revision 1.60 diff -c -r1.60 libpq-int.h *** src/interfaces/libpq/libpq-int.h 2002/10/16 02:55:30 1.60 --- src/interfaces/libpq/libpq-int.h 2003/01/13 11:59:36 *************** *** 26,31 **** --- 26,32 ---- #include #endif + #if defined(WIN32) && (!defined(ssize_t)) typedef int ssize_t; /* ssize_t doesn't exist in VC (atleast * not VC6) */ *************** *** 389,395 **** #define SOCK_STRERROR winsock_strerror #else #define SOCK_ERRNO errno ! #define SOCK_STRERROR strerror #endif #endif /* LIBPQ_INT_H */ --- 390,396 ---- #define SOCK_STRERROR winsock_strerror #else #define SOCK_ERRNO errno ! #define SOCK_STRERROR pqStrerror #endif #endif /* LIBPQ_INT_H */ Index: src/interfaces/libpq/win32.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.c,v retrieving revision 1.4 diff -c -r1.4 win32.c *** src/interfaces/libpq/win32.c 2002/09/04 20:31:47 1.4 --- src/interfaces/libpq/win32.c 2003/01/13 11:59:36 *************** *** 271,283 **** */ const char * ! winsock_strerror(int err) { - static char buf[512]; /* Not threadsafe */ unsigned long flags; int offs, i; ! int success = LookupWSErrorMessage(err, buf); for (i = 0; !success && i < DLLS_SIZE; i++) { --- 271,282 ---- */ const char * ! winsock_strerror(int err, char *strerrbuf, size_t buflen) { unsigned long flags; int offs, i; ! int success = LookupWSErrorMessage(err, strerrbuf); for (i = 0; !success && i < DLLS_SIZE; i++) { *************** *** 302,321 **** flags, dlls[i].handle, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ! buf, sizeof(buf) - 64, 0 ); } if (!success) ! sprintf(buf, "Unknown socket error (0x%08X/%lu)", err, err); else { ! buf[sizeof(buf) - 1] = '\0'; ! offs = strlen(buf); ! if (offs > sizeof(buf) - 64) ! offs = sizeof(buf) - 64; ! sprintf(buf + offs, " (0x%08X/%lu)", err, err); } ! return buf; } --- 301,320 ---- flags, dlls[i].handle, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ! strerrbuf, buflen - 64, 0 ); } if (!success) ! sprintf(strerrbuf, "Unknown socket error (0x%08X/%lu)", err, err); else { ! strerrbuf[buflen - 1] = '\0'; ! offs = strlen(strerrbuf); ! if (offs > buflen - 64) ! offs = buflen - 64; ! sprintf(strerrbuf + offs, " (0x%08X/%lu)", err, err); } ! return strerrbuf; } Index: src/interfaces/libpq/win32.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.h,v retrieving revision 1.21 diff -c -r1.21 win32.h *** src/interfaces/libpq/win32.h 2002/12/30 21:07:26 1.21 --- src/interfaces/libpq/win32.h 2003/01/13 11:59:36 *************** *** 42,48 **** /* * support for handling Windows Socket errors */ ! extern const char *winsock_strerror(int eno); ! #endif --- 42,47 ---- /* * support for handling Windows Socket errors */ ! extern const char *winsock_strerror(int err, char *strerrbuf, size_t buflen); #endif