lib/: Don't open-code get_gid()
These functions were open-coding get_gid(). Use the actual function. Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1991 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 2000, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2000 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 1991-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-2000, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2000-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2007-2009, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -14,30 +13,27 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
/*
|
||||
* getgr_nam_gid - Return a pointer to the group specified by a string.
|
||||
* The string may be a valid GID or a valid groupname.
|
||||
* If the group does not exist on the system, NULL is returned.
|
||||
*/
|
||||
extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname)
|
||||
extern /*@only@*//*@null@*/struct group *
|
||||
getgr_nam_gid(/*@null@*/const char *grname)
|
||||
{
|
||||
char *end;
|
||||
long long gid;
|
||||
gid_t gid;
|
||||
|
||||
if (NULL == grname) {
|
||||
if (NULL == grname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
gid = strtoll(grname, &end, 10);
|
||||
if ( ('\0' != *grname)
|
||||
&& ('\0' == *end)
|
||||
&& (0 == errno)
|
||||
&& (/*@+longintegral@*/gid == (gid_t)gid)/*@=longintegral@*/) {
|
||||
return xgetgrgid (gid);
|
||||
}
|
||||
return xgetgrnam (grname);
|
||||
if (get_gid(grname, &gid) == 0)
|
||||
return xgetgrgid(gid);
|
||||
return xgetgrnam(grname);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "atoi/getnum.h"
|
||||
#include "defines.h"
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
@@ -334,8 +335,7 @@ extern void prefix_endgrent(void)
|
||||
|
||||
extern struct group *prefix_getgr_nam_gid(const char *grname)
|
||||
{
|
||||
char *end;
|
||||
long long gid;
|
||||
gid_t gid;
|
||||
struct group *g;
|
||||
|
||||
if (NULL == grname) {
|
||||
@@ -345,15 +345,8 @@ extern struct group *prefix_getgr_nam_gid(const char *grname)
|
||||
if (!group_db_file)
|
||||
return getgr_nam_gid(grname);
|
||||
|
||||
errno = 0;
|
||||
gid = strtoll(grname, &end, 10);
|
||||
if ( ('\0' != *grname)
|
||||
&& ('\0' == *end)
|
||||
&& (0 == errno)
|
||||
&& (gid == (gid_t)gid))
|
||||
{
|
||||
if (get_gid(grname, &gid) == 0)
|
||||
return prefix_getgrgid(gid);
|
||||
}
|
||||
|
||||
g = prefix_getgrnam(grname);
|
||||
return g ? __gr_dup(g) : NULL;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "atoi/getnum.h"
|
||||
#include "chkname.h"
|
||||
#include "defines.h"
|
||||
#include "faillog.h"
|
||||
@@ -853,21 +854,14 @@ static int get_groups (char *list)
|
||||
*/
|
||||
static struct group * get_local_group(char * grp_name)
|
||||
{
|
||||
char *end;
|
||||
const struct group *grp;
|
||||
struct group *result_grp = NULL;
|
||||
long long gid;
|
||||
gid_t gid;
|
||||
struct group *result_grp = NULL;
|
||||
const struct group *grp;
|
||||
|
||||
gid = strtoll(grp_name, &end, 10);
|
||||
if ( ('\0' != *grp_name)
|
||||
&& ('\0' == *end)
|
||||
&& (ERANGE != errno)
|
||||
&& (gid == (gid_t)gid)) {
|
||||
grp = gr_locate_gid (gid);
|
||||
}
|
||||
else {
|
||||
if (get_gid(grp_name, &gid) == 0)
|
||||
grp = gr_locate_gid(gid);
|
||||
else
|
||||
grp = gr_locate(grp_name);
|
||||
}
|
||||
|
||||
if (grp != NULL) {
|
||||
result_grp = __gr_dup (grp);
|
||||
|
||||
Reference in New Issue
Block a user