2
* Copyright (c) 2013-2015 Todd C. Miller <Todd.Miller@courtesan.com>
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
8
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
#include <sys/types.h>
29
#endif /* STDC_HEADERS */
32
#define DEFAULT_TEXT_DOMAIN "sudo"
33
#include "sudo_gettext.h" /* must be included before sudo_compat.h */
35
#include "sudo_compat.h"
36
#include "sudo_alloc.h"
37
#include "sudo_fatal.h"
38
#include "sudo_debug.h"
39
#include "sudo_util.h"
42
* Parse a comma-separated list of gids into an allocated array of GETGROUPS_T.
43
* If a pointer to the base gid is specified, it is stored as the first element
45
* Returns the number of gids in the allocated array.
48
sudo_parse_gids_v1(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp)
52
const char *cp = gidstr;
55
debug_decl(sudo_parse_gids, SUDO_DEBUG_UTIL)
63
} while (*cp != '\0');
65
/* Base gid is optional. */
68
/* Allocate and fill in array. */
70
gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T));
73
gids[ngids++] = *basegid;
76
gids[ngids] = (GETGROUPS_T) sudo_strtoid(cp, ",", &ep, &errstr);
78
sudo_warnx(U_("%s: %s"), cp, U_(errstr));
82
if (basegid == NULL || gids[ngids] != *basegid)
85
} while (*ep != '\0');
88
debug_return_int(ngids);