From 7e5b53972233b6aea593397ed8fb8f55068eadaf Mon Sep 17 00:00:00 2001 From: Mike Tancsa Date: Fri, 31 Mar 2017 17:50:35 -0300 Subject: [PATCH] lib: fix usage of getgrouplist() in *BSD On BSD systems, the getgrouplist() function returns 0 if successful and -1 on error. Linux in the other hand returns *ngroups (the number of groups of which user is a member) on success and -1 on error. Given this difference, the most portable way to use getgrouplist() is use its return value only for checking if it succeeded or not. Signed-off-by: Renato Westphal --- lib/privs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/privs.c b/lib/privs.c index 376d6f3365..decd4bb7db 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -731,7 +731,7 @@ zprivs_init(struct zebra_privs_t *zprivs) if (zprivs->user) { ngroups = sizeof(groups); - if ( (ngroups = getgrouplist (zprivs->user, zprivs_state.zgid, groups, &ngroups )) < 0 ) + if (getgrouplist (zprivs->user, zprivs_state.zgid, groups, &ngroups) < 0) { /* cant use log.h here as it depends on vty */ fprintf (stderr, "privs_init: could not getgrouplist for user %s\n",