Fossil SCM
Set the permissions of the unix socket of fossil server through the umask in effect for bind(), not with fchmod() on the unbound socket, which macOS refuses, so that --socket-mode and the default of 0660 work there. Remove the now unused file_set_mode().
Commit
7ffce1d7b4ae7dd59314ff15d0297a2e96ae422ab1919d2940a99e1a2bfb04d4
Parent
7a8975dd84db675…
2 files changed
+13
-4
-15
+13
-4
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -78,10 +78,11 @@ | ||
| 78 | 78 | # include <arpa/inet.h> |
| 79 | 79 | # include <sys/times.h> |
| 80 | 80 | # include <sys/time.h> |
| 81 | 81 | # include <sys/wait.h> |
| 82 | 82 | # include <sys/select.h> |
| 83 | +# include <sys/stat.h> | |
| 83 | 84 | # include <errno.h> |
| 84 | 85 | #endif |
| 85 | 86 | #ifdef __EMX__ |
| 86 | 87 | typedef int socklen_t; |
| 87 | 88 | #endif |
| @@ -2642,10 +2643,12 @@ | ||
| 2642 | 2643 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2643 | 2644 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2644 | 2645 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2645 | 2646 | int opt = 1; /* setsockopt flag */ |
| 2646 | 2647 | int rc; /* Result code from system calls */ |
| 2648 | + mode_t mSock = 0660; /* Permissions for a unix-domain socket */ | |
| 2649 | + mode_t mOld; /* Saved umask */ | |
| 2647 | 2650 | int iPort = mnPort; /* Port to try to use */ |
| 2648 | 2651 | const char *zRequestType; /* Type of requests to listen for */ |
| 2649 | 2652 | |
| 2650 | 2653 | |
| 2651 | 2654 | if( flags & HTTP_SERVER_SCGI ){ |
| @@ -2685,17 +2688,23 @@ | ||
| 2685 | 2688 | mxListen = listen4; |
| 2686 | 2689 | listen6 = -1; |
| 2687 | 2690 | |
| 2688 | 2691 | /* Set the access permission for the new socket. Default to 0660. |
| 2689 | 2692 | ** But use an alternative specified by --socket-mode if available. |
| 2690 | - ** Do this before bind() to avoid a race condition. */ | |
| 2693 | + ** Set it through the umask that bind() uses to avoid a race | |
| 2694 | + ** condition. */ | |
| 2691 | 2695 | if( g.zSockMode ){ |
| 2692 | - file_set_mode(g.zSockName, listen4, g.zSockMode, 0); | |
| 2693 | - }else{ | |
| 2694 | - file_set_mode(g.zSockName, listen4, "0660", 1); | |
| 2696 | + char *zEnd = 0; | |
| 2697 | + mSock = (mode_t)strtol(g.zSockMode, &zEnd, 0); | |
| 2698 | + if( zEnd[0] ){ | |
| 2699 | + fossil_fatal("cannot change permissions on %s to \"%s\"", | |
| 2700 | + g.zSockName, g.zSockMode); | |
| 2701 | + } | |
| 2695 | 2702 | } |
| 2703 | + mOld = umask(~mSock & 0777); | |
| 2696 | 2704 | rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr)); |
| 2705 | + umask(mOld); | |
| 2697 | 2706 | /* Set the owner of the socket if requested by --socket-owner. This |
| 2698 | 2707 | ** must wait until after bind(), after the filesystem object has been |
| 2699 | 2708 | ** created. See https://lkml.org/lkml/2004/11/1/84 and |
| 2700 | 2709 | ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */ |
| 2701 | 2710 | if( g.zSockOwner ){ |
| 2702 | 2711 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -78,10 +78,11 @@ | |
| 78 | # include <arpa/inet.h> |
| 79 | # include <sys/times.h> |
| 80 | # include <sys/time.h> |
| 81 | # include <sys/wait.h> |
| 82 | # include <sys/select.h> |
| 83 | # include <errno.h> |
| 84 | #endif |
| 85 | #ifdef __EMX__ |
| 86 | typedef int socklen_t; |
| 87 | #endif |
| @@ -2642,10 +2643,12 @@ | |
| 2642 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2643 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2644 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2645 | int opt = 1; /* setsockopt flag */ |
| 2646 | int rc; /* Result code from system calls */ |
| 2647 | int iPort = mnPort; /* Port to try to use */ |
| 2648 | const char *zRequestType; /* Type of requests to listen for */ |
| 2649 | |
| 2650 | |
| 2651 | if( flags & HTTP_SERVER_SCGI ){ |
| @@ -2685,17 +2688,23 @@ | |
| 2685 | mxListen = listen4; |
| 2686 | listen6 = -1; |
| 2687 | |
| 2688 | /* Set the access permission for the new socket. Default to 0660. |
| 2689 | ** But use an alternative specified by --socket-mode if available. |
| 2690 | ** Do this before bind() to avoid a race condition. */ |
| 2691 | if( g.zSockMode ){ |
| 2692 | file_set_mode(g.zSockName, listen4, g.zSockMode, 0); |
| 2693 | }else{ |
| 2694 | file_set_mode(g.zSockName, listen4, "0660", 1); |
| 2695 | } |
| 2696 | rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr)); |
| 2697 | /* Set the owner of the socket if requested by --socket-owner. This |
| 2698 | ** must wait until after bind(), after the filesystem object has been |
| 2699 | ** created. See https://lkml.org/lkml/2004/11/1/84 and |
| 2700 | ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */ |
| 2701 | if( g.zSockOwner ){ |
| 2702 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -78,10 +78,11 @@ | |
| 78 | # include <arpa/inet.h> |
| 79 | # include <sys/times.h> |
| 80 | # include <sys/time.h> |
| 81 | # include <sys/wait.h> |
| 82 | # include <sys/select.h> |
| 83 | # include <sys/stat.h> |
| 84 | # include <errno.h> |
| 85 | #endif |
| 86 | #ifdef __EMX__ |
| 87 | typedef int socklen_t; |
| 88 | #endif |
| @@ -2642,10 +2643,12 @@ | |
| 2643 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2644 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2645 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2646 | int opt = 1; /* setsockopt flag */ |
| 2647 | int rc; /* Result code from system calls */ |
| 2648 | mode_t mSock = 0660; /* Permissions for a unix-domain socket */ |
| 2649 | mode_t mOld; /* Saved umask */ |
| 2650 | int iPort = mnPort; /* Port to try to use */ |
| 2651 | const char *zRequestType; /* Type of requests to listen for */ |
| 2652 | |
| 2653 | |
| 2654 | if( flags & HTTP_SERVER_SCGI ){ |
| @@ -2685,17 +2688,23 @@ | |
| 2688 | mxListen = listen4; |
| 2689 | listen6 = -1; |
| 2690 | |
| 2691 | /* Set the access permission for the new socket. Default to 0660. |
| 2692 | ** But use an alternative specified by --socket-mode if available. |
| 2693 | ** Set it through the umask that bind() uses to avoid a race |
| 2694 | ** condition. */ |
| 2695 | if( g.zSockMode ){ |
| 2696 | char *zEnd = 0; |
| 2697 | mSock = (mode_t)strtol(g.zSockMode, &zEnd, 0); |
| 2698 | if( zEnd[0] ){ |
| 2699 | fossil_fatal("cannot change permissions on %s to \"%s\"", |
| 2700 | g.zSockName, g.zSockMode); |
| 2701 | } |
| 2702 | } |
| 2703 | mOld = umask(~mSock & 0777); |
| 2704 | rc = bind(listen4, (struct sockaddr*)&uxaddr, sizeof(uxaddr)); |
| 2705 | umask(mOld); |
| 2706 | /* Set the owner of the socket if requested by --socket-owner. This |
| 2707 | ** must wait until after bind(), after the filesystem object has been |
| 2708 | ** created. See https://lkml.org/lkml/2004/11/1/84 and |
| 2709 | ** https://fossil-scm.org/forum/forumpost/7517680ef9684c57 */ |
| 2710 | if( g.zSockOwner ){ |
| 2711 |
-15
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -765,25 +765,10 @@ | ||
| 765 | 765 | iMTime = file_mtime(zFile, RepoFILE); |
| 766 | 766 | zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime); |
| 767 | 767 | fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime); |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | -/* | |
| 771 | -** Change access permissions on a file. | |
| 772 | -*/ | |
| 773 | -void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){ | |
| 774 | -#if !defined(_WIN32) | |
| 775 | - mode_t m; | |
| 776 | - char *zEnd = 0; | |
| 777 | - m = strtol(zMode, &zEnd, 0); | |
| 778 | - if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){ | |
| 779 | - fossil_fatal("cannot change permissions on %s to \"%s\"", | |
| 780 | - zFN, zMode); | |
| 781 | - } | |
| 782 | -#endif | |
| 783 | -} | |
| 784 | - | |
| 785 | 770 | /* Change the owner of a file to zOwner. zOwner can be of the form |
| 786 | 771 | ** USER:GROUP. |
| 787 | 772 | */ |
| 788 | 773 | void file_set_owner(const char *zFN, int fd, const char *zOwner){ |
| 789 | 774 | #if !defined(_WIN32) |
| 790 | 775 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -765,25 +765,10 @@ | |
| 765 | iMTime = file_mtime(zFile, RepoFILE); |
| 766 | zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime); |
| 767 | fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime); |
| 768 | } |
| 769 | |
| 770 | /* |
| 771 | ** Change access permissions on a file. |
| 772 | */ |
| 773 | void file_set_mode(const char *zFN, int fd, const char *zMode, int bNoErr){ |
| 774 | #if !defined(_WIN32) |
| 775 | mode_t m; |
| 776 | char *zEnd = 0; |
| 777 | m = strtol(zMode, &zEnd, 0); |
| 778 | if( (zEnd[0] || fchmod(fd, m)) && !bNoErr ){ |
| 779 | fossil_fatal("cannot change permissions on %s to \"%s\"", |
| 780 | zFN, zMode); |
| 781 | } |
| 782 | #endif |
| 783 | } |
| 784 | |
| 785 | /* Change the owner of a file to zOwner. zOwner can be of the form |
| 786 | ** USER:GROUP. |
| 787 | */ |
| 788 | void file_set_owner(const char *zFN, int fd, const char *zOwner){ |
| 789 | #if !defined(_WIN32) |
| 790 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -765,25 +765,10 @@ | |
| 765 | iMTime = file_mtime(zFile, RepoFILE); |
| 766 | zDate = db_text(0, "SELECT datetime(%lld, 'unixepoch')", iMTime); |
| 767 | fossil_print("Set mtime of \"%s\" to %s (%lld)\n", zFile, zDate, iMTime); |
| 768 | } |
| 769 | |
| 770 | /* Change the owner of a file to zOwner. zOwner can be of the form |
| 771 | ** USER:GROUP. |
| 772 | */ |
| 773 | void file_set_owner(const char *zFN, int fd, const char *zOwner){ |
| 774 | #if !defined(_WIN32) |
| 775 |