| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | #include <config.h> | - |
| 21 | | - |
| 22 | #include "mgetgroups.h" | - |
| 23 | | - |
| 24 | #include <stdlib.h> | - |
| 25 | #include <unistd.h> | - |
| 26 | #include <stdint.h> | - |
| 27 | #include <string.h> | - |
| 28 | #include <errno.h> | - |
| 29 | #if HAVE_GETGROUPLIST | - |
| 30 | # include <grp.h> | - |
| 31 | #endif | - |
| 32 | | - |
| 33 | #include "getugroups.h" | - |
| 34 | #include "xalloc-oversized.h" | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | #if 4 < __GNUC__ + (3 <= __GNUC_MINOR__) | - |
| 39 | # pragma GCC diagnostic ignored "-Wpointer-sign" | - |
| 40 | #endif | - |
| 41 | | - |
| 42 | static gid_t * | - |
| 43 | realloc_groupbuf (gid_t *g, size_t num) | - |
| 44 | { | - |
| 45 | if (xalloc_oversized (num, sizeof *g))| TRUE | never evaluated | | FALSE | evaluated 115 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 115 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-115 |
| 46 | { | - |
| 47 | errno = ENOMEM; | - |
| 48 | return NULL; never executed: ((void *)0) ; } | 0 |
| 49 | } | - |
| 50 | | - |
| 51 | return realloc (g, num * sizeof *g);executed 115 times by 1 test | 115 |
| 52 | } | - |
| 53 | | - |
| 54 | | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | | - |
| 62 | | - |
| 63 | | - |
| 64 | | - |
| 65 | int | - |
| 66 | mgetgroups (char const *username, gid_t gid, gid_t **groups) | - |
| 67 | { | - |
| 68 | int max_n_groups; | - |
| 69 | int ng; | - |
| 70 | gid_t *g; | - |
| 71 | | - |
| 72 | #if HAVE_GETGROUPLIST | - |
| 73 | | - |
| 74 | | - |
| 75 | | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | if (username)| TRUE | evaluated 42 times by 1 test | | FALSE | evaluated 16 times by 1 test |
| 16-42 |
| 82 | { | - |
| 83 | enum { N_GROUPS_INIT = 10 }; | - |
| 84 | max_n_groups = N_GROUPS_INIT; | - |
| 85 | | - |
| 86 | g = realloc_groupbuf (NULL, max_n_groups); | - |
| 87 | if (g == NULL)| TRUE | never evaluated | | FALSE | evaluated 42 times by 1 test |
| 0-42 |
| 88 | return -1; never executed | 0 |
| 89 | | - |
| 90 | while (1) | - |
| 91 | { | - |
| 92 | gid_t *h; | - |
| 93 | int last_n_groups = max_n_groups; | - |
| 94 | | - |
| 95 | | - |
| 96 | ng = getgrouplist (username, gid, g, &max_n_groups); | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | if (ng < 0 && last_n_groups == max_n_groups)| TRUE | evaluated 15 times by 1 test | | FALSE | evaluated 42 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 15 times by 1 test |
| 0-42 |
| 101 | max_n_groups *= 2; never executed | 0 |
| 102 | | - |
| 103 | if ((h = realloc_groupbuf (g, max_n_groups)) == NULL)| TRUE | never evaluated | | FALSE | evaluated 57 times by 1 test |
| 0-57 |
| 104 | { | - |
| 105 | int saved_errno = errno; | - |
| 106 | free (g); | - |
| 107 | errno = saved_errno; | - |
| 108 | return -1; never executed | 0 |
| 109 | } | - |
| 110 | g = h; | - |
| 111 | | - |
| 112 | if (0 <= ng)| TRUE | evaluated 42 times by 1 test | | FALSE | evaluated 15 times by 1 test |
| 15-42 |
| 113 | { | - |
| 114 | *groups = g; | - |
| 115 | | - |
| 116 | | - |
| 117 | return max_n_groups;executed 42 times by 1 test | 42 |
| 118 | } | - |
| 119 | }executed 15 times by 1 test | 15 |
| 120 | } never executed | 0 |
| 121 | | - |
| 122 | #endif | - |
| 123 | | - |
| 124 | max_n_groups = (username| TRUE | never evaluated | | FALSE | evaluated 16 times by 1 test |
| 0-16 |
| 125 | ? getugroups (0, NULL, username, gid) | - |
| 126 | : getgroups (0, NULL)); | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | if (max_n_groups < 0)| TRUE | never evaluated | | FALSE | evaluated 16 times by 1 test |
| 0-16 |
| 132 | { | - |
| 133 | if (errno == ENOSYS && (g = realloc_groupbuf (NULL, 1)))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 134 | { | - |
| 135 | *groups = g; | - |
| 136 | *g = gid; | - |
| 137 | return gid != (gid_t) -1; never executed | 0 |
| 138 | } | - |
| 139 | return -1; never executed | 0 |
| 140 | } | - |
| 141 | | - |
| 142 | if (max_n_groups == 0 || (!username && gid != (gid_t) -1))| TRUE | never evaluated | | FALSE | evaluated 16 times by 1 test |
| TRUE | evaluated 16 times by 1 test | | FALSE | never evaluated |
| TRUE | evaluated 16 times by 1 test | | FALSE | never evaluated |
| 0-16 |
| 143 | max_n_groups++;executed 16 times by 1 test: = realloc_group | 16 |
| 144 | g = realloc_groupbuf (NULL, max_n_groups); | - |
| 145 | if (g == NULL)| TRUE | never evaluated | | FALSE | evaluated 16 times by 1 test |
| 0-16 |
| 146 | return -1; never executed | 0 |
| 147 | | - |
| 148 | ng = (username| TRUE | never evaluated | | FALSE | evaluated 16 times by 1 test |
| 0-16 |
| 149 | ? getugroups (max_n_groups, g, username, gid) | - |
| 150 | : getgroups (max_n_groups - (gid != (gid_t) -1), | - |
| 151 | g + (gid != (gid_t) -1))); | - |
| 152 | | - |
| 153 | if (ng < 0)| TRUE | never evaluated | | FALSE | evaluated 16 times by 1 test |
| 0-16 |
| 154 | { | - |
| 155 | | - |
| 156 | int saved_errno = errno; | - |
| 157 | free (g); | - |
| 158 | errno = saved_errno; | - |
| 159 | return -1; never executed | 0 |
| 160 | } | - |
| 161 | | - |
| 162 | if (!username && gid != (gid_t) -1)| TRUE | evaluated 16 times by 1 test | | FALSE | never evaluated |
| TRUE | evaluated 16 times by 1 test | | FALSE | never evaluated |
| 0-16 |
| 163 | { | - |
| 164 | *g = gid; | - |
| 165 | ng++; | - |
| 166 | }executed 16 times by 1 test: r | 16 |
| 167 | *groups = g; | - |
| 168 | | - |
| 169 | | - |
| 170 | | - |
| 171 | | - |
| 172 | | - |
| 173 | | - |
| 174 | | - |
| 175 | | - |
| 176 | | - |
| 177 | | - |
| 178 | | - |
| 179 | | - |
| 180 | | - |
| 181 | | - |
| 182 | | - |
| 183 | | - |
| 184 | | - |
| 185 | if (1 < ng)| TRUE | evaluated 16 times by 1 test | | FALSE | never evaluated |
| 0-16 |
| 186 | { | - |
| 187 | gid_t first = *g; | - |
| 188 | gid_t *next; | - |
| 189 | gid_t *groups_end = g + ng; | - |
| 190 | | - |
| 191 | for (next = g + 1; next < groups_end; next++)| TRUE | evaluated 176 times by 1 test | | FALSE | evaluated 16 times by 1 test |
| 16-176 |
| 192 | { | - |
| 193 | if (*next == first || *next == *g)| TRUE | evaluated 16 times by 1 test | | FALSE | evaluated 160 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 160 times by 1 test |
| 0-160 |
| 194 | ng--;executed 16 times by 1 test: se | 16 |
| 195 | else | - |
| 196 | *++g = *next;executed 160 times by 1 test | 160 |
| 197 | } | - |
| 198 | }executed 16 times by 1 test | 16 |
| 199 | | - |
| 200 | return ng;executed 16 times by 1 test | 16 |
| 201 | } | - |
| | |