Skip to content

Commit 6dc1445

Browse files
committed
MDEV-23926: Fix warnings generated during compilation of plugin/auth_pam/mapper/pam_user_map.c on MacOS
Compiler warnings like one listed below are generated during server build on MacOS: [88%] Building C object plugin/auth_pam/CMakeFiles/pam_user_map.dir/mapper/pam_user_map.c.o mariadb/server-10.2/plugin/auth_pam/mapper/pam_user_map.c:87:41: error: passing 'gid_t *' (aka 'unsigned int *') to parameter of type 'int *' converts between pointers to integer types with different sign [-Werror,-Wpointer-sign] if (getgrouplist(user, user_group_id, loc_groups, &ng) < 0) ^~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/unistd.h:650:43: note: passing argument to parameter here int getgrouplist(const char *, int, int *, int *); ^ In case MariaDB server is build with -DCMAKE_BUILD_TYPE=Debug it results in build error. The reason of compiler warnings is that declaration of the Posix C API function getgrouplist() on MacOS differs from declaration of getgrouplist() proposed by Posix. To suppress this compiler warning cmake configure was adapted to detect what kind of getgrouplist() function is declared on the build platform and set the macros HAVE_POSIX_GETGROUPLIST in case the building platform supports Posix compatible interface for the getgrouplist() function. Depending on whether this macros is set the compatible type of arguments is used to pass parameter values to the function.
1 parent 985ede9 commit 6dc1445

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

plugin/auth_pam/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ CHECK_INCLUDE_FILES (security/pam_ext.h HAVE_PAM_EXT_H)
55
CHECK_INCLUDE_FILES (security/pam_appl.h HAVE_PAM_APPL_H)
66
CHECK_FUNCTION_EXISTS (strndup HAVE_STRNDUP)
77

8+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
9+
10+
# Check whether getgrouplist uses git_t for second and third arguments.
11+
SET(CMAKE_REQUIRED_FLAGS -Werror)
12+
CHECK_C_SOURCE_COMPILES(
13+
"
14+
#ifdef HAVE_GRP_H
15+
#include <grp.h>
16+
#endif
17+
#ifdef HAVE_UNISTD_H
18+
#include <unistd.h>
19+
#endif
20+
int main() {
21+
char *arg_1;
22+
gid_t arg_2, arg_3;
23+
int arg_4;
24+
(void)getgrouplist(arg_1,arg_2,&arg_3,arg_4);
25+
return 0;
26+
}
27+
"
28+
HAVE_POSIX_GETGROUPLIST
29+
)
30+
SET(CMAKE_REQUIRED_FLAGS)
31+
832
SET(CMAKE_REQUIRED_LIBRARIES pam)
933
CHECK_FUNCTION_EXISTS(pam_syslog HAVE_PAM_SYSLOG)
1034
SET(CMAKE_REQUIRED_LIBRARIES)
@@ -36,3 +60,5 @@ IF(HAVE_PAM_APPL_H)
3660
ENDIF()
3761
ENDIF(HAVE_PAM_APPL_H)
3862

63+
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
64+
${CMAKE_CURRENT_BINARY_DIR}/config_auth_pam.h)

plugin/auth_pam/mapper/pam_user_map.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ These comments are written to the syslog as 'authpriv.debug'
3131
and usually end up in /var/log/secure file.
3232
*/
3333

34+
#include <config_auth_pam.h>
3435
#include <stdlib.h>
3536
#include <stdio.h>
3637
#include <ctype.h>
@@ -70,10 +71,16 @@ pam_syslog (const pam_handle_t *pamh, int priority,
7071
#define GROUP_BUFFER_SIZE 100
7172
static const char debug_keyword[]= "debug";
7273

73-
static int populate_user_groups(const char *user, gid_t **groups)
74+
#ifdef HAVE_POSIX_GETGROUPLIST
75+
typedef gid_t my_gid_t;
76+
#else
77+
typedef int my_gid_t;
78+
#endif
79+
80+
static int populate_user_groups(const char *user, my_gid_t **groups)
7481
{
75-
gid_t user_group_id;
76-
gid_t *loc_groups= *groups;
82+
my_gid_t user_group_id;
83+
my_gid_t *loc_groups= *groups;
7784
int ng;
7885

7986
{
@@ -88,22 +95,23 @@ static int populate_user_groups(const char *user, gid_t **groups)
8895
{
8996
/* The rare case when the user is present in more than */
9097
/* GROUP_BUFFER_SIZE groups. */
91-
loc_groups= (gid_t *) malloc(ng * sizeof (gid_t));
98+
loc_groups= (my_gid_t *) malloc(ng * sizeof (my_gid_t));
99+
92100
if (!loc_groups)
93101
return 0;
94102

95103
(void) getgrouplist(user, user_group_id, loc_groups, &ng);
96-
*groups= loc_groups;
104+
*groups= (my_gid_t*)loc_groups;
97105
}
98106

99107
return ng;
100108
}
101109

102110

103-
static int user_in_group(const gid_t *user_groups, int ng,const char *group)
111+
static int user_in_group(const my_gid_t *user_groups, int ng,const char *group)
104112
{
105-
gid_t group_id;
106-
const gid_t *groups_end = user_groups + ng;
113+
my_gid_t group_id;
114+
const my_gid_t *groups_end = user_groups + ng;
107115

108116
{
109117
struct group *g= getgrnam(group);
@@ -122,7 +130,7 @@ static int user_in_group(const gid_t *user_groups, int ng,const char *group)
122130
}
123131

124132

125-
static void print_groups(pam_handle_t *pamh, const gid_t *user_groups, int ng)
133+
static void print_groups(pam_handle_t *pamh, const my_gid_t *user_groups, int ng)
126134
{
127135
char buf[256];
128136
char *c_buf= buf, *buf_end= buf+sizeof(buf)-2;
@@ -158,8 +166,8 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags,
158166
const char *username;
159167
char buf[256];
160168
FILE *f;
161-
gid_t group_buffer[GROUP_BUFFER_SIZE];
162-
gid_t *groups= group_buffer;
169+
my_gid_t group_buffer[GROUP_BUFFER_SIZE];
170+
my_gid_t *groups= group_buffer;
163171
int n_groups= -1;
164172

165173
for (; argc > 0; argc--)

0 commit comments

Comments
 (0)