~d-jj/+junk/sudo

« back to all changes in this revision

Viewing changes to lib/util/gidlist.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-05-13 15:43:49 UTC
  • mfrom: (1.4.17) (1.3.38 sid)
  • Revision ID: package-import@ubuntu.com-20150513154349-3wazxyt6jxlgtgpi
Tags: 1.8.12-1ubuntu1
* Merge from Debian unstable. (LP: #1451274, LP: #1219337)
  Remaining changes:
  - debian/rules:
    + compile with --without-lecture --with-tty-tickets --enable-admin-flag
    + install man/man8/sudo_root.8 in both flavours
    + install apport hooks
  - debian/sudoers:
    + also grant admin group sudo access
  - debian/source_sudo.py, debian/sudo-ldap.dirs, debian/sudo.dirs:
    + add usr/share/apport/package-hooks
  - debian/sudo.pam:
    + Use pam_env to read /etc/environment and /etc/default/locale
      environment files. Reading ~/.pam_environment is not permitted due to
      security reasons.
  - debian/control:
    + dh-autoreconf dependency fixes missing-build-dependency-for-dh_-command
  - Remaining patches:
    + keep_home_by_default.patch: Keep HOME in the default environment
    + debian/patches/also_check_sudo_group.diff: also check the sudo group
      in plugins/sudoers/sudoers.c to create the admin flag file. Leave the
      admin group check for backwards compatibility.
* Dropped patches no longer needed:
    + add_probe_interfaces_setting.diff
    + actually-use-buildflags.diff
    + CVE-2014-9680.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2013-2015 Todd C. Miller <Todd.Miller@courtesan.com>
 
3
 *
 
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.
 
7
 *
 
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.
 
15
 */
 
16
 
 
17
#include <config.h>
 
18
 
 
19
#include <sys/types.h>
 
20
 
 
21
#include <stdio.h>
 
22
#ifdef STDC_HEADERS
 
23
# include <stdlib.h>
 
24
# include <stddef.h>
 
25
#else
 
26
# ifdef HAVE_STDLIB_H
 
27
#  include <stdlib.h>
 
28
# endif
 
29
#endif /* STDC_HEADERS */
 
30
#include <grp.h>
 
31
 
 
32
#define DEFAULT_TEXT_DOMAIN     "sudo"
 
33
#include "sudo_gettext.h"       /* must be included before sudo_compat.h */
 
34
 
 
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"
 
40
 
 
41
/*
 
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
 
44
 * in the array.
 
45
 * Returns the number of gids in the allocated array.
 
46
 */
 
47
int
 
48
sudo_parse_gids_v1(const char *gidstr, const gid_t *basegid, GETGROUPS_T **gidsp)
 
49
{
 
50
    int ngids = 0;
 
51
    GETGROUPS_T *gids;
 
52
    const char *cp = gidstr;
 
53
    const char *errstr;
 
54
    char *ep;
 
55
    debug_decl(sudo_parse_gids, SUDO_DEBUG_UTIL)
 
56
 
 
57
    /* Count groups. */
 
58
    if (*cp != '\0') {
 
59
        ngids++;
 
60
        do {
 
61
            if (*cp++ == ',')
 
62
                ngids++;
 
63
        } while (*cp != '\0');
 
64
    }
 
65
    /* Base gid is optional. */
 
66
    if (basegid != NULL)
 
67
        ngids++;
 
68
    /* Allocate and fill in array. */
 
69
    if (ngids != 0) {
 
70
        gids = sudo_emallocarray(ngids, sizeof(GETGROUPS_T));
 
71
        ngids = 0;
 
72
        if (basegid != NULL)
 
73
            gids[ngids++] = *basegid;
 
74
        cp = gidstr;
 
75
        do {
 
76
            gids[ngids] = (GETGROUPS_T) sudo_strtoid(cp, ",", &ep, &errstr);
 
77
            if (errstr != NULL) {
 
78
                sudo_warnx(U_("%s: %s"), cp, U_(errstr));
 
79
                free(gids);
 
80
                debug_return_int(-1);
 
81
            }
 
82
            if (basegid == NULL || gids[ngids] != *basegid)
 
83
                ngids++;
 
84
            cp = ep + 1;
 
85
        } while (*ep != '\0');
 
86
        *gidsp = gids;
 
87
    }
 
88
    debug_return_int(ngids);
 
89
}