--------------------- PatchSet 3997 Date: 2002/04/13 14:58:55 Author: serassio Branch: nt-2_5 Tag: (none) Log: Rearranged WIN32 code in ipc.c and pinger.c, and other little WIN32 code cleanup Members: acconfig.h:1.13.6.1->1.13.6.2 include/util.h:1.10.14.3->1.10.14.4 lib/win32lib.c:1.1.32.2->1.1.32.3 port/win32/include/squid-mswin.h:1.1.2.7->1.1.2.8 src/comm_select.c:1.8.10.4->1.8.10.5 src/ipc.c:1.7.10.4->1.7.10.5 src/pinger.c:1.4.74.1->1.4.74.2 src/unlinkd.c:1.6.10.3->1.6.10.4 Index: squid/acconfig.h =================================================================== RCS file: /cvsroot/squid-sf//squid/Attic/acconfig.h,v retrieving revision 1.13.6.1 retrieving revision 1.13.6.2 diff -u -r1.13.6.1 -r1.13.6.2 --- squid/acconfig.h 23 Mar 2002 10:35:23 -0000 1.13.6.1 +++ squid/acconfig.h 13 Apr 2002 14:58:55 -0000 1.13.6.2 @@ -23,7 +23,7 @@ #ifndef __CONFIGURE_H__ #define __CONFIGURE_H__ @TOP@ -/* $Id: acconfig.h,v 1.13.6.1 2002/03/23 10:35:23 serassio Exp $ */ +/* $Id: acconfig.h,v 1.13.6.2 2002/04/13 14:58:55 serassio Exp $ */ /* * configure command line used to configure Squid @@ -218,6 +218,9 @@ /* Define if you have struct rusage */ #undef HAVE_STRUCT_RUSAGE +/* Define if you have PSAPI.DLL on Windows systems */ +#undef HAVE_WIN32_PSAPI + /* * This makes warnings go away. If you have socklen_t defined in your * /usr/include files, then this should remain undef'd. Otherwise it Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.10.14.3 retrieving revision 1.10.14.4 diff -u -r1.10.14.3 -r1.10.14.4 --- squid/include/util.h 7 Apr 2002 09:59:51 -0000 1.10.14.3 +++ squid/include/util.h 13 Apr 2002 14:58:55 -0000 1.10.14.4 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.10.14.3 2002/04/07 09:59:51 serassio Exp $ + * $Id: util.h,v 1.10.14.4 2002/04/13 14:58:55 serassio Exp $ * * AUTHOR: Harvest Derived * @@ -147,6 +147,13 @@ extern struct passwd *getpwnam(char *); extern struct group *getgrnam(char *); extern uid_t geteuid(void); +extern uid_t getuid(void); +extern int setuid(uid_t); +extern int seteuid(uid_t); +extern gid_t getgid(void); +extern gid_t getegid(void); +extern int setgid(gid_t); +extern int setegid(gid_t); #endif #endif /* SQUID_UTIL_H */ Index: squid/lib/win32lib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/win32lib.c,v retrieving revision 1.1.32.2 retrieving revision 1.1.32.3 diff -u -r1.1.32.2 -r1.1.32.3 --- squid/lib/win32lib.c 7 Apr 2002 09:59:51 -0000 1.1.32.2 +++ squid/lib/win32lib.c 13 Apr 2002 14:58:55 -0000 1.1.32.3 @@ -1,5 +1,5 @@ /* - * $Id: win32lib.c,v 1.1.32.2 2002/04/07 09:59:51 serassio Exp $ + * $Id: win32lib.c,v 1.1.32.3 2002/04/13 14:58:55 serassio Exp $ * * * * * * * * * Legal stuff * * * * * * * * @@ -54,6 +54,41 @@ return 100; } +uid_t getuid(void) +{ + return 100; +} + +int setuid(uid_t uid) +{ + return 0; +} + +int seteuid(uid_t euid) +{ + return 0; +} + +gid_t getegid(void) +{ + return 100; +} + +gid_t getgid(void) +{ + return 100; +} + +int setgid(gid_t gid) +{ + return 0; +} + +int setegid(gid_t egid) +{ + return 0; +} + int chroot (const char *dirname) { if (SetCurrentDirectory(dirname)) Index: squid/port/win32/include/squid-mswin.h =================================================================== RCS file: /cvsroot/squid-sf//squid/port/win32/include/Attic/squid-mswin.h,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -u -r1.1.2.7 -r1.1.2.8 --- squid/port/win32/include/squid-mswin.h 7 Apr 2002 09:59:52 -0000 1.1.2.7 +++ squid/port/win32/include/squid-mswin.h 13 Apr 2002 14:58:55 -0000 1.1.2.8 @@ -1,5 +1,5 @@ /* - * $Id: squid-mswin.h,v 1.1.2.7 2002/04/07 09:59:52 serassio Exp $ + * $Id: squid-mswin.h,v 1.1.2.8 2002/04/13 14:58:55 serassio Exp $ * * AUTHOR: Guido Serassio & Andrey Shorin * @@ -49,7 +49,6 @@ #define ftruncate WIN32_ftruncate #define getcwd _getcwd #define getpid _getpid -#define getegid() 100 #define getrusage WIN32_getrusage #define ioctl ioctlsocket #define is_interface_down WIN32_is_interface_down @@ -59,9 +58,7 @@ #define mktemp _mktemp #define open _open #define putenv _putenv -#define setgid(g) 100 #define setmode _setmode -#define setuid(l) 100 #define sleep(t) Sleep((t)*1000) #define snprintf _snprintf #define stat _stati64 Index: squid/src/comm_select.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/comm_select.c,v retrieving revision 1.8.10.4 retrieving revision 1.8.10.5 diff -u -r1.8.10.4 -r1.8.10.5 --- squid/src/comm_select.c 4 Apr 2002 19:40:22 -0000 1.8.10.4 +++ squid/src/comm_select.c 13 Apr 2002 14:58:55 -0000 1.8.10.5 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.c,v 1.8.10.4 2002/04/04 19:40:22 serassio Exp $ + * $Id: comm_select.c,v 1.8.10.5 2002/04/13 14:58:55 serassio Exp $ * * DEBUG: section 5 Socket Functions * @@ -1222,4 +1222,4 @@ { MAX_POLL_TIME = 10; } -#endif +#endif /* COMM_SELECT_C */ Index: squid/src/ipc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/ipc.c,v retrieving revision 1.7.10.4 retrieving revision 1.7.10.5 diff -u -r1.7.10.4 -r1.7.10.5 --- squid/src/ipc.c 7 Apr 2002 09:59:52 -0000 1.7.10.4 +++ squid/src/ipc.c 13 Apr 2002 14:58:55 -0000 1.7.10.5 @@ -1,6 +1,6 @@ /* - * $Id: ipc.c,v 1.7.10.4 2002/04/07 09:59:52 serassio Exp $ + * $Id: ipc.c,v 1.7.10.5 2002/04/13 14:58:55 serassio Exp $ * * DEBUG: section 54 Interprocess Communication * AUTHOR: Duane Wessels @@ -191,11 +191,7 @@ debug(54, 0) ("ipcCreate: Failed to create server FD.\n"); return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } -#ifdef _SQUID_MSWIN_ - { -#else if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) { -#endif len = sizeof(PS); memset(&PS, '\0', len); if (getsockname(pwfd, (struct sockaddr *) &PS, &len) < 0) { @@ -252,18 +248,19 @@ #undef ipcCloseAllFD #define ipcCloseAllFD(w,x,y,z) (CloseHandle((HANDLE)thread), ipcCloseAllFD((w),(x),-1,-1)) { + { #endif if (comm_connect_addr(pwfd, &CS) == COMM_ERROR) return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } memset(hello_buf, '\0', HELLO_BUF_SZ); -#ifndef _SQUID_MSWIN_ - if (type == IPC_UDP_SOCKET) -#endif +#ifdef _SQUID_MSWIN_ + x = recv(prfd, hello_buf, HELLO_BUF_SZ - 1, 0); +#else + if (type == IPC_UDP_SOCKET) x = recv(prfd, hello_buf, HELLO_BUF_SZ - 1, 0); -#ifndef _SQUID_MSWIN_ - else - x = read(prfd, hello_buf, HELLO_BUF_SZ - 1); + else + x = read(prfd, hello_buf, HELLO_BUF_SZ - 1); #endif if (x < 0) { debug(50, 0) ("ipcCreate: PARENT: hello read test failed\n"); @@ -276,26 +273,26 @@ return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } #ifdef _SQUID_MSWIN_ - x = send(pwfd, ok_string, strlen(ok_string), 0); - if (x < 0) { - debug(50, 0) ("ipcCreate: PARENT: OK write test failed\n"); - debug(50, 0) ("--> read: %s\n", xstrerror()); - return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); - } - memset(hello_buf, '\0', HELLO_BUF_SZ); - x = recv(prfd, hello_buf, HELLO_BUF_SZ - 1, 0); - if (x < 0) { - debug(50, 0) ("ipcCreate: PARENT: OK read test failed\n"); - debug(50, 0) ("--> read: %s\n", xstrerror()); - return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); - } else if (!strcmp(hello_buf, err_string)) { - debug(54, 0) ("ipcCreate: PARENT: OK read test failed\n"); - debug(54, 0) ("--> read returned %d\n", x); - debug(54, 0) ("--> got '%s'\n", rfc1738_escape(hello_buf)); - return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); - } - hello_buf[x] = '\0'; - pid = atol(hello_buf); + x = send(pwfd, ok_string, strlen(ok_string), 0); + if (x < 0) { + debug(50, 0) ("ipcCreate: PARENT: OK write test failed\n"); + debug(50, 0) ("--> read: %s\n", xstrerror()); + return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); + } + memset(hello_buf, '\0', HELLO_BUF_SZ); + x = recv(prfd, hello_buf, HELLO_BUF_SZ - 1, 0); + if (x < 0) { + debug(50, 0) ("ipcCreate: PARENT: OK read test failed\n"); + debug(50, 0) ("--> read: %s\n", xstrerror()); + return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); + } else if (!strcmp(hello_buf, err_string)) { + debug(54, 0) ("ipcCreate: PARENT: OK read test failed\n"); + debug(54, 0) ("--> read returned %d\n", x); + debug(54, 0) ("--> got '%s'\n", rfc1738_escape(hello_buf)); + return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); + } + hello_buf[x] = '\0'; + pid = atol(hello_buf); #endif commSetTimeout(prfd, -1, NULL, NULL); commSetNonBlocking(prfd); @@ -305,21 +302,21 @@ if (wfd) *wfd = pwfd; #ifdef _SQUID_MSWIN_ - fd_table[prfd].flags.ipc = 1; - fd_table[pwfd].flags.ipc = 1; - fd_table[crfd].flags.ipc = 1; - fd_table[cwfd].flags.ipc = 1; - { - DWORD ecode = 0; - if (GetExitCodeThread((HANDLE) thread, &ecode) && ecode == STILL_ACTIVE) { - if (hIpc) - *hIpc = (HANDLE) thread; - if (ppid) - *ppid = pid; - return pwfd; - } else - return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); - } + fd_table[prfd].flags.ipc = 1; + fd_table[pwfd].flags.ipc = 1; + fd_table[crfd].flags.ipc = 1; + fd_table[cwfd].flags.ipc = 1; + { + DWORD ecode = 0; + if (GetExitCodeThread((HANDLE) thread, &ecode) && ecode == STILL_ACTIVE) { + if (hIpc) + *hIpc = (HANDLE) thread; + if (ppid) + *ppid = pid; + return pwfd; + } else + return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); + } #else fd_table[prfd].flags.ipc = 1; fd_table[pwfd].flags.ipc = 1; @@ -333,8 +330,8 @@ return pid; #endif } - #ifdef _SQUID_MSWIN_ +} #undef ipcCloseAllFD static int @@ -386,7 +383,6 @@ if (str = strrchr(prog, '\\')) prog = ++str; prog = xstrdup(prog); - #else /* child */ no_suid(); /* give up extra priviliges */ @@ -402,17 +398,17 @@ if ((fd = accept(crfd, NULL, NULL)) < 0) { debug(50, 0) ("ipcCreate: FD %d accept: %s\n", crfd, xstrerror()); #ifdef _SQUID_MSWIN_ - goto cleanup; + goto cleanup; #else - _exit(1); + _exit(1); #endif } debug(54, 3) ("ipcCreate: CHILD accepted new FD %d\n", fd); #ifdef _SQUID_MSWIN_ - comm_close(crfd); - snprintf(buf1, 8191, "%s CHILD socket", prog); - fd_open(fd, FD_SOCKET, buf1); - fd_table[fd].flags.ipc = 1; + comm_close(crfd); + snprintf(buf1, 8191, "%s CHILD socket", prog); + fd_open(fd, FD_SOCKET, buf1); + fd_table[fd].flags.ipc = 1; #else close(crfd); #endif @@ -420,20 +416,23 @@ } else if (type == IPC_UDP_SOCKET) { if (comm_connect_addr(crfd, &PS) == COMM_ERROR) #ifdef _SQUID_MSWIN_ - goto cleanup; + goto cleanup; #else return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); #endif } #ifndef _SQUID_MSWIN_ if (type == IPC_UDP_SOCKET) { +#else + { #endif x = send(cwfd, hello_string, strlen(hello_string) + 1, 0); if (x < 0) { debug(50, 0) ("sendto FD %d: %s\n", cwfd, xstrerror()); debug(50, 0) ("ipcCreate: CHILD: hello write test failed\n"); #ifdef _SQUID_MSWIN_ - goto cleanup; + goto cleanup; + } } #else _exit(1); @@ -443,7 +442,7 @@ debug(50, 0) ("write FD %d: %s\n", cwfd, xstrerror()); debug(50, 0) ("ipcCreate: CHILD: hello write test failed\n"); _exit(1); -// } + } } #endif #if HAVE_PUTENV Index: squid/src/pinger.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/pinger.c,v retrieving revision 1.4.74.1 retrieving revision 1.4.74.2 diff -u -r1.4.74.1 -r1.4.74.2 --- squid/src/pinger.c 27 Mar 2002 21:01:18 -0000 1.4.74.1 +++ squid/src/pinger.c 13 Apr 2002 14:58:55 -0000 1.4.74.2 @@ -1,6 +1,6 @@ /* - * $Id: pinger.c,v 1.4.74.1 2002/03/27 21:01:18 serassio Exp $ + * $Id: pinger.c,v 1.4.74.2 2002/04/13 14:58:55 serassio Exp $ * * DEBUG: section 42 ICMP Pinger program * AUTHOR: Duane Wessels @@ -42,6 +42,9 @@ #include #include #include +#define PINGER_TIMEOUT 10 +static int socket_from_squid = 0; +static int socket_to_squid = 1; #else #include #include @@ -77,8 +80,9 @@ } icmphdr; -static SOCKET squid_sock = -1; - +#define PINGER_TIMEOUT 5 +static SOCKET socket_to_squid = -1; +#define socket_from_squid socket_to_squid #endif /* _SQUID_MSWIN_ */ #ifndef _SQUID_LINUX_ @@ -208,16 +212,16 @@ icmp_ident = getpid() & 0xffff; debug(42, 0) ("pinger: ICMP socket opened\n"); #ifdef _SQUID_MSWIN_ - squid_sock = + socket_to_squid = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &wpi, 0, 0); - if (squid_sock == INVALID_SOCKET) { + if (socket_to_squid == INVALID_SOCKET) { getCurrentTime(); debug(42, 0) ("pingerOpen: WSASocket: %s\n", xstrerror()); write(1, "ERR\n", 4); exit(1); } - x = connect(squid_sock, (struct sockaddr *) &PS, sizeof(PS)); + x = connect(socket_to_squid, (struct sockaddr *) &PS, sizeof(PS)); if (SOCKET_ERROR == x) { getCurrentTime(); debug(42, 0) ("pingerOpen: connect: %s\n", xstrerror()); @@ -226,12 +230,12 @@ } write(1, "OK\n", 3); memset(buf, 0, sizeof(buf)); - x = recv(squid_sock, buf, sizeof(buf), 0); + x = recv(socket_to_squid, buf, sizeof(buf), 0); if (x < 3) { debug(42, 0) ("icmpOpen: recv: %s\n", xstrerror()); exit(1); } - x = send(squid_sock, buf, strlen(buf), 0); + x = send(socket_to_squid, buf, strlen(buf), 0); if (x < 3 || strncmp("OK\n", buf, 3)) { debug(42, 0) ("icmpOpen: recv: %s\n", xstrerror()); exit(1); @@ -247,9 +251,9 @@ { close(icmp_sock); #ifdef _SQUID_MSWIN_ - shutdown(squid_sock, SD_BOTH); - close(squid_sock); - squid_sock = -1; + shutdown(socket_to_squid, SD_BOTH); + close(socket_to_squid); + socket_to_squid = -1; #endif icmp_sock = -1; icmp_ident = 0; @@ -378,7 +382,7 @@ } sum = (sum >> 16) + (sum & 0xffff); sum += (sum >> 16); - answer = ~sum; + answer = (unsigned short) ~sum; return (answer); } @@ -418,11 +422,7 @@ int n; int guess_size; memset(&pecho, '\0', sizeof(pecho)); -#ifdef _SQUID_MSWIN_ - n = recv(squid_sock, (char *) &pecho, sizeof(pecho), 0); -#else - n = recv(0, (char *) &pecho, sizeof(pecho), 0); -#endif + n = recv(socket_from_squid, (char *) &pecho, sizeof(pecho), 0); if (n < 0) return n; if (0 == n) { @@ -449,11 +449,7 @@ pingerSendtoSquid(pingerReplyData * preply) { int len = sizeof(pingerReplyData) - MAX_PKT_SZ + preply->psize; -#ifdef _SQUID_MSWIN_ - if (send(squid_sock, (char *) preply, len, 0) < 0) { -#else - if (send(1, (char *) preply, len, 0) < 0) { -#endif + if (send(socket_to_squid, (char *) preply, len, 0) < 0) { debug(50, 0) ("pinger: send: %s\n", xstrerror()); exit(1); } @@ -487,10 +483,9 @@ */ pingerOpen(); -#ifndef _SQUID_MSWIN_ setgid(getgid()); setuid(getuid()); -#else +#ifdef _SQUID_MSWIN_ atexit(pingerClose); #endif @@ -500,45 +495,29 @@ _db_init(NULL, debug_args); for (;;) { -#ifdef _SQUID_MSWIN_ - tv.tv_sec = 5; -#else - tv.tv_sec = 10; -#endif + tv.tv_sec = PINGER_TIMEOUT; tv.tv_usec = 0; FD_ZERO(&R); -#ifdef _SQUID_MSWIN_ - FD_SET(squid_sock, &R); -#else - FD_SET(0, &R); -#endif + FD_SET(socket_from_squid, &R); FD_SET(icmp_sock, &R); x = select(icmp_sock + 1, &R, NULL, NULL, &tv); getCurrentTime(); if (x < 0) exit(1); -#ifdef _SQUID_MSWIN_ - if (FD_ISSET(squid_sock, &R)) -#else - if (FD_ISSET(0, &R)) -#endif + if (FD_ISSET(socket_from_squid, &R)) if (pingerReadRequest() < 0) { debug(42, 0) ("Pinger exiting.\n"); exit(1); } if (FD_ISSET(icmp_sock, &R)) pingerRecv(); + if (PINGER_TIMEOUT + last_check_time < squid_curtime) { + if (send(socket_to_squid, (char *) &tv, 0, 0) < 0) { #ifdef _SQUID_MSWIN_ - if (5 + last_check_time < squid_curtime) { - if (send(squid_sock, (char *) &tv, 0, 0) < 0) { debug(42, 0) ("Pinger exiting.\n"); +#endif exit(1); } -#else - if (10 + last_check_time < squid_curtime) { - if (send(1, (char *) &tv, 0, 0) < 0) - exit(1); -#endif last_check_time = squid_curtime; } } Index: squid/src/unlinkd.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/unlinkd.c,v retrieving revision 1.6.10.3 retrieving revision 1.6.10.4 diff -u -r1.6.10.3 -r1.6.10.4 --- squid/src/unlinkd.c 27 Mar 2002 21:01:18 -0000 1.6.10.3 +++ squid/src/unlinkd.c 13 Apr 2002 14:58:55 -0000 1.6.10.4 @@ -1,6 +1,6 @@ /* - * $Id: unlinkd.c,v 1.6.10.3 2002/03/27 21:01:18 serassio Exp $ + * $Id: unlinkd.c,v 1.6.10.4 2002/04/13 14:58:55 serassio Exp $ * * DEBUG: section 12 Unlink Daemon * AUTHOR: Duane Wessels @@ -220,8 +220,8 @@ /* pipes and poll() don't get along on DUNIX -DW */ x = ipcCreate(IPC_TCP_SOCKET, #elif defined(_SQUID_MSWIN_) - /* select() will fail on a pipe */ - x = ipcCreate(IPC_TCP_SOCKET, + /* select() will fail on a pipe */ + x = ipcCreate(IPC_TCP_SOCKET, #else x = ipcCreate(IPC_FIFO, #endif