2 Copyright (C) 2014-2017 Cédric Schieli
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public License
6 as published by the Free Software Foundation; either version 2.1
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
29 #include <AvailabilityMacros.h>
31 #include "JackError.h"
36 jack_group2gid(const char* group
)
47 if (!group
|| !*group
)
50 ret
= strtol(group
, &buf
, 10);
54 /* MacOSX only defines _SC_GETGR_R_SIZE_MAX starting from 10.4 */
55 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
58 buflen
= sysconf(_SC_GETGR_R_SIZE_MAX
);
62 buf
= (char*)malloc(buflen
);
64 while (buf
&& ((ret
= getgrnam_r(group
, &grp
, buf
, buflen
, &result
)) == ERANGE
)) {
66 buf
= (char*)realloc(buf
, buflen
);
79 jack_promiscuous_perms(int fd
, const char* path
, gid_t gid
)
81 mode_t mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
| S_IROTH
| S_IWOTH
;
83 if (((fd
< 0) ? chown(path
, -1, gid
) : fchown(fd
, -1, gid
)) < 0) {
84 jack_log("Cannot chgrp %s: %s. Falling back to permissive perms.", path
, strerror(errno
));
86 mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
;
89 if (((fd
< 0) ? chmod(path
, mode
) : fchmod(fd
, mode
)) < 0) {
90 jack_log("Cannot chmod %s: %s. Falling back to default (umask) perms.", path
, strerror(errno
));